From 7bfd6ad6da7e82bda69f1f71698e517e9452044f Mon Sep 17 00:00:00 2001 From: Aaron Tomlin Date: Tue, 26 Nov 2013 17:00:40 +0000 Subject: [PATCH] Add loadavg tapset 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 --- 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 000000000..b3e55dcad --- /dev/null +++ b/tapset/linux/loadavg.stp @@ -0,0 +1,61 @@ +// Copyright (C) 2013 Red Hat Inc., Aaron Tomlin +// +// 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. + +// +// Functions in the loadavg tapset allow a probe handler to capture +// the load average. +// + + +%{ +#include + +#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)); +%} -- 2.43.5