Skip to content

Commit ad89a22

Browse files
KaigeFulijinxia
authored andcommitted
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>
1 parent e75cca6 commit ad89a22

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

tools/acrntrace/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Usage
4444
4545
Replace username and hostname with appropriate values.
4646

47-
#. On the Linux system, run the provided python2 script to analyze the
47+
#. On the Linux system, run the provided Python3 script to analyze the
4848
``vm_exits`` (currently only vm_exit analysis is supported):
4949

5050
.. code-block:: none
@@ -56,7 +56,7 @@ Usage
5656
a copy of the original data file is saved with suffix ``.orig``.
5757
- Analysis report is written to stdout, or to a CSV file if
5858
a filename is specified using ``-o filename``.
59-
- The scripts require bash and python2.
59+
- The scripts require Python3.
6060

6161
Build and Install
6262
*****************

tools/acrntrace/scripts/acrnalyze.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2
1+
#!/usr/bin/python3
22
# -*- coding: UTF-8 -*-
33

44
"""
@@ -20,7 +20,7 @@ def usage():
2020
Returns: None
2121
Raises: NA
2222
"""
23-
print '''
23+
print ('''
2424
[Usage] acrnalyze.py [options] [value] ...
2525
2626
[options]
@@ -30,7 +30,7 @@ def usage():
3030
-f, --frequency=[unsigned int]: TSC frequency in MHz
3131
--vm_exit: to generate vm_exit report
3232
--irq: to generate irq related report
33-
'''
33+
''')
3434

3535
def do_analysis(ifile, ofile, analyzer):
3636
"""do the specific analysis

tools/acrntrace/scripts/irq_analyze.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import struct
1010
from config import TSC_FREQ
1111

12-
TSC_BEGIN = 0L
13-
TSC_END = 0L
12+
TSC_BEGIN = 0
13+
TSC_END = 0
1414

1515
VMEXIT_ENTRY = 0x10000
1616

@@ -44,13 +44,13 @@ def parse_trace(ifile):
4444
event = event & 0xffffffffffff
4545

4646
if TSC_BEGIN == 0:
47-
TSC_BEGIN = long(tsc)
47+
TSC_BEGIN = tsc
4848

49-
TSC_END = long(tsc)
49+
TSC_END = tsc
5050

5151
for key in LIST_EVENTS.keys():
5252
if event == LIST_EVENTS.get(key):
53-
if IRQ_EXITS.has_key(vec):
53+
if vec in IRQ_EXITS.keys():
5454
IRQ_EXITS[vec] += 1
5555
else:
5656
IRQ_EXITS[vec] = 1

tools/acrntrace/scripts/vmexit_analyze.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2
1+
#!/usr/bin/python3
22
# -*- coding: UTF-8 -*-
33

44
"""
@@ -9,9 +9,9 @@
99
import struct
1010
from config import TSC_FREQ
1111

12-
TSC_BEGIN = 0L
13-
TSC_END = 0L
14-
TOTAL_NR_EXITS = 0L
12+
TSC_BEGIN = 0
13+
TSC_END = 0
14+
TOTAL_NR_EXITS = 0
1515

1616
VM_EXIT = 0x10
1717
VM_ENTER = 0x11
@@ -90,11 +90,11 @@ def parse_trace_data(ifile):
9090

9191
global TSC_BEGIN, TSC_END, TOTAL_NR_EXITS
9292
last_ev_id = ''
93-
tsc_enter = 0L
94-
tsc_exit = 0L
95-
tsc_last_exit_period = 0L
93+
tsc_enter = 0
94+
tsc_exit = 0
95+
tsc_last_exit_period = 0
9696

97-
fd = open(ifile)
97+
fd = open(ifile, 'rb')
9898

9999
while True:
100100
try:
@@ -107,19 +107,19 @@ def parse_trace_data(ifile):
107107

108108
if event == VM_ENTER:
109109
if TSC_BEGIN == 0:
110-
TSC_BEGIN = long(tsc)
111-
tsc_exit = long(tsc)
110+
TSC_BEGIN = tsc
111+
tsc_exit = tsc
112112
TOTAL_NR_EXITS = 0
113113

114-
tsc_enter = long(tsc)
114+
tsc_enter = tsc
115115
TSC_END = tsc_enter
116116
tsc_last_exit_period = tsc_enter - tsc_exit
117117

118118
if tsc_last_exit_period != 0:
119119
TIME_IN_EXIT[last_ev_id] += tsc_last_exit_period
120120

121121
elif event == VM_EXIT:
122-
tsc_exit = long(tsc)
122+
tsc_exit = tsc
123123
TSC_END = tsc_exit
124124
TOTAL_NR_EXITS += 1
125125

@@ -133,7 +133,7 @@ def parse_trace_data(ifile):
133133
# Skip the non-VMEXIT trace event
134134
pass
135135

136-
except IOError, struct.error:
136+
except (IOError, struct.error) as e:
137137
sys.exit()
138138

139139
def generate_report(ofile, freq):
@@ -151,7 +151,7 @@ def generate_report(ofile, freq):
151151
with open(csv_name, 'a') as filep:
152152
f_csv = csv.writer(filep)
153153

154-
total_exit_time = 0L
154+
total_exit_time = 0
155155
rt_cycle = TSC_END - TSC_BEGIN
156156
assert rt_cycle != 0, "total_run_time in cycle is 0,\
157157
tsc_end %d, tsc_begin %d"\
@@ -162,16 +162,16 @@ def generate_report(ofile, freq):
162162
for event in LIST_EVENTS:
163163
total_exit_time += TIME_IN_EXIT[event]
164164

165-
print "Total run time: %d (cycles)" % (rt_cycle)
166-
print "TSC Freq: %f MHz)" % (freq)
167-
print "Total run time %d (Sec)" % (rt_sec)
165+
print ("Total run time: %d cycles" % (rt_cycle))
166+
print ("TSC Freq: %f MHz" % (freq))
167+
print ("Total run time: %d sec" % (rt_sec))
168168

169169
f_csv.writerow(['Run time(cycles)', 'Run time(Sec)', 'Freq(MHz)'])
170170
f_csv.writerow(['%d' % (rt_cycle),
171171
'%.3f' % (rt_sec),
172172
'%d' % (freq)])
173173

174-
print "Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed \tTime Percentage"
174+
print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed \tTime Percentage")
175175
f_csv.writerow(['Exit_Reason',
176176
'NR_Exit',
177177
'NR_Exit/Sec',
@@ -197,7 +197,7 @@ def generate_report(ofile, freq):
197197
f_csv.writerow(row)
198198

199199
except IOError as err:
200-
print "Output File Error: " + str(err)
200+
print ("Output File Error: " + str(err))
201201

202202
def analyze_vm_exit(ifile, ofile):
203203
"""do the vm exits analysis

0 commit comments

Comments
 (0)