diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/libwebrtc/tools_webrtc/cpu | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/tools_webrtc/cpu')
-rw-r--r-- | third_party/libwebrtc/tools_webrtc/cpu/OWNERS | 1 | ||||
-rw-r--r-- | third_party/libwebrtc/tools_webrtc/cpu/README | 12 | ||||
-rw-r--r-- | third_party/libwebrtc/tools_webrtc/cpu/cpu_mon.py | 83 |
3 files changed, 96 insertions, 0 deletions
diff --git a/third_party/libwebrtc/tools_webrtc/cpu/OWNERS b/third_party/libwebrtc/tools_webrtc/cpu/OWNERS new file mode 100644 index 0000000000..0fba125734 --- /dev/null +++ b/third_party/libwebrtc/tools_webrtc/cpu/OWNERS @@ -0,0 +1 @@ +tommi@webrtc.org diff --git a/third_party/libwebrtc/tools_webrtc/cpu/README b/third_party/libwebrtc/tools_webrtc/cpu/README new file mode 100644 index 0000000000..a0cee30a82 --- /dev/null +++ b/third_party/libwebrtc/tools_webrtc/cpu/README @@ -0,0 +1,12 @@ +This directory contains a little utility for doing CPU measurements. +It requires a Python package, psutil, to be installed. +See: https://pypi.python.org/pypi/psutil + +On mac you can install this package like so: +sudo ARCHFLAGS='-Wno-error=unused-command-line-argument-hard-error-in-future' easy_install psutil + +On Windows: +- TBD (see link above) + +On Linux: +- TBD (see link above) diff --git a/third_party/libwebrtc/tools_webrtc/cpu/cpu_mon.py b/third_party/libwebrtc/tools_webrtc/cpu/cpu_mon.py new file mode 100644 index 0000000000..9c25fbd088 --- /dev/null +++ b/third_party/libwebrtc/tools_webrtc/cpu/cpu_mon.py @@ -0,0 +1,83 @@ +#!/usr/bin/env vpython3 +# +# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import sys + +import psutil +import numpy +from matplotlib import pyplot + + +class CpuSnapshot: + def __init__(self, label): + self.label = label + self.samples = [] + + def Capture(self, sample_count): + print(('Capturing %d CPU samples for %s...' % + ((sample_count - len(self.samples)), self.label))) + while len(self.samples) < sample_count: + self.samples.append(psutil.cpu_percent(1.0, False)) + + def Text(self): + return ( + '%s: avg=%s, median=%s, min=%s, max=%s' % + (self.label, numpy.average(self.samples), numpy.median( + self.samples), numpy.min(self.samples), numpy.max(self.samples))) + + def Max(self): + return numpy.max(self.samples) + + +def GrabCpuSamples(sample_count): + print('Label for snapshot (enter to quit): ') + label = eval(input().strip()) + if len(label) == 0: + return None + + snapshot = CpuSnapshot(label) + snapshot.Capture(sample_count) + + return snapshot + + +def main(): + print('How many seconds to capture per snapshot (enter for 60)?') + sample_count = eval(input().strip()) + if len(sample_count) > 0 and int(sample_count) > 0: + sample_count = int(sample_count) + else: + print('Defaulting to 60 samples.') + sample_count = 60 + + snapshots = [] + while True: + snapshot = GrabCpuSamples(sample_count) + if snapshot is None: + break + snapshots.append(snapshot) + + if len(snapshots) == 0: + print('no samples captured') + return -1 + + pyplot.title('CPU usage') + + for s in snapshots: + pyplot.plot(s.samples, label=s.Text(), linewidth=2) + + pyplot.legend() + + pyplot.show() + return 0 + + +if __name__ == '__main__': + sys.exit(main()) |