File: cpu-parse.sh

package info (click to toggle)
libvirt 5.0.0-4%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 251,264 kB
  • sloc: ansic: 573,843; xml: 168,347; sh: 9,976; python: 4,883; perl: 3,953; makefile: 3,323; ml: 465
file content (61 lines) | stat: -rwxr-xr-x 1,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

# Usage:
# ./cpu-gather.sh | ./cpu-parse.sh

data=`cat`

model=`sed -ne '/^model name[ 	]*:/ {s/^[^:]*: \(.*\)/\1/p; q}' <<<"$data"`

fname=`sed -e 's/^ *//;
               s/ *$//;
               s/[ -]\+ \+/ /g;
               s/(\([Rr]\|[Tt][Mm]\))//g;
               s/.*\(Intel\|AMD\) //;
               s/ \(Duo\|Quad\|II X[0-9]\+\) / /;
               s/ \(CPU\|Processor\)\>//;
               s/ @.*//;
               s/ APU .*//;
               s/ SE$//;
               s/ /-/g' <<<"$model"`
fname="x86_64-cpuid-$fname"

xml()
{
    hex='\(0x[0-9a-f]\+\)'
    match="$hex $hex: eax=$hex ebx=$hex ecx=$hex edx=$hex"
    subst="<cpuid eax_in='\\1' ecx_in='\\2' eax='\\3' ebx='\\4' ecx='\\5' edx='\\6'\\/>"

    echo "<!-- $model -->"
    echo "<cpudata arch='x86'>"
    sed -ne "s/^ *$match$/  $subst/p"
    echo "</cpudata>"
}

json()
{
    first=true
    sed -ne '/{"QMP".*/d;
             /{"return": {}}/d;
             /{"timestamp":.*/d;
             /^{/p' <<<"$data" | \
    while read; do
        $first || echo
        first=false
        $(dirname $0)/cpu-reformat.py <<<"$REPLY"
    done
}

xml <<<"$data" >$fname.xml
echo $fname.xml

json <<<"$data" >$fname.json
if [[ -s $fname.json ]]; then
    echo $fname.json
    if ! grep -q model-expansion $fname.json; then
        $(dirname $0)/cpu-cpuid.py convert $fname.json
    fi
    $(dirname $0)/cpu-cpuid.py diff $fname.json
else
    rm $fname.json
fi