DTrace

DTrace
Developer(s) Sun Microsystems
Initial release January 2005
Repository github.com/dtrace4linux/linux
Development status Active
Operating system Solaris, OS X, FreeBSD, NetBSD, Linux[1]
Type Tracing
License CDDL
Website dtrace.org

DTrace is a comprehensive dynamic tracing framework created by Sun Microsystems for troubleshooting kernel and application problems on production systems in real time. Originally developed for Solaris, it has since been released under the free Common Development and Distribution License (CDDL) and has been ported to several other Unix-like systems.

DTrace can be used to get a global overview of a running system, such as the amount of memory, CPU time, filesystem and network resources used by the active processes. It can also provide much more fine-grained information, such as a log of the arguments with which a specific function is being called, or a list of the processes accessing a specific file.

As of October 2011, Oracle announced the porting of DTrace from Solaris to Linux, but as of October 13, 2014 it remains officially unavailable.[2] An unofficial DTrace port to Linux is available, although with no changes in licensing terms.[3] As an alternative, Linux's SystemTap provides a similar set of features as DTrace.

Description

Sun Microsystems designed DTrace to give operational insights that allow users to tune and troubleshoot applications and the OS itself.

Testers write tracing programs (also referred to as scripts) using the D programming language (not to be confused with other programming languages named "D"). The language, inspired by C, includes added functions and variables specific to tracing. D programs resemble awk programs in structure; they consist of a list of one or more probes (instrumentation points), and each probe is associated with an action. These probes are comparable to a pointcut in aspect-oriented programming. Whenever the condition for the probe is met, the associated action is executed (the probe "fires"). A typical probe might fire when a certain file is opened, or a process is started, or a certain line of code is executed. A probe that fires may analyze the run-time situation by accessing the call stack and context variables and evaluating expressions; it can then print out or log some information, record it in a database, or modify context variables. The reading and writing of context variables allows probes to pass information to each other, allowing them to cooperatively analyze the correlation of different events.

Special consideration has been taken to make DTrace safe to use in a production environment. For example, there is minimal probe effect when tracing is underway, and no performance impact associated with any disabled probe; this is important since there are tens of thousands of DTrace probes that can be enabled. New probes can also be created dynamically.

Command line examples

DTrace scripts can be invoked directly from the command line, providing one or more probes and actions as arguments. Some examples:

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

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

# Syscall count by program
dtrace -n 'syscall:::entry { @num[execname] = count(); }'

# Syscall count by syscall
dtrace -n 'syscall:::entry { @num[probefunc] = count(); }'

# Syscall count by process
dtrace -n 'syscall:::entry { @num[pid,execname] = count(); }'

# Disk size by process
dtrace -n 'io:::start { printf("%d %s %d",pid,execname,args[0]->b_bcount); }'

# Pages paged in by process
dtrace -n 'vminfo:::pgpgin { @pg[execname] = sum(arg0); }'

Scripts can also be written which can reach hundreds of lines in length, although typically only tens of lines are needed for advanced troubleshooting and analysis. Over 200 examples of open source DTrace scripts can be found in the DTraceToolkit,[4] created by Brendan Gregg (author of the DTrace book[5]), which also provides documentation and demonstrations of each.

Supported platforms

DTrace first became available for use in November 2003, and was formally released as part of Sun's Solaris 10 in January 2005. DTrace was the first component of the OpenSolaris project to have its source code released under the Common Development and Distribution License (CDDL).

DTrace is a standard part of FreeBSD[6] and NetBSD.[7]

Apple added DTrace support in Mac OS X 10.5 "Leopard", including a GUI called Instruments.[8] Over 40 DTrace scripts from the DTraceToolkit are included in /usr/bin,[9] including tools to examine disk I/O (iosnoop) and process execution (execsnoop). Unlike other platforms that DTrace is supported on, Mac OS X has a flag (P_LNOATTACH) that a program may set that disallows tracing of that process by debugging utilities such as DTrace and gdb. In the original Mac OS X DTrace implementation, this could affect tracing of other system information, as unrelated probes that should fire while a program with this flag set was running would fail to do so.[10] The OS X 10.5.3 update addressed this issue a few months later.[11]

