This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] Add loadavg tapset
- From: Aaron Tomlin <atomlin at redhat dot com>
- To: systemtap at sourceware dot org
- Cc: fche at redhat dot com, jistone at redhat dot com
- Date: Fri, 22 Nov 2013 15:42:19 +0000
- Subject: [PATCH] Add loadavg tapset
- Authentication-results: sourceware.org; auth=none
Provide a tapset to obtain the load average.
Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
---
tapset/linux/loadavg.stp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 tapset/linux/loadavg.stp
diff --git a/tapset/linux/loadavg.stp b/tapset/linux/loadavg.stp
new file mode 100644
index 0000000..702c9b4
--- /dev/null
+++ b/tapset/linux/loadavg.stp
@@ -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. If the specified
+ * index is out-of-bounds, then an error message and exception is thrown, which
+ * can be handled with a try { } and catch { } statement.
+ */
+function get_loadavg_index:string (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);
+
+ snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%d.%02d\n",
+ LOAD_INT(value), LOAD_FRAC(value));
+%}
+
+/**
+ * sfunction get_loadavg - Get the load average
+ *
+ * Description: Returns the complete load average.
+ */
+function get_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));
+%}
--
1.8.1.4