[dtrace-discuss] Aggregation elements

Bryan Cantrill bmc at eng.sun.com
Tue Nov 1 21:22:58 PST 2005


> > Are the results stored in an aggregation guaranteed to be in any type
> > of order?
> 
> They are sorted by the userland process before display, by the aggregation
> value.  Bryan is currently working on some new options to control
> the sorting of aggregation output; I'll let him elaborate.

Currently, the order is guaranteed to be in value order, with ties broken
by key order.  In my current wad to add multiple aggregation support to
printa(), I'm also adding two new boolean options:

  aggsortkey     => denotes that aggregations should be sorted in key
		    order, with ties broken by value order

  aggsortrev     => denotes that aggregations should be reverse sorted

And:

  aggsortpos     => when multiple aggregations are being printed, the
		    position of the aggregation that should act as the
		    primary sort key

  aggsortkeypos  => when multiple keys are present, the position of the 
		    key that should act as the primary sort key

So, for example (and with the caveat that it uses functionality that
only exists in my workspace at present) take the following script:

---8<--- rwsummary.d ---8<---

#pragma D option quiet

syscall::read:return
/errno == 0/
{
	@reads[execname, pid] = count();
	@rbytes[execname, pid] = sum(arg1);
}

syscall::write:entry
{
	@writes[execname, pid] = count();
	@wbytes[execname, pid] = sum(arg2);
}

END
{
	normalize(@wbytes, 1024);
	normalize(@rbytes, 1024);

	printf("%20s %7s %7s %7s %7s %7s\n", "PROGRAM", "PID",
	    "READS", "KB", "WRITES", "KB");
	printa("%20s %7d %@7d %@6dK %@7d %@6dK\n", @reads, @rbytes,
	    @writes, @wbytes);
}

---8<--- rwsummary.d ---8<---

Just running this might yield output like:

             PROGRAM     PID   READS      KB  WRITES      KB
              dtrace  152294       0      0K       1      0K
              svcadm  152296       0      0K      31      0K
                svcs  152295       1      0K     165      8K
                  sh  152280       4      0K       3      0K
               utmpd  100392       4      2K       0      0K
          in.telnetd  152277       4      8K       4      0K
                init       1       6      3K       2      0K
         svc.configd  100006      58     58K      54     46K

If I ran the same script with "aggsortrev" set (either via -x, "#pragma
D option" or the setopt() function), I would see the reverse-sorted output:

             PROGRAM     PID   READS      KB  WRITES      KB
         svc.configd  100006      58     58K      54     46K
                init       1       6      3K       2      0K
          in.telnetd  152277       4      8K       4      0K
               utmpd  100392       4      2K       0      0K
                  sh  152280       4      0K       3      0K
                svcs  152295       1      0K     165      8K
              svcadm  152296       0      0K      31      0K
              dtrace  152294       0      0K       1      0K

If I set "aggsortpos" to "2", the output would be sorted based on the
number of writes: 

             PROGRAM     PID   READS      KB  WRITES      KB
               utmpd  100392       4      2K       0      0K
              dtrace  152294       0      0K       1      0K
                init       1       6      3K       2      0K
                  sh  152280       4      0K       3      0K
          in.telnetd  152277       4      8K       4      0K
              svcadm  152296       0      0K      31      0K
         svc.configd  100006      58     58K      54     46K
                svcs  152295       1      0K     165      8K

(The positions number from 0:  @reads is position 0, @rbytes is position 1,
@writes is position 2 and @wbytes is position 3.)  If I set "aggsortkey",
the aggregation will be sorted in key order:

             PROGRAM     PID   READS      KB  WRITES      KB
              dtrace  152294       0      0K       1      0K
          in.telnetd  152277       4      8K       4      0K
                init       1       6      3K       2      0K
                  sh  152280       4      0K       3      0K
         svc.configd  100006      58     58K      54     46K
              svcadm  152296       0      0K      31      0K
                svcs  152295       1      0K     165      8K
               utmpd  100392       4      2K       0      0K

And similarly, if I both set "aggsortkey" and set "aggsortkeypos" to "1":

             PROGRAM     PID   READS      KB  WRITES      KB
                init       1       6      3K       2      0K
         svc.configd  100006      58     58K      54     46K
               utmpd  100392       4      2K       0      0K
          in.telnetd  152277       4      8K       4      0K
                  sh  152280       4      0K       3      0K
              dtrace  152294       0      0K       1      0K
                svcs  152295       1      0K     165      8K
              svcadm  152296       0      0K      31      0K

Finally, these options can be set in combination (for example, you
could set "aggsortrev" and "aggsortkey", etc.) and they can be set 
dynamically via setopt():

	setopt("aggsortrev");
	printa(@foo);		/* print in reverse-sorted order */

	setopt("aggsortrev", "false");
	printa(@foo);		/* print in sorted order */

This wad will be in code review soon (hopefully, tomorrow), and will
be in Solaris after testing is completed and in OpenSolaris and Solaris
Express shortly thereafter...

	- Bryan

--------------------------------------------------------------------------
Bryan Cantrill, Solaris Kernel Development.       http://blogs.sun.com/bmc



More information about the dtrace-discuss mailing list