Skip to content

Commit e09208b

Browse files
lyan3jren1
authored andcommitted
DM:tools: add scripts for VM exit analysis
Script usage: [Usage] acrnalyze.py [options] [value] ... [options] -h: print this message -i, --ifile=[string]: input file -o, --ofile=[string]: output file --vm_exit: to generate vm_exit report Note: bash and python2 are required. Example: Assumed trace data have been copied to /home/xxxx/trace_data/20171115-101605 # acrnalyze.py -i /home/xxxx/trace_data/20171115-101605/0 -o /home/xxxx/trac e_data/20171115-101605/cpu0 --vm_exit - "--vm_exit" specify the analysis to do, currently, only vm_exit analysis is supported. - A preprocess would be taken out to make the trace data start and end with an VM_ENTER, and a copy of original data file is saved with suffix ".orig"; - Analysis report would be given on the std output and in a csv file with name specified via "-o outpu_file"; Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Signed-off-by: Yan, Like <like.yan@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 99c69c7 commit e09208b

File tree

3 files changed

+414
-0
lines changed

3 files changed

+414
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/python2
2+
# -*- coding: UTF-8 -*-
3+
4+
"""
5+
This is the main script of arnalyzer, which:
6+
- parse the options
7+
- pre-process the trace data file
8+
- call a specific script to do analysis
9+
"""
10+
11+
import sys
12+
import getopt
13+
import os
14+
from vmexit_analyze import analyze_vm_exit
15+
16+
def usage():
17+
"""print the usage of the script
18+
Args: NA
19+
Returns: None
20+
Raises: NA
21+
"""
22+
print '''
23+
[Usage] acrnalyze.py [options] [value] ...
24+
25+
[options]
26+
-h: print this message
27+
-i, --ifile=[string]: input file
28+
-o, --ofile=[string]: output file
29+
--vm_exit: to generate vm_exit report
30+
'''
31+
32+
def do_analysis(ifile, ofile, analyzer):
33+
"""do the specific analysis
34+
35+
Args:
36+
ifile: input trace data file
37+
ofile: output analysis report file
38+
analyzer: a function do the specific analysis
39+
Returns:
40+
None
41+
Raises:
42+
NA
43+
"""
44+
analyzer(ifile, ofile)
45+
46+
# pre process to make sure the trace data start and end with VMENTER
47+
def pre_process(ifile, evstr):
48+
"""invoke sh script to preprocess the data file
49+
50+
Args:
51+
ifile: input trace data file
52+
evstr: event string, after the processing, the data file should
53+
start and end with the string
54+
Returns:
55+
status of sh script execution
56+
Raises:
57+
NA
58+
"""
59+
status = os.system('bash pre_process.sh %s %s' % (ifile, evstr))
60+
return status
61+
62+
def main(argv):
63+
"""Main enterance function
64+
65+
Args:
66+
argv: arguments string
67+
Returns:
68+
None
69+
Raises:
70+
GetoptError
71+
"""
72+
inputfile = ''
73+
outputfile = ''
74+
opts_short = "hi:o:"
75+
opts_long = ["ifile=", "ofile=", "vm_exit"]
76+
77+
try:
78+
opts, args = getopt.getopt(argv, opts_short, opts_long)
79+
except getopt.GetoptError:
80+
usage()
81+
sys.exit(1)
82+
83+
for opt, arg in opts:
84+
if opt == '-h':
85+
usage()
86+
sys.exit()
87+
elif opt in ("-i", "--ifile"):
88+
inputfile = arg
89+
elif opt in ("-o", "--ofile"):
90+
outputfile = arg
91+
elif opt == "--vm_exit":
92+
analyzer = analyze_vm_exit
93+
else:
94+
assert False, "unhandled option"
95+
96+
assert inputfile != '', "input file is required"
97+
assert outputfile != '', "output file is required"
98+
assert analyzer != '', 'MUST contain one of analyzer: ''vm_exit'
99+
100+
status = pre_process(inputfile, 'VM_ENTER')
101+
if status == 0:
102+
do_analysis(inputfile, outputfile, analyzer)
103+
else:
104+
print "Invalid trace data file %s" % (inputfile)
105+
106+
if __name__ == "__main__":
107+
main(sys.argv[1:])
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
IFILE=$1
4+
STR=$2
5+
BAK_FILE=${IFILE}.orig
6+
7+
if [ ! -f $BAK_FILE ]; then
8+
cp $IFILE $BAK_FILE
9+
fi
10+
11+
echo $IFILE, $BAK_FILE, $STR
12+
13+
FIRST_LINE=$(grep -n $STR -m 1 $IFILE | awk -F: '{print $1}')
14+
LAST_LINE=$(grep -n $STR $IFILE | tail -1 | awk -F: '{print $1}')
15+
TOTAL_LINE=$(wc -l $IFILE | awk '{print $1}')
16+
17+
echo $FIRST_LINE, $LAST_LINE, $TOTAL_LINE
18+
19+
if [[ $FIRST_LINE -ge $LAST_LINE || $LAST_LINE -gt $TOTAL_LINE ]]; then
20+
exit 1
21+
fi
22+
23+
if [[ $LAST_LINE -lt $TOTAL_LINE ]]; then
24+
let LAST_LINE=$((LAST_LINE))+1
25+
echo "sed -i ${LAST_LINE},${TOTAL_LINE}d $IFILE"
26+
sed -i ${LAST_LINE}','${TOTAL_LINE}'d' $IFILE
27+
fi
28+
29+
if [[ $FIRST_LINE -gt 2 ]]; then
30+
let FIRST_LINE=$((FIRST_LINE))-1
31+
echo "sed -i 2,${FIRST_LINE}d $IFILE"
32+
sed -i '2,'${FIRST_LINE}'d' $IFILE
33+
fi

0 commit comments

Comments
 (0)