tools: acrntrace: Add irq related analyzer
This analyzer is implemented in vmexit_analyze. This patch make it as independent analyzer with an option "--irq" Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com> Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
This commit is contained in:
parent
8a233eec63
commit
136d5c30fb
|
@ -12,6 +12,7 @@ import getopt
|
||||||
import os
|
import os
|
||||||
import config
|
import config
|
||||||
from vmexit_analyze import analyze_vm_exit
|
from vmexit_analyze import analyze_vm_exit
|
||||||
|
from irq_analyze import analyze_irq
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
"""print the usage of the script
|
"""print the usage of the script
|
||||||
|
@ -28,6 +29,7 @@ def usage():
|
||||||
-o, --ofile=[string]: output file
|
-o, --ofile=[string]: output file
|
||||||
-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
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def do_analysis(ifile, ofile, analyzer):
|
def do_analysis(ifile, ofile, analyzer):
|
||||||
|
@ -58,7 +60,7 @@ def main(argv):
|
||||||
inputfile = ''
|
inputfile = ''
|
||||||
outputfile = ''
|
outputfile = ''
|
||||||
opts_short = "hi:o:f:"
|
opts_short = "hi:o:f:"
|
||||||
opts_long = ["ifile=", "ofile=", "frequency=", "vm_exit"]
|
opts_long = ["ifile=", "ofile=", "frequency=", "vm_exit", "irq"]
|
||||||
analyzer = []
|
analyzer = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -79,6 +81,8 @@ def main(argv):
|
||||||
TSC_FREQ = arg
|
TSC_FREQ = arg
|
||||||
elif opt == "--vm_exit":
|
elif opt == "--vm_exit":
|
||||||
analyzer.append(analyze_vm_exit)
|
analyzer.append(analyze_vm_exit)
|
||||||
|
elif opt == "--irq":
|
||||||
|
analyzer.append(analyze_irq)
|
||||||
else:
|
else:
|
||||||
assert False, "unhandled option"
|
assert False, "unhandled option"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
This script defines the function to do the irq related analysis
|
||||||
|
"""
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import struct
|
||||||
|
from config import TSC_FREQ
|
||||||
|
|
||||||
|
TSC_BEGIN = 0L
|
||||||
|
TSC_END = 0L
|
||||||
|
|
||||||
|
VMEXIT_ENTRY = 0x10000
|
||||||
|
|
||||||
|
LIST_EVENTS = {
|
||||||
|
'VMEXIT_EXTERNAL_INTERRUPT': VMEXIT_ENTRY + 0x00000001,
|
||||||
|
}
|
||||||
|
|
||||||
|
IRQ_EXITS = {}
|
||||||
|
|
||||||
|
# 4 * 64bit per trace entry
|
||||||
|
TRCREC = "QQQQ"
|
||||||
|
|
||||||
|
def parse_trace(ifile):
|
||||||
|
"""parse the trace data file
|
||||||
|
Args:
|
||||||
|
ifile: input trace data file
|
||||||
|
Return:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
|
||||||
|
fd = open(ifile, 'rb')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
global TSC_BEGIN, TSC_END
|
||||||
|
try:
|
||||||
|
line = fd.read(struct.calcsize(TRCREC))
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
(tsc, event, vec, d2) = struct.unpack(TRCREC, line)
|
||||||
|
|
||||||
|
event = event & 0xffffffffffff
|
||||||
|
|
||||||
|
if TSC_BEGIN == 0:
|
||||||
|
TSC_BEGIN = long(tsc)
|
||||||
|
|
||||||
|
TSC_END = long(tsc)
|
||||||
|
|
||||||
|
for key in LIST_EVENTS.keys():
|
||||||
|
if event == LIST_EVENTS.get(key):
|
||||||
|
if IRQ_EXITS.has_key(vec):
|
||||||
|
IRQ_EXITS[vec] += 1
|
||||||
|
else:
|
||||||
|
IRQ_EXITS[vec] = 1
|
||||||
|
|
||||||
|
except struct.error:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
def generate_report(ofile, freq):
|
||||||
|
""" generate analysis report
|
||||||
|
Args:
|
||||||
|
ofile: output report
|
||||||
|
freq: TSC frequency of the device trace data from
|
||||||
|
Return:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
global TSC_BEGIN, TSC_END
|
||||||
|
|
||||||
|
csv_name = ofile + '.csv'
|
||||||
|
try:
|
||||||
|
with open(csv_name, 'a') as filep:
|
||||||
|
f_csv = csv.writer(filep)
|
||||||
|
|
||||||
|
rt_cycle = TSC_END - TSC_BEGIN
|
||||||
|
assert rt_cycle != 0, "Total run time in cycle is 0, \
|
||||||
|
TSC end %d, TSC begin %d" \
|
||||||
|
% (TSC_END, TSC_BEGIN)
|
||||||
|
|
||||||
|
rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)
|
||||||
|
|
||||||
|
print ("\nVector \t\tCount \tNR_Exit/Sec")
|
||||||
|
f_csv.writerow(['Vector', 'NR_Exit', 'NR_Exit/Sec'])
|
||||||
|
for e in IRQ_EXITS.keys():
|
||||||
|
pct = float(IRQ_EXITS[e]) / rt_sec
|
||||||
|
print ("0x%08x \t %d \t%.2f" % (e, IRQ_EXITS[e], pct))
|
||||||
|
f_csv.writerow([e, IRQ_EXITS[e], '%.2f' % pct])
|
||||||
|
|
||||||
|
except IOError as err:
|
||||||
|
print ("Output File Error: " + str(err))
|
||||||
|
|
||||||
|
def analyze_irq(ifile, ofile):
|
||||||
|
"""do the vm exits analysis
|
||||||
|
Args:
|
||||||
|
ifile: input trace data file
|
||||||
|
ofile: output report file
|
||||||
|
Return:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
|
||||||
|
print("IRQ analysis started... \n\tinput file: %s\n"
|
||||||
|
"\toutput file: %s.csv" % (ifile, ofile))
|
||||||
|
|
||||||
|
parse_trace(ifile)
|
||||||
|
# save report to the output file
|
||||||
|
generate_report(ofile, TSC_FREQ)
|
Loading…
Reference in New Issue