This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Dealing with empty aggregates?
- From: "Bryn M. Reeves" <bmr at redhat dot com>
- To: systemtap at sources dot redhat dot com
- Date: Thu, 19 May 2011 12:29:46 +0100
- Subject: Dealing with empty aggregates?
Hi Folks,
I have a script that uses the aggregation operator to accumulate a bunch of
samples in probes that fire when stuff happens. Stuff may or may not be
happening on the system at any given moment.
These are then extracted and reported by a timer probe that runs once per second.
If it happens that no "stuff" happened before the first timer I hit the
following error:
ERROR: empty aggregate near identifier '@sum' at <input>:1:42
for e.g.:
stap -e 'global foo; probe begin { printf("%d\n", @sum(foo)); } probe end {foo
<<< 1}'
ERROR: empty aggregate near identifier '@sum' at <input>:1:42
Right now I handle this with script like:
global have_stuff
probe kernel.stuff {
stuff <<< nonsense
have_stuff = 1
}
probe timer.ms(1000) {
if (have_stuff) {
printf("Sum of stuff: %d\n", @sum(stuff))
} else {
print("Sum of stuff: n/a\n")
}
}
I wondered if there was a more elegant way? I have a few of these in the script
I'm working on and the special casing/flags are looking a bit kludgey.
Sorry if there's something obvious I missed!
Regards,
Bryn.