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:
Kaige Fu 2018-06-29 09:15:19 +08:00 committed by lijinxia
parent e75cca64c8
commit ad89a22011
4 changed files with 29 additions and 29 deletions

View File

@ -44,7 +44,7 @@ Usage
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):
.. code-block:: none
@ -56,7 +56,7 @@ Usage
a copy of the original data file is saved with suffix ``.orig``.
- Analysis report is written to stdout, or to a CSV file if
a filename is specified using ``-o filename``.
- The scripts require bash and python2.
- The scripts require Python3.
Build and Install
*****************

View File

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
@ -20,7 +20,7 @@ def usage():
Returns: None
Raises: NA
"""
print '''
print ('''
[Usage] acrnalyze.py [options] [value] ...
[options]
@ -30,7 +30,7 @@ def usage():
-f, --frequency=[unsigned int]: TSC frequency in MHz
--vm_exit: to generate vm_exit report
--irq: to generate irq related report
'''
''')
def do_analysis(ifile, ofile, analyzer):
"""do the specific analysis

View File

@ -9,8 +9,8 @@ import csv
import struct
from config import TSC_FREQ
TSC_BEGIN = 0L
TSC_END = 0L
TSC_BEGIN = 0
TSC_END = 0
VMEXIT_ENTRY = 0x10000
@ -44,13 +44,13 @@ def parse_trace(ifile):
event = event & 0xffffffffffff
if TSC_BEGIN == 0:
TSC_BEGIN = long(tsc)
TSC_BEGIN = tsc
TSC_END = long(tsc)
TSC_END = tsc
for key in LIST_EVENTS.keys():
if event == LIST_EVENTS.get(key):
if IRQ_EXITS.has_key(vec):
if vec in IRQ_EXITS.keys():
IRQ_EXITS[vec] += 1
else:
IRQ_EXITS[vec] = 1

View File

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
@ -9,9 +9,9 @@ import csv
import struct
from config import TSC_FREQ
TSC_BEGIN = 0L
TSC_END = 0L
TOTAL_NR_EXITS = 0L
TSC_BEGIN = 0
TSC_END = 0
TOTAL_NR_EXITS = 0
VM_EXIT = 0x10
VM_ENTER = 0x11
@ -90,11 +90,11 @@ def parse_trace_data(ifile):
global TSC_BEGIN, TSC_END, TOTAL_NR_EXITS
last_ev_id = ''
tsc_enter = 0L
tsc_exit = 0L
tsc_last_exit_period = 0L
tsc_enter = 0
tsc_exit = 0
tsc_last_exit_period = 0
fd = open(ifile)
fd = open(ifile, 'rb')
while True:
try:
@ -107,11 +107,11 @@ def parse_trace_data(ifile):
if event == VM_ENTER:
if TSC_BEGIN == 0:
TSC_BEGIN = long(tsc)
tsc_exit = long(tsc)
TSC_BEGIN = tsc
tsc_exit = tsc
TOTAL_NR_EXITS = 0
tsc_enter = long(tsc)
tsc_enter = tsc
TSC_END = tsc_enter
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
elif event == VM_EXIT:
tsc_exit = long(tsc)
tsc_exit = tsc
TSC_END = tsc_exit
TOTAL_NR_EXITS += 1
@ -133,7 +133,7 @@ def parse_trace_data(ifile):
# Skip the non-VMEXIT trace event
pass
except IOError, struct.error:
except (IOError, struct.error) as e:
sys.exit()
def generate_report(ofile, freq):
@ -151,7 +151,7 @@ def generate_report(ofile, freq):
with open(csv_name, 'a') as filep:
f_csv = csv.writer(filep)
total_exit_time = 0L
total_exit_time = 0
rt_cycle = TSC_END - TSC_BEGIN
assert rt_cycle != 0, "total_run_time in cycle is 0,\
tsc_end %d, tsc_begin %d"\
@ -162,16 +162,16 @@ def generate_report(ofile, freq):
for event in LIST_EVENTS:
total_exit_time += TIME_IN_EXIT[event]
print "Total run time: %d (cycles)" % (rt_cycle)
print "TSC Freq: %f MHz)" % (freq)
print "Total run time %d (Sec)" % (rt_sec)
print ("Total run time: %d cycles" % (rt_cycle))
print ("TSC Freq: %f MHz" % (freq))
print ("Total run time: %d sec" % (rt_sec))
f_csv.writerow(['Run time(cycles)', 'Run time(Sec)', 'Freq(MHz)'])
f_csv.writerow(['%d' % (rt_cycle),
'%.3f' % (rt_sec),
'%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',
'NR_Exit',
'NR_Exit/Sec',
@ -197,7 +197,7 @@ def generate_report(ofile, freq):
f_csv.writerow(row)
except IOError as err:
print "Output File Error: " + str(err)
print ("Output File Error: " + str(err))
def analyze_vm_exit(ifile, ofile):
"""do the vm exits analysis