This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: sort a foreach on a stat value?
- From: fche at redhat dot com (Frank Ch. Eigler)
- To: "Stone, Joshua I" <joshua dot i dot stone at intel dot com>
- Cc: <systemtap at sources dot redhat dot com>
- Date: 11 Jan 2006 23:14:25 -0500
- Subject: Re: sort a foreach on a stat value?
- References: <CBDB88BFD06F7F408399DBCF8776B3DC05F01BA9@scsmsx403.amr.corp.intel.com>
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