solaris.pro / Field manuals / DTrace

DTrace cookbook: CPU profiling and hot stacks

Use sampling and stacks to discover where CPU time goes.

Scope: Oracle Solaris 11.4 and, for LDoms, compatible SPARC hardware with Oracle VM Server for SPARC. Examples are educational: verify release, privileges, target names and backups before running changes.

How it works

Sampling vs tracing

A profile probe samples active execution periodically. Samples are a statistical estimate of where time is spent, not an exact accounting of every instruction.

Stack interpretation

Kernel stacks (stack()) and user stacks (ustack()) show different execution contexts. User symbol resolution depends on binaries, symbols and permissions.

Use modest sample rates

Begin with a moderate frequency, such as profile-97, and narrow the target before collecting user stacks.

Worked examples

Each example explains the question it answers, a reproducible starting point, what to look for, and operational precautions.

1. Top sampled executables

Identify CPU consumers from samples.

profile-97
{
  @samples[execname] = count();
}

Interpretation: More samples imply more observed on-CPU activity during the sampling interval.

Operational note: Run commands in a test environment first; confirm device names, privileges and release-specific options.

2. Kernel hot stacks

Investigate kernel-side CPU work.

profile-97
{
  @[stack()] = count();
}

Interpretation: Repeated stacks identify likely hot paths; symbol names may be partial.

Operational note: Run commands in a test environment first; confirm device names, privileges and release-specific options.

3. User hot stacks for a PID

Find functions active in one process.

profile-97
/pid == $target/
{
  @[ustack()] = count();
}

Interpretation: Run with `dtrace -s hotuser.d -p 1234`; interpret unresolved frames cautiously.

Operational note: Run commands in a test environment first; confirm device names, privileges and release-specific options.

4. CPU samples by PID

Find busy workers sharing the same executable.

profile-97
{
  @cpu[pid, execname] = count();
}

Interpretation: Useful for identifying a hot worker among many identical service processes.

Operational note: Run commands in a test environment first; confirm device names, privileges and release-specific options.

Before you finish

  • Sampling is not wall-clock response-time tracing.
  • Check symbols and build flags before trusting stack names.

Primary documentation

Read the relevant Oracle documentation for exact version-specific flags, supported platforms and limitations: Oracle primary reference ↗.

This field manual is independent, not affiliated with or endorsed by Oracle. Command examples should be adapted to your environment.