DTrace Topics One Liners

From Siwiki

Jump to: navigation, search

Contents

[edit] DTrace Topics: One Liners

This is a list of DTrace One Liners, and is part of the DTrace Topics collection. See the DTrace Topics: Intro section for a general understanding of DTrace.

DTrace is a dynamic troubleshooting and analysis tool first introduced in the Solaris 10 and OpenSolaris operating systems.

Completion Image:trafficlight_yellow02.png
Difficulty Image:coffeemug01.png Image:coffeemug01.png
Audience All DTrace users

[edit] Top One-Liners

The following are the top 10 one-liners to try out.

[edit] DTrace One Liners

This section is inteded as a concise list of one-liners. See the sections below for detailed explanations.

[edit] Processes

  • New processes with arguments,
dtrace -n 'proc:::exec-success { trace(curpsinfo->pr_psargs); }'

[edit] Files

  • Files opened by process name,
dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }'
  • Files created using creat() by process name,
dtrace -n 'syscall::creat*:entry { printf("%s %s",execname,copyinstr(arg0)); }'

[edit] Syscalls

  • Syscall count by process name,
dtrace -n 'syscall:::entry { @num[execname] = count(); }'
  • Syscall count by syscall,
dtrace -n 'syscall:::entry { @num[probefunc] = count(); }'
  • Syscall count by process ID,
dtrace -n 'syscall:::entry { @num[pid,execname] = count(); }'
  • Read bytes by process name,
dtrace -n 'sysinfo:::readch { @bytes[execname] = sum(arg0); }'

[edit] I/O

  • Write bytes by process name,
dtrace -n 'sysinfo:::writech { @bytes[execname] = sum(arg0); }'
  • Read size distribution by process name,
dtrace -n 'sysinfo:::readch { @dist[execname] = quantize(arg0); }'
  • Write size distribution by process name,
dtrace -n 'sysinfo:::writech { @dist[execname] = quantize(arg0); }'

[edit] Physical I/O

  • Disk size by process ID,
dtrace -n 'io:::start { printf("%d %s %d",pid,execname,args[0]->b_bcount); }'
  • Disk size aggregation
dtrace -n 'io:::start { @size[execname] = quantize(args[0]->b_bcount); }'
  • Pages paged in by process name,
dtrace -n 'vminfo:::pgpgin { @pg[execname] = sum(arg0); }'

[edit] Memory

  • Minor faults by process name,
dtrace -n 'vminfo:::as_fault { @mem[execname] = sum(arg0); }'

[edit] User-land

  • Sample user stack trace of specified process ID at 1001 Hertz
dtrace -n 'profile-1001 /pid == $target/ { @num[ustack()] = count(); }' -p PID
  • Trace why threads are context switching off the CPU, from the user-land perspective,
dtrace -n 'sched:::off-cpu { @[execname, ustack()] = count(); }'
  • User stack size for processes
dtrace -n 'sched:::on-cpu { @[execname] = max(curthread->t_procp->p_stksize);}'

[edit] Kernel

  • Sample kernel stack trace at 1001 Hertz
dtrace -n 'profile-1001 /!pid/ { @num[stack()] = count(); }'
  • Interrupts by CPU,
dtrace -n 'sdt:::interrupt-start { @num[cpu] = count(); }'
  • CPU cross calls by process name,
dtrace -n 'sysinfo:::xcalls { @num[execname] = count(); }'
  • Trace why threads are context switching off the CPU, from the kernel perspective,
dtrace -n 'sched:::off-cpu { @[execname, stack()] = count(); }'
  • Kernel funtion calls by module
dtrace -n 'fbt:::entry { @calls[probemod] = count(); }'

[edit] Locks

  • Trace user-level lock statistics for 10 seconds, with 8 line stack traces (uses DTrace),
plockstat -s8 -e10 -p PID
  • Trace kernel lock statistics for 10 seconds, with 8 line stack traces (uses DTrace),
lockstat -s8 sleep 10
  • Lock time by process name,
dtrace -n 'lockstat:::adaptive-block { @time[execname] = sum(arg1); }'
  • Lock distribution by process name,
dtrace -n 'lockstat:::adaptive-block { @time[execname] = quantize(arg1); }'

[edit] Zones

  • Syscalls by zonename
dtrace -n 'syscall:::entry { @num[zonename] = count(); }'

[edit] DTrace Longer One Liners

  • New processes with arguments and time,
dtrace -qn 'syscall::exec*:return { printf("%Y %s\n",walltimestamp,curpsinfo->pr_psargs); }'
  • Successful signal details,
dtrace -n 'proc:::signal-send /pid/ { printf("%s -%d %d",execname,args[2],args[1]->pr_pid); }'

[edit] References

Most of these onliners are in the DTraceToolkit as docs/oneliners.txt, and as Appendix B in Solaris Performance and Tools.

Solaris Internals
Personal tools
The Books