]> sourceware.org Git - systemtap.git/commitdiff
Add loadavg tapset
authorAaron Tomlin <atomlin@redhat.com>
Tue, 26 Nov 2013 17:00:40 +0000 (17:00 +0000)
committerFrank Ch. Eigler <fche@redhat.com>
Tue, 26 Nov 2013 17:26:37 +0000 (12:26 -0500)
Provide a tapset to obtain the load average.

Sample usage via a timer probe:

probe timer.s(1) {
printf("%s: Load average: %s",
ctime(gettimeofday_s()),
sprint_loadavg())
}

$ sudo stap ./show_loadavg.stp
Tue Nov 26 16:54:04 2013: Load average: 0.12 0.33 0.30
Tue Nov 26 16:54:05 2013: Load average: 0.11 0.33 0.30
Tue Nov 26 16:54:06 2013: Load average: 0.11 0.33 0.30
Tue Nov 26 16:54:07 2013: Load average: 0.11 0.33 0.30
Tue Nov 26 16:54:08 2013: Load average: 0.11 0.33 0.30
Tue Nov 26 16:54:09 2013: Load average: 0.11 0.33 0.30
Tue Nov 26 16:54:10 2013: Load average: 0.18 0.34 0.30
Tue Nov 26 16:54:11 2013: Load average: 0.18 0.34 0.30

Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
tapset/linux/loadavg.stp [new file with mode: 0644]

diff --git a/tapset/linux/loadavg.stp b/tapset/linux/loadavg.stp
new file mode 100644 (file)
index 0000000..b3e55dc
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2013 Red Hat Inc., Aaron Tomlin <atomlin@redhat.com>
+//
+// This file is part of systemtap, and is free software.  You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+// <tapsetdescription>
+// Functions in the loadavg tapset allow a probe handler to capture
+// the load average.
+// </tapsetdescription>
+
+
+%{
+#include <linux/sched.h>
+
+#define LOAD_INT(x) ((x) >> FSHIFT)
+#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
+%}
+
+/**
+ * sfunction get_loadavg_index - Get the load average for a specified interval
+ * @indx: The load average interval to capture.
+ *
+ * Description: This function returns the load average at a specified interval.
+ * The three load average values 1, 5 and 15 minute average corresponds to
+ * indexes 0, 1 and 2 of the avenrun array - see linux/sched.h.
+ * Please note that the truncated-integer portion of the load average is returned.
+ * If the specified index is out-of-bounds, then an error message and exception is
+ * thrown.
+ */
+function get_loadavg_index:long (indx:long) %{ /* pure */
+       int value;
+
+       if (STAP_ARG_indx < 0 || STAP_ARG_indx > 2)
+               STAP_ERROR("Invalid loadavg index %lld specified.",
+               STAP_ARG_indx);
+
+       value = avenrun[STAP_ARG_indx] + (FIXED_1/200);
+
+       STAP_RETVALUE = LOAD_INT(value);
+%}
+
+/**
+ * sfunction sprint_loadavg - Get the load average
+ *
+ * Description: Returns the complete load average.
+ */
+function sprint_loadavg:string () %{ /* pure */
+       int a, b, c;
+
+       a = avenrun[0] + (FIXED_1/200);
+       b = avenrun[1] + (FIXED_1/200);
+       c = avenrun[2] + (FIXED_1/200);
+
+       snprintf(STAP_RETVALUE, MAXSTRINGLEN,
+               "%d.%02d %d.%02d %d.%02d\n",
+               LOAD_INT(a), LOAD_FRAC(a),
+               LOAD_INT(b), LOAD_FRAC(b),
+               LOAD_INT(c), LOAD_FRAC(c));
+%}
This page took 0.029527 seconds and 5 git commands to generate.