tools_webrtc dir converted to py3 + top level PRESUBMIT script
Bug: webrtc:13607 Change-Id: Ib018e43ea977cc24dd71048e68e3343741f7f31b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249083 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Jeremy Leconte <jleconte@google.com> Commit-Queue: Christoffer Jansson <jansson@google.com> Cr-Commit-Position: refs/heads/main@{#35953}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
b5cba85c2f
commit
4e8a773b4b
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env vpython3
|
||||
#
|
||||
# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||
#
|
||||
@ -8,76 +8,76 @@
|
||||
# in the file PATENTS. All contributing project authors may
|
||||
# be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
import psutil
|
||||
import numpy
|
||||
from matplotlib import pyplot
|
||||
|
||||
|
||||
class CpuSnapshot(object):
|
||||
def __init__(self, label):
|
||||
self.label = label
|
||||
self.samples = []
|
||||
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 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 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 Max(self):
|
||||
return numpy.max(self.samples)
|
||||
|
||||
|
||||
def GrabCpuSamples(sample_count):
|
||||
print 'Label for snapshot (enter to quit): '
|
||||
label = raw_input().strip()
|
||||
if len(label) == 0:
|
||||
return None
|
||||
print('Label for snapshot (enter to quit): ')
|
||||
label = eval(input().strip())
|
||||
if len(label) == 0:
|
||||
return None
|
||||
|
||||
snapshot = CpuSnapshot(label)
|
||||
snapshot.Capture(sample_count)
|
||||
snapshot = CpuSnapshot(label)
|
||||
snapshot.Capture(sample_count)
|
||||
|
||||
return snapshot
|
||||
return snapshot
|
||||
|
||||
|
||||
def main():
|
||||
print 'How many seconds to capture per snapshot (enter for 60)?'
|
||||
sample_count = raw_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
|
||||
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)
|
||||
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
|
||||
if len(snapshots) == 0:
|
||||
print('no samples captured')
|
||||
return -1
|
||||
|
||||
pyplot.title('CPU usage')
|
||||
pyplot.title('CPU usage')
|
||||
|
||||
for s in snapshots:
|
||||
pyplot.plot(s.samples, label=s.Text(), linewidth=2)
|
||||
for s in snapshots:
|
||||
pyplot.plot(s.samples, label=s.Text(), linewidth=2)
|
||||
|
||||
pyplot.legend()
|
||||
pyplot.legend()
|
||||
|
||||
pyplot.show()
|
||||
return 0
|
||||
pyplot.show()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user