mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-24 14:33:38 +00:00
tools: acrntrace: Make all python scripts python3 module
The trend is to focus on Python3 and deprecate Python2. This patch make all the acrntrace related scripts as Python3 module. - Add parentheses to all the print as Python3 required. - Remove suffix L and long() Python3 has deprecated. Python3 will treat all intergers as long. - Replace has_key() with "key in .keys()" because has_key() has been deprecated. - Other minor fixes. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
This commit is contained in:
parent
e75cca64c8
commit
ad89a22011
@ -44,7 +44,7 @@ Usage
|
|||||||
|
|
||||||
Replace username and hostname with appropriate values.
|
Replace username and hostname with appropriate values.
|
||||||
|
|
||||||
#. On the Linux system, run the provided python2 script to analyze the
|
#. On the Linux system, run the provided Python3 script to analyze the
|
||||||
``vm_exits`` (currently only vm_exit analysis is supported):
|
``vm_exits`` (currently only vm_exit analysis is supported):
|
||||||
|
|
||||||
.. code-block:: none
|
.. code-block:: none
|
||||||
@ -56,7 +56,7 @@ Usage
|
|||||||
a copy of the original data file is saved with suffix ``.orig``.
|
a copy of the original data file is saved with suffix ``.orig``.
|
||||||
- Analysis report is written to stdout, or to a CSV file if
|
- Analysis report is written to stdout, or to a CSV file if
|
||||||
a filename is specified using ``-o filename``.
|
a filename is specified using ``-o filename``.
|
||||||
- The scripts require bash and python2.
|
- The scripts require Python3.
|
||||||
|
|
||||||
Build and Install
|
Build and Install
|
||||||
*****************
|
*****************
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python2
|
#!/usr/bin/python3
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -20,7 +20,7 @@ def usage():
|
|||||||
Returns: None
|
Returns: None
|
||||||
Raises: NA
|
Raises: NA
|
||||||
"""
|
"""
|
||||||
print '''
|
print ('''
|
||||||
[Usage] acrnalyze.py [options] [value] ...
|
[Usage] acrnalyze.py [options] [value] ...
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
@ -30,7 +30,7 @@ def usage():
|
|||||||
-f, --frequency=[unsigned int]: TSC frequency in MHz
|
-f, --frequency=[unsigned int]: TSC frequency in MHz
|
||||||
--vm_exit: to generate vm_exit report
|
--vm_exit: to generate vm_exit report
|
||||||
--irq: to generate irq related report
|
--irq: to generate irq related report
|
||||||
'''
|
''')
|
||||||
|
|
||||||
def do_analysis(ifile, ofile, analyzer):
|
def do_analysis(ifile, ofile, analyzer):
|
||||||
"""do the specific analysis
|
"""do the specific analysis
|
||||||
|
@ -9,8 +9,8 @@ import csv
|
|||||||
import struct
|
import struct
|
||||||
from config import TSC_FREQ
|
from config import TSC_FREQ
|
||||||
|
|
||||||
TSC_BEGIN = 0L
|
TSC_BEGIN = 0
|
||||||
TSC_END = 0L
|
TSC_END = 0
|
||||||
|
|
||||||
VMEXIT_ENTRY = 0x10000
|
VMEXIT_ENTRY = 0x10000
|
||||||
|
|
||||||
@ -44,13 +44,13 @@ def parse_trace(ifile):
|
|||||||
event = event & 0xffffffffffff
|
event = event & 0xffffffffffff
|
||||||
|
|
||||||
if TSC_BEGIN == 0:
|
if TSC_BEGIN == 0:
|
||||||
TSC_BEGIN = long(tsc)
|
TSC_BEGIN = tsc
|
||||||
|
|
||||||
TSC_END = long(tsc)
|
TSC_END = tsc
|
||||||
|
|
||||||
for key in LIST_EVENTS.keys():
|
for key in LIST_EVENTS.keys():
|
||||||
if event == LIST_EVENTS.get(key):
|
if event == LIST_EVENTS.get(key):
|
||||||
if IRQ_EXITS.has_key(vec):
|
if vec in IRQ_EXITS.keys():
|
||||||
IRQ_EXITS[vec] += 1
|
IRQ_EXITS[vec] += 1
|
||||||
else:
|
else:
|
||||||
IRQ_EXITS[vec] = 1
|
IRQ_EXITS[vec] = 1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python2
|
#!/usr/bin/python3
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -9,9 +9,9 @@ import csv
|
|||||||
import struct
|
import struct
|
||||||
from config import TSC_FREQ
|
from config import TSC_FREQ
|
||||||
|
|
||||||
TSC_BEGIN = 0L
|
TSC_BEGIN = 0
|
||||||
TSC_END = 0L
|
TSC_END = 0
|
||||||
TOTAL_NR_EXITS = 0L
|
TOTAL_NR_EXITS = 0
|
||||||
|
|
||||||
VM_EXIT = 0x10
|
VM_EXIT = 0x10
|
||||||
VM_ENTER = 0x11
|
VM_ENTER = 0x11
|
||||||
@ -90,11 +90,11 @@ def parse_trace_data(ifile):
|
|||||||
|
|
||||||
global TSC_BEGIN, TSC_END, TOTAL_NR_EXITS
|
global TSC_BEGIN, TSC_END, TOTAL_NR_EXITS
|
||||||
last_ev_id = ''
|
last_ev_id = ''
|
||||||
tsc_enter = 0L
|
tsc_enter = 0
|
||||||
tsc_exit = 0L
|
tsc_exit = 0
|
||||||
tsc_last_exit_period = 0L
|
tsc_last_exit_period = 0
|
||||||
|
|
||||||
fd = open(ifile)
|
fd = open(ifile, 'rb')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -107,11 +107,11 @@ def parse_trace_data(ifile):
|
|||||||
|
|
||||||
if event == VM_ENTER:
|
if event == VM_ENTER:
|
||||||
if TSC_BEGIN == 0:
|
if TSC_BEGIN == 0:
|
||||||
TSC_BEGIN = long(tsc)
|
TSC_BEGIN = tsc
|
||||||
tsc_exit = long(tsc)
|
tsc_exit = tsc
|
||||||
TOTAL_NR_EXITS = 0
|
TOTAL_NR_EXITS = 0
|
||||||
|
|
||||||
tsc_enter = long(tsc)
|
tsc_enter = tsc
|
||||||
TSC_END = tsc_enter
|
TSC_END = tsc_enter
|
||||||
tsc_last_exit_period = tsc_enter - tsc_exit
|
tsc_last_exit_period = tsc_enter - tsc_exit
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ def parse_trace_data(ifile):
|
|||||||
TIME_IN_EXIT[last_ev_id] += tsc_last_exit_period
|
TIME_IN_EXIT[last_ev_id] += tsc_last_exit_period
|
||||||
|
|
||||||
elif event == VM_EXIT:
|
elif event == VM_EXIT:
|
||||||
tsc_exit = long(tsc)
|
tsc_exit = tsc
|
||||||
TSC_END = tsc_exit
|
TSC_END = tsc_exit
|
||||||
TOTAL_NR_EXITS += 1
|
TOTAL_NR_EXITS += 1
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ def parse_trace_data(ifile):
|
|||||||
# Skip the non-VMEXIT trace event
|
# Skip the non-VMEXIT trace event
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except IOError, struct.error:
|
except (IOError, struct.error) as e:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def generate_report(ofile, freq):
|
def generate_report(ofile, freq):
|
||||||
@ -151,7 +151,7 @@ def generate_report(ofile, freq):
|
|||||||
with open(csv_name, 'a') as filep:
|
with open(csv_name, 'a') as filep:
|
||||||
f_csv = csv.writer(filep)
|
f_csv = csv.writer(filep)
|
||||||
|
|
||||||
total_exit_time = 0L
|
total_exit_time = 0
|
||||||
rt_cycle = TSC_END - TSC_BEGIN
|
rt_cycle = TSC_END - TSC_BEGIN
|
||||||
assert rt_cycle != 0, "total_run_time in cycle is 0,\
|
assert rt_cycle != 0, "total_run_time in cycle is 0,\
|
||||||
tsc_end %d, tsc_begin %d"\
|
tsc_end %d, tsc_begin %d"\
|
||||||
@ -162,16 +162,16 @@ def generate_report(ofile, freq):
|
|||||||
for event in LIST_EVENTS:
|
for event in LIST_EVENTS:
|
||||||
total_exit_time += TIME_IN_EXIT[event]
|
total_exit_time += TIME_IN_EXIT[event]
|
||||||
|
|
||||||
print "Total run time: %d (cycles)" % (rt_cycle)
|
print ("Total run time: %d cycles" % (rt_cycle))
|
||||||
print "TSC Freq: %f MHz)" % (freq)
|
print ("TSC Freq: %f MHz" % (freq))
|
||||||
print "Total run time %d (Sec)" % (rt_sec)
|
print ("Total run time: %d sec" % (rt_sec))
|
||||||
|
|
||||||
f_csv.writerow(['Run time(cycles)', 'Run time(Sec)', 'Freq(MHz)'])
|
f_csv.writerow(['Run time(cycles)', 'Run time(Sec)', 'Freq(MHz)'])
|
||||||
f_csv.writerow(['%d' % (rt_cycle),
|
f_csv.writerow(['%d' % (rt_cycle),
|
||||||
'%.3f' % (rt_sec),
|
'%.3f' % (rt_sec),
|
||||||
'%d' % (freq)])
|
'%d' % (freq)])
|
||||||
|
|
||||||
print "Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed \tTime Percentage"
|
print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed \tTime Percentage")
|
||||||
f_csv.writerow(['Exit_Reason',
|
f_csv.writerow(['Exit_Reason',
|
||||||
'NR_Exit',
|
'NR_Exit',
|
||||||
'NR_Exit/Sec',
|
'NR_Exit/Sec',
|
||||||
@ -197,7 +197,7 @@ def generate_report(ofile, freq):
|
|||||||
f_csv.writerow(row)
|
f_csv.writerow(row)
|
||||||
|
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
print "Output File Error: " + str(err)
|
print ("Output File Error: " + str(err))
|
||||||
|
|
||||||
def analyze_vm_exit(ifile, ofile):
|
def analyze_vm_exit(ifile, ofile):
|
||||||
"""do the vm exits analysis
|
"""do the vm exits analysis
|
||||||
|
Loading…
Reference in New Issue
Block a user