From faded22e4157c16952be36ac898a98f29443e3f4 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 19 Aug 2023 13:47:05 +0200 Subject: [PATCH 1/2] Hide common path prefix by default --- scripts/osg_stats.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/osg_stats.py b/scripts/osg_stats.py index 804b09b909..fcd6f45fc0 100755 --- a/scripts/osg_stats.py +++ b/scripts/osg_stats.py @@ -9,10 +9,11 @@ import click import collections import matplotlib.pyplot import numpy +import os.path +import re import statistics import sys import termtables -import re @click.command() @@ -59,12 +60,17 @@ import re help='Frame duration metric name.') @click.option('--threshold_value', type=float, default=1.05/60, help='Threshold for hist_over.') +@click.option('--show_common_path_prefix', is_flag=True, + help='Show common path prefix when applied to multiple files.') @click.argument('path', type=click.Path(), nargs=-1) def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plot, stats, precision, timeseries_sum, stats_sum, begin_frame, end_frame, path, commulative_timeseries, commulative_timeseries_sum, frame_number_name, - hist_threshold, threshold_name, threshold_value): + hist_threshold, threshold_name, threshold_value, show_common_path_prefix): sources = {v: list(read_data(v)) for v in path} if path else {'stdin': list(read_data(None))} + if not show_common_path_prefix and len(sources) > 1: + longest_common_prefix = os.path.commonprefix(list(sources.keys())) + sources = {k.removeprefix(longest_common_prefix): v for k, v in sources.items()} keys = collect_unique_keys(sources) frames, begin_frame, end_frame = collect_per_frame( sources=sources, keys=keys, begin_frame=begin_frame, From 9019a815ebfda8571c40dffc70e3d7bfb1e1ed13 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 19 Aug 2023 14:04:32 +0200 Subject: [PATCH 2/2] Add option to sort stats fields --- scripts/osg_stats.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/osg_stats.py b/scripts/osg_stats.py index fcd6f45fc0..d8dab2ad1a 100755 --- a/scripts/osg_stats.py +++ b/scripts/osg_stats.py @@ -9,6 +9,7 @@ import click import collections import matplotlib.pyplot import numpy +import operator import os.path import re import statistics @@ -62,11 +63,13 @@ import termtables help='Threshold for hist_over.') @click.option('--show_common_path_prefix', is_flag=True, help='Show common path prefix when applied to multiple files.') +@click.option('--stats_sort_by', type=str, default=None, multiple=True, + help='Sort stats table by given fields (source, key, sum, min, max etc).') @click.argument('path', type=click.Path(), nargs=-1) def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plot, stats, precision, timeseries_sum, stats_sum, begin_frame, end_frame, path, commulative_timeseries, commulative_timeseries_sum, frame_number_name, - hist_threshold, threshold_name, threshold_value, show_common_path_prefix): + hist_threshold, threshold_name, threshold_value, show_common_path_prefix, stats_sort_by): sources = {v: list(read_data(v)) for v in path} if path else {'stdin': list(read_data(None))} if not show_common_path_prefix and len(sources) > 1: longest_common_prefix = os.path.commonprefix(list(sources.keys())) @@ -98,7 +101,7 @@ def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plo if plot: draw_plots(sources=frames, plots=plot) if stats: - print_stats(sources=frames, keys=matching_keys(stats), stats_sum=stats_sum, precision=precision) + print_stats(sources=frames, keys=matching_keys(stats), stats_sum=stats_sum, precision=precision, sort_by=stats_sort_by) if hist_threshold: draw_hist_threshold(sources=frames, keys=matching_keys(hist_threshold), begin_frame=begin_frame, threshold_name=threshold_name, threshold_value=threshold_value) @@ -259,7 +262,7 @@ def draw_plots(sources, plots): fig.canvas.manager.set_window_title('plots') -def print_stats(sources, keys, stats_sum, precision): +def print_stats(sources, keys, stats_sum, precision, sort_by): stats = list() for name, frames in sources.items(): for key in keys: @@ -267,6 +270,8 @@ def print_stats(sources, keys, stats_sum, precision): if stats_sum: stats.append(make_stats(source=name, key='sum', values=sum_multiple(frames, keys), precision=precision)) metrics = list(stats[0].keys()) + if sort_by: + stats.sort(key=operator.itemgetter(*sort_by)) termtables.print( [list(v.values()) for v in stats], header=metrics,