This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Capturing load average from within systemtap script...


Hi Rick,

<quote sender="Rick Beldin">
> I've been struggling for a bit on how to (or if possible) to capture the
> value of avenrun (declared as: 
> 
> unsigned long avenrun[3];
> EXPORT_SYMBOL(avenrun);
[...]

> global timer_count

%{
#include <linux/sysrq.h>

/* defined in fs/proc/proc_misc.c */
#define LOAD_INT(x) ((x) >> FSHIFT)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
%}

> function rab_show_mem:long (arg:long) 
> %{
>         handle_sysrq('m', NULL, NULL);
>         handle_sysrq('t', NULL, NULL);

void handle_sysrq(int key, struct tty_struct *tty);

So, it should be handle_sysrq('m', NULL);

> %}
> probe timer.ms(3000) {
>     if (timer_count < 5) {
>         printf("timer %d %d\n", rab_show_mem(0),timer_count++)
>         ave = kernel_long(avenrun)
>         printf("avenrun %d\n",ave)

function get_avenrun:string (idx:long) %{ /* pure */
	if (THIS->idx < 0 || THIS->idx > 2)
		strcat(THIS->__retvalue, "0");
	else {
		int a = avenrun[THIS->idx] + (FIXED_1/200);
		snprintf(THIS->__retvalue, MAXSTRINGLEN, "%d.%02d",
				LOAD_INT(a), LOAD_FRAC(a));
	}
%}

in hangwatch.c, it reads the first value from /proc/loadavg, so in this case
we are interested in avenrun[0]:

probe timer.ms(3000) {
[...]
		/*
		 * hangwatch.c:
		 * load = atof(procbuf);
		 * it reads 'avenrun[0] + (FIXED_1/200)'
		 */
		printf("avenrun %s\n", get_avenrun(0))

Hope this helps.

Eugene


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]