Oracle® Solaris 11.2 Dynamic Tracing Guide

Exit Print View

Updated: July 2014
 
 

Sorting Aggregations

When displaying aggregated data, you can sort the output. The output can be sorted based on aggregation keys or aggregation variables. The following options are available to sort the output:

aggsortkey

Sort aggregation by key order with ties broken by value.

aggsortkeypos

Position of the aggregate key on which the output is sorted.

aggsortpos

Position of the argument in the aggregate function on which the output is sorted.

aggsortrev

Sort aggregation in the reverse order.

For example, consider the following aggsort.d script that prints aggregation values.

/* aggsort.d */
syscall::read:entry
{
@avg[execname, pid] = avg(arg2);
@max[execname, pid] = max(arg2);
@min[execname, pid] = min(arg2);
@cnt[execname, pid] = count();
}
END
{
printf("%20s %10s %10s %10s %10s %10s\n", "EXECNAME", "PID", "COUNT", "MIN", "MAX", "AVG");
printa("%20s %10d %@10d %@10d %@10d %@10d\n", @cnt, @min, @max, @avg);
}

Running the aggsort.d script displays an output similar to the following:

# dtrace -q -s ./aggsort.d
^C

EXECNAME                    PID        COUNT      MIN        MAX        AVG
battstat-applet-         100981          2        32         32         32
gnome-settings-d         100853          3        32         64         53
soffice.bin              101382         10        32         32         32
dsdm                     100708         10        32        160         54
xscreensaver             101082         14        32         32         32
gnome-panel              100896         24        12        168         51
firefox-bin              101363         31         1       1024         35
gnome-terminal           101029         40        32       4096        163
nautilus                 100906        119        32        480         48
wnck-applet              100961        161         8        128         32
metacity                 100893        447         4         96         33
Xorg                     100534        926        64       5104       3263

Note -  If no sort options are provided, the output is sorted on the value of first aggregation. In the preceeding example, the output is sorted on COUNT.

If you want to sort the output based on the pid which is the second aggregation key, you must specify the aggsortkey and the aggsortkeypos options. Running the aggsort.d with these options, displays an output similar to the following:

# dtrace -q -s ./aggsort.d -x aggsortkey -x aggsortkeypos=1
^C

EXECNAME               PID         COUNT      MIN         MAX         AVG
Xorg                100534         885        64         4940        3688
dsdm                100708          23        32          128          40
gnome-settings-d    100853           4        32           64          40
metacity            100893         196         4          128          34
gnome-panel         100896          26        12          168          49
nautilus            100906          79        32          320          40
wnck-applet         100961         161         8           96          32
gnome-terminal      101029          27        32         4096         220
xscreensaver        101082          11        32           64          34
thunderbird-bin     101337           2         1         1024         512
firefox-bin         101363          29         1         1024          36
soffice.bin         101382         525         4         1440          33

To sort the output based on any of the aggregation variables, you must use the aggsortpos option. Running the following command sorts the output based on MAX which is the third aggregation variable.

# dtrace -q -s ./aggsort.d -x aggsortpos=2

To sort the aggregation values in a reverse order, use the aggsortrev option. For example:

# dtrace -q -s ./aggsort.d -x aggsortrev