For performancerelated questions, aggregated data is often more useful than individual data points. DTrace provides several builtin aggregating functions. When an aggregating function is applied to subsets of a collection of data, then applied again to the results of the analysis of those subsets, the results are identical to the results returned by the aggregating function when it is applied to the collection as a whole.
The DTrace facility stores a running count of data items for aggregations. The aggregating functions store only the current intermediate result and the new element that the function is being applied to. The intermediate results are allocated on a perCPU basis. Because this allocation scheme does not require locks, the implementation is inherently scalable.
A DTrace aggregation takes the following general form:
@name[keys
] = aggfunc(args
);
In this general form, the variables are defined as follows:
name
The name of the aggregation, preceded by the @
character.
keys
A commaseparated list of D expressions.
aggfunc
One of the DTrace aggregating functions.
args
A commaseparated list of arguments appropriate to the aggregating function.
Table 2.1. DTrace Aggregating Functions
Function Name 
Arguments 
Result 


none 
The number of times that the 

scalar expression 
The total value of the specified expressions. 

scalar expression 
The arithmetic average of the specified expressions. 

scalar expression 
The smallest value among the specified expressions. 

scalar expression 
The largest value among the specified expressions. 

scalar expression, lower bound, upper bound, step value 
A linear frequency distribution of the values of the specified expressions that is sized by the specified range. This aggregating function increments the value in the highest bucket that is less than the specified expression. 

scalar expression 
A poweroftwo frequency distribution of the values of the specified expressions. This aggregating function increments the value in the highest poweroftwo bucket that is less than the specified expression. 
Example 2.14. Using an Aggregating Function
This example uses the count aggregating function to count the number of write ( 2 ) system calls per process. The aggregation does not output any data until the dtrace command is terminated. The output data represents a summary of the data collected during the time that the dtrace command was active.
#cat writes.d
#!/usr/sbin/dtrace s syscall::write:entry] { @numWrites[execname] = count(); } #./writes.d
dtrace: script 'writes.d' matched 1 probe^C
dtrace 1 date 1 bash 3 grep 20 file 197 ls 201