summaryrefslogtreecommitdiff
path: root/scripts/backends_cpu_usage/log_cpu_usage.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-04-04 16:34:57 -0300
committerTomás Touceda <chiiph@leap.se>2014-04-04 16:34:57 -0300
commitce22976cc0e203e53799e771aa5e3717d498cc5c (patch)
tree8c69733f1f8a83ac83e40bf7e522a5fe8eae9b50 /scripts/backends_cpu_usage/log_cpu_usage.py
parentdeb78a5f3502ece98ec3e0b70f93025c4a1b3da5 (diff)
parenta3fed4d42ab4a7be7bc7ebe86b35805ac73d62de (diff)
Merge branch 'release-0.4.5'0.5.00.4.5
Diffstat (limited to 'scripts/backends_cpu_usage/log_cpu_usage.py')
-rwxr-xr-xscripts/backends_cpu_usage/log_cpu_usage.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/backends_cpu_usage/log_cpu_usage.py b/scripts/backends_cpu_usage/log_cpu_usage.py
new file mode 100755
index 00000000..2674e1ff
--- /dev/null
+++ b/scripts/backends_cpu_usage/log_cpu_usage.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+
+# Get the CPU usage and print to file.
+
+
+import psutil
+import time
+import argparse
+import os
+import threading
+
+
+class LogCpuUsage(threading.Thread):
+
+ def __init__(self, fname):
+ threading.Thread.__init__(self)
+ self._stopped = True
+ self._fname = fname
+
+ def run(self):
+ self._stopped = False
+ with open(self._fname, 'w') as f:
+ start = time.time()
+ while self._stopped is False:
+ now = time.time()
+ f.write("%f %f\n" % ((now - start), psutil.cpu_percent()))
+ time.sleep(0.01)
+
+ def stop(self):
+ self._stopped = True
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('file', help='where to save output')
+ args = parser.parse_args()
+
+ if os.path.isfile(args.file):
+ replace = raw_input('File %s exists, replace it (y/N)? ' % args.file)
+ if replace.lower() != 'y':
+ print 'Bailing out.'
+ exit(1)
+
+ log_cpu = LogCpuUsage(args.file)
+ log_cpu.run()