New proc get_clk_tck() function to analyse clock granularity
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 9 May 2012 12:08:39 +0000 (12:08 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 9 May 2012 12:08:39 +0000 (12:08 +0000)
bin/proc.py

index 4c4121b82c1a7be4e211d93578a7aaff67e2faf6..6d30bcf800401ba58960b8a67c7da194ca813b77 100644 (file)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from __future__ import division
+import subprocess
 
 __proc_keys__ = (
     # see man 5 proc
@@ -58,6 +59,15 @@ __states__ = {
     'W': 'swapping',
 }
 
+def get_clk_tck():
+    process = subprocess.Popen(['getconf', 'CLK_TCK'], shell=True, stdout=subprocess.PIPE)
+    if process.wait() != 0:
+        raise "getconf CLK_TCK failed"
+    return process[0]
+
+    #= 100 -> 1 tick = 1/100 seconds
+    # require libc-bin to be installed
+
 class Stat(dict):
     def __init__(self, processid):
         dict.__init__(self)
@@ -81,3 +91,6 @@ class Stat(dict):
 
     def nice_stime(self):
         return self['stime'] / 100
+
+if __name__ == '__main__':
+    print get_clk_tck()