]> sourceware.org Git - systemtap.git/commitdiff
Add cputime_to_usecs() and usecs_to_string()
authorJosh Stone <jistone@redhat.com>
Thu, 9 May 2013 22:25:04 +0000 (15:25 -0700)
committerJosh Stone <jistone@redhat.com>
Thu, 9 May 2013 23:11:22 +0000 (16:11 -0700)
This also corrects for kernels that don't define cputime_to_msecs, but
do have cputime_to_usecs.  It's not always correct to call that jiffies.

tapset/linux/task_time.stp
testsuite/buildok/task_time-embedded.stp

index c581ad02a410939134a994fda81abe65486c9c7d..ae383603e345da370f89c0ef37f943812dc832a1 100644 (file)
 #include <linux/sched.h>               /* includes asm/cputime.h */
 #include <linux/time.h>
 
-/* RHEL4 (2.6.9) kernels don't have cputime_to_msecs */
-#ifndef cputime_to_msecs
+/* Kernels since 2.6.37 generally have cputime_to_usecs, but not msecs.
+ * (ref: kernel commit d57af9b2142f31a39dcfdeb30776baadfc802827)
+ * Yet note some kernels (RHEL6) may already have both...  */
+#if defined(cputime_to_usecs)
+#if !defined(cputime_to_msecs)
+#define cputime_to_msecs(__ct)         _stp_div64(NULL, cputime_to_usecs(__ct), 1000ULL)
+#endif
+
+/* Kernels before 2.6.37 have cputime_to_msecs, but not usecs. */
+#elif defined(cputime_to_msecs)
+#define cputime_to_usecs(__ct)         (cputime_to_msecs(__ct) * 1000ULL)
+
+/* RHEL4 (2.6.9) kernels have neither, but it's just jiffies anyway. */
+#else
 #define cputime_to_msecs(__ct)         jiffies_to_msecs(__ct)
+#define cputime_to_usecs(__ct)         jiffies_to_usecs(__ct)
 #endif
 %}
 
@@ -99,6 +112,15 @@ function cputime_to_msecs:long (cputime:long)
   STAP_RETVALUE = cputime_to_msecs (STAP_ARG_cputime);
 %}
 
+/**
+ * sfunction cputime_to_usecs - Translates the given cputime into microseconds
+ * @cputime: Time to convert to microseconds.
+ */
+function cputime_to_usecs:long (cputime:long)
+%{ /* pure */ /* unprivileged */
+  STAP_RETVALUE = cputime_to_usecs (STAP_ARG_cputime);
+%}
+
 /**
  * sfunction msecs_to_string - Human readable string for given milliseconds
  *
@@ -118,6 +140,25 @@ function msecs_to_string:string (msecs:long)
   return sprintf("%dm%d.%.3ds", mins, secs, ms);
 }
 
+/**
+ * sfunction usecs_to_string - Human readable string for given microseconds
+ *
+ * @usecs: Number of microseconds to translate.
+ *
+ * Description: Returns a string representing the number of
+ * milliseconds as a human readable string consisting of "XmY.ZZZZZZs",
+ * where X is the number of minutes, Y is the number of seconds and
+ * ZZZZZZ is the number of microseconds.
+ */
+function usecs_to_string:string (usecs:long)
+{
+  us = usecs % 1000000;
+  secs = usecs / 1000000;
+  mins = secs / 60;
+  secs = secs % 60;
+  return sprintf("%dm%d.%.6ds", mins, secs, us);
+}
+
 /**
  * sfunction cputime_to_string - Human readable string for given cputime
  *
index 4cf4676d746aa5bb36fc710e8d2d1825943f9ca7..9deef6422425cb8e7edb3eff473aaff43a6d5ff7 100755 (executable)
@@ -6,8 +6,10 @@ probe begin
              + task_utime_tid(0)
              + task_stime()
              + task_stime_tid(0)
-             + cputime_to_msecs(0))
+             + cputime_to_msecs(0)
+             + cputime_to_usecs(0))
        print(msecs_to_string(0))
+       print(usecs_to_string(0))
        print(cputime_to_string(0))
        print(task_time_string())
        print(task_time_string_tid(0))
This page took 0.029965 seconds and 5 git commands to generate.