6.2 printa

The printa function allows you to format the results of aggregations in a D program. The function is invoked using one of two forms:

printa(@aggregation-name); 
printa(format-string, @aggregation-name);

If the first form of the function is used, the dtrace command takes a consistent snapshot of the aggregation data and produces output equivalent to the default output format used for aggregations, described in Chapter 3, Aggregations. If the second form of the function is used, dtrace takes a consistent snapshot of the aggregation data and produces output according to the conversions specified in the format string, according to the following rules:

Aggregation

Result Type

avg

uint64_t

count

uint64_t

lquantize

int64_t

max

uint64_t

min

uint64_t

quantize

int64_t

sum

uint64_t

For example, to format the results of avg, you can apply the %d, %i, %o, %u, or %x format conversions. The quantize and lquantize functions format their results as an ASCII table rather than as a single value.

The following D program shows a complete example of printa, using the profile provider to sample the value of caller, and then formatting the results as a simple table:

profile:::tick-1000
{
  @a[caller] = count();
}

END
{
  printa("%@8u %a\n", @a);
}

If you use dtrace to execute this program, wait a few seconds, and then press Ctrl-C, you see output similar to the following example:

# dtrace -s printa.d 
dtrace: script 'printa.d' matched 2 probes
^C
CPU     ID                    FUNCTION:NAME
  0      2                             :END        8 0xffffffff8105f128
    1313 0xffffffff8110cb90
    6358 0xffffffff81052fb9
   36347 0xffffffffa03c92d7
...