Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: client/deps/realtimecomm_playground/pgutil.py

Issue 1224003: Add dep for playground (Closed)
Patch Set: Improvement from codereview Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/deps/realtimecomm_playground/pgutil.py
diff --git a/client/deps/realtimecomm_playground/pgutil.py b/client/deps/realtimecomm_playground/pgutil.py
new file mode 100644
index 0000000000000000000000000000000000000000..e3811232c030ea3261e6f6e73ae2e7358f433fb6
--- /dev/null
+++ b/client/deps/realtimecomm_playground/pgutil.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.client.bin import test, utils
+
+def get_pids(program_name):
+ """
+ Collect a list of pids for all the instances of a program.
+
+ @param program_name the name of the program
+ @return list of pids
+ """
+ pidlist = utils.system_output("pgrep -f \'%s\'" % program_name)
+ return pidlist.splitlines()
+
+
+def get_number_of_logical_cpu():
+ """
+ From /proc/stat/.
+
+ @return number of logic cpu
+ """
+ ret = utils.system_output("cat /proc/stat | grep ^cpu[0-9+] | wc -l")
+ return int(ret)
+
+
+def get_utime_stime(pids):
+ """
+ Snapshot the sum of utime and the sum of stime for a list of processes.
+
+ @param pids a list of pid
+ @return [sum_of_utime, sum_of_stime]
+ """
+ timelist = [0, 0]
+ for p in pids:
+ statFile = file("/proc/%s/stat" % p, "r")
+ T = statFile.readline().split(" ")[13:15]
+ statFile.close()
+ for i in range(len(timelist)):
+ timelist[i] = timelist[i] + int(T[i])
+ return timelist
+
+
+def get_cpu_usage(duration, time):
+ """
+ Calculate cpu usage based on duration and time on cpu.
+
+ @param duration
+ @param time on cpu
+ @return cpu usage
+ """
+ return float(time) / float(duration * get_number_of_logical_cpu())
+
« no previous file with comments | « client/deps/realtimecomm_playground/control ('k') | client/deps/realtimecomm_playground/realtimecomm_playground.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698