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 .*//;
|
2017-11-02 13:43:37 +00:00
|
|
|
s/ SE$//;
|
2016-06-01 13:57:00 +00:00
|
|
|
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]\+\)'
|
2019-03-26 20:20:38 +00:00
|
|
|
matchCPUID="$hex $hex: eax=$hex ebx=$hex ecx=$hex edx=$hex"
|
|
|
|
substCPUID="<cpuid eax_in='\\1' ecx_in='\\2' eax='\\3' ebx='\\4' ecx='\\5' edx='\\6'\\/>"
|
|
|
|
|
|
|
|
matchMSR="$hex: $hex\(.......[0-9a-f]\)"
|
|
|
|
substMSR="<msr index='\\1' edx='\\2' eax='0x\\3'\\/>"
|
2016-06-01 13:57:00 +00:00
|
|
|
|
|
|
|
echo "<!-- $model -->"
|
|
|
|
echo "<cpudata arch='x86'>"
|
2019-03-26 20:20:38 +00:00
|
|
|
sed -ne "s/^ *$matchCPUID$/ $substCPUID/p; s/^ *$matchMSR$/ $substMSR/p"
|
2016-06-01 13:57:00 +00:00
|
|
|
echo "</cpudata>"
|
|
|
|
}
|
|
|
|
|
|
|
|
json()
|
|
|
|
{
|
|
|
|
first=true
|
|
|
|
sed -ne '/{"QMP".*/d;
|
|
|
|
/{"return": {}}/d;
|
|
|
|
/{"timestamp":.*/d;
|
|
|
|
/^{/p' <<<"$data" | \
|
|
|
|
while read; do
|
|
|
|
$first || echo
|
|
|
|
first=false
|
2017-09-26 21:02:48 +00:00
|
|
|
$(dirname $0)/cpu-reformat.py <<<"$REPLY"
|
2016-06-01 13:57:00 +00:00
|
|
|
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
|
2019-04-01 11:19:16 +00:00
|
|
|
echo "Missing query-cpu-model-expansion reply in $name.json" >&2
|
|
|
|
exit 1
|
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
|