diff --git a/tools/acrntrace/scripts/acrnalyze.py b/tools/acrntrace/scripts/acrnalyze.py index b56a984a4..d09edf095 100755 --- a/tools/acrntrace/scripts/acrnalyze.py +++ b/tools/acrntrace/scripts/acrnalyze.py @@ -12,6 +12,7 @@ import getopt import os import config from vmexit_analyze import analyze_vm_exit +from irq_analyze import analyze_irq def usage(): """print the usage of the script @@ -28,6 +29,7 @@ def usage(): -o, --ofile=[string]: output file -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): @@ -58,7 +60,7 @@ def main(argv): inputfile = '' outputfile = '' opts_short = "hi:o:f:" - opts_long = ["ifile=", "ofile=", "frequency=", "vm_exit"] + opts_long = ["ifile=", "ofile=", "frequency=", "vm_exit", "irq"] analyzer = [] try: @@ -79,6 +81,8 @@ def main(argv): TSC_FREQ = arg elif opt == "--vm_exit": analyzer.append(analyze_vm_exit) + elif opt == "--irq": + analyzer.append(analyze_irq) else: assert False, "unhandled option" diff --git a/tools/acrntrace/scripts/irq_analyze.py b/tools/acrntrace/scripts/irq_analyze.py new file mode 100755 index 000000000..a4a40050d --- /dev/null +++ b/tools/acrntrace/scripts/irq_analyze.py @@ -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)