Providers

A provider is a facility that publishes the probes that you use in your D script. There are a number of built-in providers.

BEGIN and END providers

These are actually called dtrace:::BEGIN and dtrace:::END, but they are usually used as just BEGIN and END. The BEGIN probe fires when the D script begins execution, and the END probe fires when the script finishes. Example 9.2 shows using the BEGIN and END probes.

Example 9.2. begin-end.d

B​E​G​I​N​
{​
 ​ ​ ​ ​t​r​a​c​e​(​"​b​e​g​i​n​ ​t​h​e​ ​b​e​g​u​i​n​e​"​)​;​
 ​ ​ ​ ​e​x​i​t​(​0​)​;​
}​

E​N​D​
{​
 ​ ​ ​ ​t​r​a​c​e​ ​(​"​t​h​a​t​'​s​ ​a​l​l​,​ ​f​o​l​k​s​.​.​.​"​)​;​
}​

Run it:

$​ ​s​u​d​o​ ​d​t​r​a​c​e​ ​-​s​ ​b​e​g​i​n​-​e​n​d​.​d​ d​t​r​a​c​e​:​ ​s​c​r​i​p​t​ ​'​b​e​g​i​n​-​e​n​d​.​d​'​ ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.