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

 ​ ​ ​ ​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​)​;​

 ​ ​ ​ ​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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.