sort a foreach on a stat value?
Frank Ch. Eigler
fche@redhat.com
Thu Jan 12 04:14:00 GMT 2006
joshua.i.stone wrote:
> Do we have a syntax to sort a foreach based on a stat value? [...]
Not at this time.
> [...]
> The scalable, per-cpu way to do this is:
>
> global stat
> probe my.event { stat[tid()]<<<1 }
> probe end {
> foreach(tid in stat-) // sort by value -> ???
> printf("%d: %d\n", tid, @count(stat[tid]))
> }
Since the reporting phase does not need to be as "scalable" (fast) as
the accumulation phase, perhaps one could do this thusly today:
global stat, stat_counts
probe my.event { stat[tid()]<<<1 }
probe end {
foreach (tid in stat) // sort by value -> ???
stat_counts[tid] = @count(stat[tid])
foreach (tid in stat_counts-)
printf("%d: %d\n", tid, stat_counts[tid]) # and/or @avg(stat[tid])) etc.
}
> Along the same lines, it would be extremely useful to be able to do
> "cascading" sort - i.e. sort by more than one field.
If the runtime provided such an facility, one might imagine the script syntax
exposing it thusly:
foreach ([x1+, x2--, y2+++] in array----) { ... }
encoding the cascading order in the length of those +/- suffixes.
- FChE
More information about the Systemtap
mailing list