acrn-hypervisor/misc/debug_tools/acrn_trace/scripts/acrnalyze.py
nacui 512c98fd79 hv: trace: show cpu usage of vms in pcpu sharing case
To maximize the cpu utilization, core 0 is usually shared by service
vm and guest vm. But there are no statistics to show the cpu occupation
of each vm.

This patch is to provide cpu usage statistic for users. To calculate
it, a new trace event is added and marked in scheduling context switch,
accompanying with a new python script to analyze the data from acrntrace
output.

Tracked-On: #8621
Signed-off-by: nacui <na.cui@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Reviewed-by: Haiwei Li <haiwei.li@intel.com>
2024-06-28 12:55:23 +08:00

103 lines
2.5 KiB
Python
Executable File

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
This is the main script of arnalyzer, which:
- parse the options
- call a specific script to do analysis
"""
import sys
import getopt
import os
from vmexit_analyze import analyze_vm_exit
from irq_analyze import analyze_irq
from cpuusage_analyze import analyze_cpu_usage
def usage():
"""print the usage of the script
Args: NA
Returns: None
Raises: NA
"""
print ('''
[Usage] acrnalyze.py [options] [value] ...
[options]
-h: print this message
-i, --ifile=[string]: input file
-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
--cpu_usage: to generate cpu_usage report
''')
def do_analysis(ifile, ofile, analyzer, freq):
"""do the specific analysis
Args:
ifile: input trace data file
ofile: output analysis report file
analyzer: a function do the specific analysis
freq: TSC frequency of the host where we capture the trace data
Returns:
None
Raises:
NA
"""
for alyer in analyzer:
alyer(ifile, ofile, freq)
def main(argv):
"""Main enterance function
Args:
argv: arguments string
Returns:
None
Raises:
GetoptError
"""
inputfile = ''
outputfile = ''
# Default TSC frequency of MRB in MHz
freq = 1881.6
opts_short = "hi:o:f:"
opts_long = ["ifile=", "ofile=", "frequency=", "vm_exit", "irq", "cpu_usage"]
analyzer = []
try:
opts, args = getopt.getopt(argv, opts_short, opts_long)
except getopt.GetoptError:
usage()
sys.exit(1)
for opt, arg in opts:
if opt == '-h':
usage()
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
elif opt in ("-f", "--frequency"):
freq = arg
elif opt == "--vm_exit":
analyzer.append(analyze_vm_exit)
elif opt == "--irq":
analyzer.append(analyze_irq)
elif opt == "--cpu_usage":
analyzer.append(analyze_cpu_usage)
else:
assert False, "unhandled option"
assert inputfile != '', "input file is required"
assert outputfile != '', "output file is required"
assert analyzer != '', 'MUST contain one of analyzer: ''vm_exit'
do_analysis(inputfile, outputfile, analyzer, freq)
if __name__ == "__main__":
main(sys.argv[1:])