You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #!/usr/bin/env python
  2. # Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
  3. #
  4. # Use of this source code is governed by a BSD-style license
  5. # that can be found in the LICENSE file in the root of the source
  6. # tree. An additional intellectual property rights grant can be found
  7. # in the file PATENTS. All contributing project authors may
  8. # be found in the AUTHORS file in the root of the source tree.
  9. """Plots metrics from stdin.
  10. Expected format:
  11. PLOTTABLE_DATA: <json data>
  12. Where json data has the following format:
  13. {
  14. "graph_name": "<graph name>",
  15. "trace_name": "<test suite name>",
  16. "units": "<units>",
  17. "mean": <mean value>,
  18. "std": <standard deviation value>,
  19. "samples": [
  20. { "time": <sample time in us>, "value": <sample value> },
  21. ...
  22. ]
  23. }
  24. """
  25. import fileinput
  26. import json
  27. import matplotlib.pyplot as plt
  28. LINE_PREFIX = 'PLOTTABLE_DATA: '
  29. GRAPH_NAME = 'graph_name'
  30. TRACE_NAME = 'trace_name'
  31. UNITS = 'units'
  32. MICROSECONDS_IN_SECOND = 1e6
  33. def main():
  34. metrics = []
  35. for line in fileinput.input():
  36. line = line.strip()
  37. if line.startswith(LINE_PREFIX):
  38. line = line.replace(LINE_PREFIX, '')
  39. metrics.append(json.loads(line))
  40. else:
  41. print line
  42. for metric in metrics:
  43. figure = plt.figure()
  44. figure.canvas.set_window_title(metric[TRACE_NAME])
  45. x_values = []
  46. y_values = []
  47. start_x = None
  48. for sample in metric['samples']:
  49. if start_x is None:
  50. start_x = sample['time']
  51. # Time is us, we want to show it in seconds.
  52. x_values.append((sample['time'] - start_x) / MICROSECONDS_IN_SECOND)
  53. y_values.append(sample['value'])
  54. plt.ylabel('%s (%s)' % (metric[GRAPH_NAME], metric[UNITS]))
  55. plt.xlabel('time (s)')
  56. plt.title(metric[GRAPH_NAME])
  57. plt.plot(x_values, y_values)
  58. plt.show()
  59. if __name__ == '__main__':
  60. main()