2016-06-01 13:57:00 +00:00
|
|
|
#!/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/ \(v[0-9]\|SE\)$//;
|
|
|
|
s/ /-/g' <<<"$model"`
|
2017-02-13 13:12:28 +00:00
|
|
|
fname="x86_64-cpuid-$fname"
|
2016-06-01 13:57:00 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
json_reformat <<<"$REPLY" | tr -s '\n'
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
xml <<<"$data" >$fname.xml
|
|
|
|
echo $fname.xml
|
|
|
|
|
|
|
|
json <<<"$data" >$fname.json
|
|
|
|
if [[ -s $fname.json ]]; then
|
|
|
|
echo $fname.json
|
2017-02-01 16:48:41 +00:00
|
|
|
if ! grep -q model-expansion $fname.json; then
|
2017-03-15 12:16:37 +00:00
|
|
|
$(dirname $0)/cpu-cpuid.py convert $fname.json
|
2017-02-01 16:48:41 +00:00
|
|
|
fi
|
2017-03-16 11:25:30 +00:00
|
|
|
$(dirname $0)/cpu-cpuid.py diff $fname.json
|
2016-06-01 13:57:00 +00:00
|
|
|
else
|
2017-02-16 13:44:33 +00:00
|
|
|
rm $fname.json
|
2016-06-01 13:57:00 +00:00
|
|
|
fi
|