1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-28 03:40:04 +00:00

Merge branch 'osg_stats' into 'master'

Add quality of life options to osg_stats.py

See merge request OpenMW/openmw!3360
This commit is contained in:
jvoisin 2023-08-19 15:12:33 +00:00
commit b53c758e13

View File

@ -9,10 +9,12 @@ import click
import collections import collections
import matplotlib.pyplot import matplotlib.pyplot
import numpy import numpy
import operator
import os.path
import re
import statistics import statistics
import sys import sys
import termtables import termtables
import re
@click.command() @click.command()
@ -59,12 +61,19 @@ import re
help='Frame duration metric name.') help='Frame duration metric name.')
@click.option('--threshold_value', type=float, default=1.05/60, @click.option('--threshold_value', type=float, default=1.05/60,
help='Threshold for hist_over.') 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) @click.argument('path', type=click.Path(), nargs=-1)
def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plot, stats, precision, def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plot, stats, precision,
timeseries_sum, stats_sum, begin_frame, end_frame, path, timeseries_sum, stats_sum, begin_frame, end_frame, path,
commulative_timeseries, commulative_timeseries_sum, frame_number_name, commulative_timeseries, commulative_timeseries_sum, frame_number_name,
hist_threshold, threshold_name, threshold_value): 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))} 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) keys = collect_unique_keys(sources)
frames, begin_frame, end_frame = collect_per_frame( frames, begin_frame, end_frame = collect_per_frame(
sources=sources, keys=keys, begin_frame=begin_frame, sources=sources, keys=keys, begin_frame=begin_frame,
@ -92,7 +101,7 @@ def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plo
if plot: if plot:
draw_plots(sources=frames, plots=plot) draw_plots(sources=frames, plots=plot)
if stats: 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: if hist_threshold:
draw_hist_threshold(sources=frames, keys=matching_keys(hist_threshold), begin_frame=begin_frame, draw_hist_threshold(sources=frames, keys=matching_keys(hist_threshold), begin_frame=begin_frame,
threshold_name=threshold_name, threshold_value=threshold_value) threshold_name=threshold_name, threshold_value=threshold_value)
@ -253,7 +262,7 @@ def draw_plots(sources, plots):
fig.canvas.manager.set_window_title('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() stats = list()
for name, frames in sources.items(): for name, frames in sources.items():
for key in keys: for key in keys:
@ -261,6 +270,8 @@ def print_stats(sources, keys, stats_sum, precision):
if stats_sum: if stats_sum:
stats.append(make_stats(source=name, key='sum', values=sum_multiple(frames, keys), precision=precision)) stats.append(make_stats(source=name, key='sum', values=sum_multiple(frames, keys), precision=precision))
metrics = list(stats[0].keys()) metrics = list(stats[0].keys())
if sort_by:
stats.sort(key=operator.itemgetter(*sort_by))
termtables.print( termtables.print(
[list(v.values()) for v in stats], [list(v.values()) for v in stats],
header=metrics, header=metrics,