def main(): global from_time global cap_time # Suppress future warnings warnings.simplefilter(action='ignore', category=FutureWarning) parser = OptionParser(usage="usage: %prog [options] <cdict_file1> [cdict_file2...]") parser.add_option("-t", "--task", dest="task", metavar="task name (regex)", help="selected task(s) (regex on task name)" ) parser.add_option("--label", dest="label", metavar="label", help="label for the title (defaults to the cdict file name)" ) parser.add_option("--map", dest="map", action="store", metavar="mapping csv file", help="remap task names from mapping csv file" ) parser.add_option("--output-dir", dest="output_dir", action="store", metavar="dir pathname", help="output all html files to the provided directory" ) parser.add_option("--heatmaps", dest="heatmaps", action="store_true", help="generate heatmap charts only (default: generate basic charts only)" ) parser.add_option("--headless", dest="headless", action="store_true", help="do not show chart in the browser (default=False)" ) parser.add_option("-c", "--cap", dest="cap_time", help="(optional) cap the analysis to first <cap_time> msec" " of capture (default=all)" ) parser.add_option("-f", "--from", dest="from_time", help="(optional) start the analysis after first <from_time> msec" " of capture (default=0)" ) parser.add_option("--merge-sys-tasks", dest="merge_sys_tasks", action="store_true", help="group all system tasks (e.g. swapper/0 -> swapper)" ) parser.add_option("--successors-of", dest="successor_of_task", help="only show list of successors of given tid or task name" ) parser.add_option("--list", dest="list", action="store_true", default=False, help="only show list of all tasks with event count" ) (options, args) = parser.parse_args() if options.from_time: from_time = int(options.from_time) * 1000 if options.cap_time: # convert to usec cap_time = int(options.cap_time) * 1000 + from_time if not args: print 'Missing cdict file' sys.exit(1) if options.output_dir: if not os.path.isdir(options.output_dir): print('Invalid output directory: ' + options.output_dir) sys.exit(1) dfds = [] cdict_files = args if len(cdict_files): if len(cdict_files) > 1: html_filename = cdict_files[0] + '-diff' else: html_filename = cdict_files[0] else: html_filename = cdict_files[0] if len(cdict_files) else 'perfwhiz' set_html_file(html_filename, options.headless, options.label, options.output_dir) # get smallest capture window of all cdicts min_cap_usec = 0 for cdict_file in cdict_files: perf_dict = open_cdict(cdict_file, options.map) df = DataFrame(perf_dict) dfd = DfDesc(cdict_file, df, options.merge_sys_tasks) dfds.append(dfd) last_usec = df['usecs'].iloc[-1] if min_cap_usec == 0: min_cap_usec = last_usec else: min_cap_usec = min(min_cap_usec, last_usec) if from_time and from_time >= min_cap_usec: print 'Error: from time cannot be larger than %d msec' % (min_cap_usec / 1000) sys.exit(2) # if a cap time is provided, always use that value (even if it is >min_cap_usec) if not cap_time: cap_time = min_cap_usec # normalize all dataframes for dfd in dfds: dfd.normalize(from_time, cap_time) # at this point some cdict entries may have "missing" data # if the requested cap_time is > the cdict cap time # the relevant processing will extrapolate when needed (and if possible) # reduce all names to minimize the length o;f the cdict file name set_short_names(dfds) if not options.label: if len(dfds) > 1: options.label = 'diff' else: options.label = os.path.splitext(os.path.basename(cdict_file))[0] if options.list: print 'List of tids and task names sorted by context switches and kvm event count' for dfd in dfds: print dfd.name + ':' res = dfd.df.groupby(['pid', 'task_name']).size() res.sort_values(ascending=False, inplace=True) pandas.set_option('display.max_rows', len(res)) print res sys.exit(0) if options.successor_of_task: for dfd in dfds: print dfd.name + ':' show_successors(dfd.df, options.successor_of_task, options.label) sys.exit(0) # These options can be cumulative and all require a --task parameter to select tasks if not options.task: print '--task <task_regex> is required' sys.exit(1) # A common mistake is to forget the head "." before a star ("*.vcpu0") # Better detect and fix to avoid frustration if options.task.startswith("*"): options.task = "." + options.task # create heatmaps only if one cdict was given if options.heatmaps: if len(dfds) == 1: create_heatmaps(dfds[0], cap_time, options.task, options.label) else: print 'Error: --heat-maps requires 1 cdict file only' sys.exit(1) else: create_charts(dfds, cap_time, options.task, options.label)
with open(cdict_file, 'r') as ff: cdict = ff.read() decomp = zlib.decompress(cdict) try: perf_dict = unpackb(decomp) except Exception: # old serialization format perf_dict = marshal.loads(decomp) if options.map: remap(perf_dict, options.map) df = DataFrame(perf_dict) set_html_file(cdict_file) # filter on usecs if from_time: df = df[df['usecs'] >= from_time] if cap_time: df = df[df['usecs'] <= cap_time] if not options.label: options.label = os.path.splitext(os.path.basename(cdict_file))[0] if options.convert: convert(df, options.convert) sys.exit(0)
if options.from_time: from_time = int(options.from_time) * 1000 if options.cap_time: # convert to usec cap_time = int(options.cap_time) * 1000 + from_time if not args: print 'Missing cdict file' sys.exit(1) cdict_file = args[0] perf_dict = open_cdict(cdict_file, options.map) df = DataFrame(perf_dict) set_html_file(cdict_file, options.headless) # filter on usecs if from_time: df = df[df['usecs'] >= from_time] if cap_time: df = df[df['usecs'] <= cap_time] if not options.label: options.label = os.path.splitext(os.path.basename(cdict_file))[0] if options.convert: convert(df, options.convert) sys.exit(0) if options.show_tids:
if options.from_time: from_time = int(options.from_time) * 1000 if options.cap_time: # convert to usec cap_time = int(options.cap_time) * 1000 + from_time if not args: print 'Missing cdict file' sys.exit(1) cdict_file = args[0] perf_dict = open_cdict(cdict_file, options.map) df = DataFrame(perf_dict) set_html_file(cdict_file, options.headless) # filter on usecs if from_time: df = df[df['usecs'] >= from_time] if cap_time: df = df[df['usecs'] <= cap_time] if not options.label: options.label = os.path.splitext(os.path.basename(cdict_file))[0] if options.convert: convert(df, options.convert) sys.exit(0) if options.show_tids: