From 0b9e354d61dbacbc21086216c916c820f5cba1fa Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Tue, 29 Sep 2020 15:14:06 +0200 Subject: [PATCH] Improve perf metrics plotter Add ability to specify which metrics to plot on the plotter level and add sorting of plottable data because there is no guarantee on the perf writer side that output is sorted by time. Bug: webrtc:11959 Change-Id: I87e6f5720fff2b259f58e3fc5f7ed2462568e0d3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185963 Reviewed-by: Mirko Bonadei Commit-Queue: Artem Titov Cr-Commit-Position: refs/heads/master@{#32233} --- rtc_tools/metrics_plotter.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rtc_tools/metrics_plotter.py b/rtc_tools/metrics_plotter.py index 54ccee9c01..37a9d63546 100644 --- a/rtc_tools/metrics_plotter.py +++ b/rtc_tools/metrics_plotter.py @@ -24,6 +24,7 @@ Where json data has the following format: } """ +import argparse import fileinput import json import matplotlib.pyplot as plt @@ -38,8 +39,19 @@ MICROSECONDS_IN_SECOND = 1e6 def main(): + parser = argparse.ArgumentParser( + description='Plots metrics exported from WebRTC perf tests') + parser.add_argument('-m', '--metrics', type=str, nargs='*', + help='Metrics to plot. If nothing specified then will plot all available') + args = parser.parse_args() + + metrics_to_plot = set() + if args.metrics: + for metric in args.metrics: + metrics_to_plot.add(metric) + metrics = [] - for line in fileinput.input(): + for line in fileinput.input('-'): line = line.strip() if line.startswith(LINE_PREFIX): line = line.replace(LINE_PREFIX, '') @@ -48,13 +60,18 @@ def main(): print line for metric in metrics: + if len(metrics_to_plot) > 0 and metric[GRAPH_NAME] not in metrics_to_plot: + continue + figure = plt.figure() figure.canvas.set_window_title(metric[TRACE_NAME]) x_values = [] y_values = [] start_x = None - for sample in metric['samples']: + samples = metric['samples'] + samples.sort(key=lambda x: x['time']) + for sample in samples: if start_x is None: start_x = sample['time'] # Time is us, we want to show it in seconds.