Oracle® Linux

DTrace Tutorial

Oracle Legal Notices
Oracle Documentation License

E50705-11

November 2018


Table of Contents

Preface
1 Introducing DTrace
1.1 About This Tutorial
1.2 About DTrace
1.3 About DTrace Providers
1.4 Preparing to Install and Configure DTrace
1.4.1 Using Automatically Loaded DTrace Modules
1.4.2 Manually Loading DTrace Modules
1.5 Running a Simple DTrace Program
1.5.1 Example: Simple D Program That Uses the BEGIN Probe (hello.d)
1.5.2 Exercise: Using the END Probe
1.5.3 Solution to Exercise and Example: Using the END Probe
2 Tracing Operating System Behavior
2.1 Tracing Process Creation
2.1.1 Example: Monitoring the System as Programs Are Executed (execcalls.d)
2.1.2 Exercise: Suppressing Verbose Output From DTrace
2.1.3 Solution to Exercise: Suppressing Verbose Output From DTrace
2.2 Tracing System Calls
2.2.1 Example: Recording open() System Calls on a System (syscalls.d)
2.2.2 Exercise: Using the printf() Function to Format Output
2.2.3 Solution to Exercise: Using the printf() Function to Format Output
2.3 Performing an Action at Specified Intervals
2.3.1 Example: Using tick.d
2.3.2 Exercise: Using tick Probes
2.3.3 Solution to Exercise and Example: Using tick Probes
2.3.4 Example: Modified Version of tick.d
2.4 Using Predicates to Select Actions
2.4.1 Example: Using daterun.d
2.4.2 Example: Listing Available syscall Provider Probes
2.4.3 Exercise: Using syscall Probes
2.4.4 Solution to Exercise: Using syscall Probes
2.5 Timing Events on a System
2.5.1 Example: Monitoring read() System Call Duration (readtrace.d)
2.5.2 Exercise: Timing System Calls
2.5.3 Solution to Exercise: Timing System Calls
2.5.4 Exercise: Timing All System Calls for cp (calltrace.d)
2.5.5 Solution to Exercise: Timing All System Calls for cp (calltrace.d)
2.6 Tracing Parent and Child Processes
2.6.1 Example: Using proc Probes to Report Activity on a System (activity.d)
2.6.2 Exercise: Using a Predicate to Control the Execution of an Action
2.6.3 Solution to Exercise: Using a Predicate to Control the Execution of an Action
2.6.4 Example: Recording fork() and exec() Activity for a Specified Program (activity1.d)
2.7 Simple Data Aggregations
2.7.1 Example: Counting the Number of write() System Calls Invoked by Processes
2.7.2 Example: Counting the Number of read() and write() System Calls
2.7.3 Exercise: Counting System Calls Over a Fixed Period
2.7.4 Solution to Exercise and Example: Counting Write, Read, and Open System Calls Over 100 Seconds (countcalls.d)
2.7.5 Example: Counting System Calls Invoked by a Process (countsyscalls.d)
2.7.6 Exercise: Tracing Processes That Are Run by a User
2.7.7 Solution to Exercise and Example: Counting Programs Invoked by a Specified User (countprogs.d)
2.7.8 Example: Counting the Number of Times a Program Reads From Different Files in 10 Seconds (fdscount.d)
2.7.9 Exercise: Counting Context Switches on a System
2.7.10 Solution to Exercise and Example: Counting Context Switches on a System
2.8 Working With More Complex Data Aggregations
2.8.1 Example: Displaying the Distribution of Read Sizes Resulting From a Command
2.8.2 Example: Displaying the Distribution of I/O Throughput for Block Devices (diskact.d)
2.8.3 Exercise: Displaying Read and Write I/O Throughput Separately
2.8.4 Solution to Exercise: Displaying Read and Write I/O Throughput Separately
2.8.5 Example: Displaying Cumulative Read and Write Activity Across a File System Device (fsact)
2.9 Displaying System Call Errors
2.9.1 Example: Displaying System Call Errors (errno.d)
2.9.2 Exercise: Displaying More Information About System Call Errors
2.9.3 Solution to Exercise: Displaying More Information About System Call Errors
3 Tracing User-Space Applications
3.1 Preparing for Tracing User-Space Applications
3.1.1 Example: Changing the Mode of the DTrace Helper Device
3.2 Sample Application
3.2.1 Description and Format of the makefile File
3.2.2 Description of the primelib.h Source File
3.2.3 Description of the primelib.c Source File
3.2.4 Description of the primain.c Source File
3.2.5 Compiling the Program and Running the prime Executable
3.3 Adding USDT Probes to an Application
3.3.1 Exercise: Creating a dprime.d File
3.3.2 Solution to Exercise: Creating a dprime.d File
3.3.3 Example: Creating a .h File From a dprime.d File
3.3.4 Exercise: Directing makefile to Re-Create the dprime.h File
3.3.5 Solution to Exercise: Directing makefile to Re-Create the dprime.h File
3.3.6 Example: Testing the Program
3.4 Using USDT Probes
3.4.1 Example: Using simpleTimeProbe.d to Show the Elapsed Time Between Two Probes
3.4.2 Example: Using timeTweenprobes.d to Show the Elapsed Time Between Each Probe
4 Going Further With DTrace