The Linux port of DTrace has been available since 2008;[12] work continues actively to enhance and fix issues. There is also an active implementation on github. Standard core providers are available (fbt, syscall, profile), plus a special "instr" provider (some of the Solaris providers are not yet available as of 2013). The Linux DTrace implementation is a loadable kernel module, which means that the kernel itself requires no modification, and thus allows DTrace to avoid CDDL vs. GPL licensing conflicts (in its source form, at least). However, once DTrace is loaded the kernel instance will be marked as tainted.

In 2007, a developer at QNX Software Systems announced on his blog that he and a colleague were working on incorporating DTrace into the QNX operating system.[13]

Oracle Corporation added beta DTrace support for Oracle Linux in 2011.[14] DTrace is available as a technology preview in the Unbreakable Enterprise Kernel release 2, which is under GPL2 (the DTrace kernel module is released under CDDL).[15] In December 2012, Oracle announced the general availability of DTrace for Oracle Linux.[16][17]

Language and application providers

Language providers supported by DTrace include assembly language, C, C++, Java, Erlang, JavaScript, Perl, PHP, Python, Ruby, shell script, and Tcl. With a supported language provider, DTrace can retrieve context of the code, including function, source file, and line number location. Further, dynamic memory allocation and garbage collection can be made available if supported by the language.[18]

Application providers allow DTrace to follow the operation of applications through system calls and into the kernel. Applications that offer DTrace application providers include MySQL, PostgreSQL, Oracle Database, Oracle Grid Engine, and Firefox.[18][19][20]

Authors and awards

DTrace was designed and implemented by Bryan Cantrill, Mike Shapiro, and Adam Leventhal.

The authors received recognition in 2005 for the innovations in DTrace from InfoWorld and Technology Review.[21][22] DTrace won the top prize in the Wall Street Journal's 2006 Technology Innovation Awards competition.[23] The authors were recognized by USENIX with the Software Tools User Group (STUG) award in 2008.[24]

See also

References

Notes

  1. "Trying out dtrace". oracle.com.
  2. http://www.slideshare.net/brendangregg/from-dtrace-to-linux Published on Oct 13, 2014 (slide 28)
  3. https://github.com/dtrace4linux/linux
  4. "DTraceToolkit". Brendan Gregg. Retrieved 2014-06-08.
  5. "DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD". Safari Books. Retrieved 2011-01-03.
  6. "FreeBSD 7.1-RELEASE Announcement". 2009-01-06. Retrieved 2009-01-06.
  7. "NetBSD source changes, 21 February 2010".
  8. "Mac OS X Leopard - Developer Tools - Instruments". Apple Inc. Archived from the original on 2007-10-24. Retrieved 2007-10-19.
  9. "Mac OS X DTrace". Apple Inc. Retrieved 2010-05-31.
  10. "Mac OS X and the missing probes". Leventhal, Adam H. January 18, 2008. Retrieved 2008-01-20.
  11. "Apple Updates DTrace". Leventhal, Adam H. June 7, 2008. Retrieved 2008-06-16.
  12. "CRiSP tools download page.". Retrieved 2011-03-02.
  13. DTrace on QNX
  14. trying out dtrace
  15. DTrace on Linux
  16. Announcement: DTrace for Oracle Linux General Availability
  17. DTrace module source code for Linux
  18. 1 2 DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD. Prentice Hall. 2011. p. 1152. ISBN 9780132091510.
  19. "Open Grid Scheduler / Grid Engine Documentation". Open Grid Scheduler. Retrieved December 30, 2012.
  20. "DTrace – MDN". Mozilla. Retrieved December 30, 2012.
  21. "Tracing software in real time". Technology Review. MIT. 2005. Retrieved 2007-03-31.
  22. McAllister, Neil (August 2005). "Innovation is alive and well in 2005". InfoWorld. IDG. Retrieved 2007-03-31.
  23. Totty, Michael (September 2006). "The Winners Are...". The Wall Street Journal. Dow Jones & Company, Inc. Retrieved 2007-03-31.
  24. "2008 USENIX Annual Technical Conference (USENIX '08)". 2008. Retrieved 2008-11-26.

External links

This article is issued from Wikipedia - version of the 12/4/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.