This document discusses using DTrace to dynamically observe applications and their environments. It describes how DTrace allows instrumentation of applications, frameworks, databases, operating systems and more. Examples are provided of using DTrace to analyze performance of a Drupal site and its Apache, MySQL and PHP components.
Observing Your App and Everything Else Using DTrace
1. Observing Your App and
Everything Else It Runs On Using
DTrace
session code S308357
Angelo Rajadurai
Sr. Technology Evangelist – Sun Microsystems Inc.
Sunday, May 31, 2009
2. goal
Learn how to Dynamically observe your
application and its environment.
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone
Sunday, May 31, 2009
3. your app...
Application Logic
ruby
Frameworks
python
Presentation php
C++
C
JSP/Javascript/Ajax/JavaFX
perl
Container Glassfish/J2EE shell
java
Database Apps run Native
in VM Apps
MySQL/Oracle/Postgres
Operating System Solaris/Linux/OS X/Windows
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 3
Sunday, May 31, 2009
4. on the menu today
Our Setup
Drupal 6.12
Apache 2.2
PHP - Zend 5.2
MySQL 5.1.30
Amp Stack
OpenSolaris 2009.06
4
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone
Sunday, May 31, 2009
5. one small easy step
the AMP stack
To build, install, integrate, performance tune and deploy
the amp stack on opensolaris...
# pkg install amp-dev
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 5
Sunday, May 31, 2009
6. one slide on Drupal
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 6
Sunday, May 31, 2009
7. questions questions questions
How much time am I
spending in Apache/
How much of my load is MySQL/PHP?
from anonymous users
What are the Drupal
modules that take up
the most time?
What type of database
load is caused by
anonymous users What are the most
expensive hooks in a
given Drupal module?
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 7
Sunday, May 31, 2009
8. the big game hunt
“M
ay
m in” Da
be ta
d
r: e a th bas
pe as
lo b
e
w i m Ad
e
ve ata ll idd mi
De d kn le n:
o w wa
e
th ” re
k gu
as ys
“I’d
“I :
do S
n’t ysa e rt in”
xp adm
De kno dmi E
e ys
ve w! n ar e S
lop A
e r sk d lew th
” th id sk
e M a
s
et
“L
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 8
Sunday, May 31, 2009
9. the vicious cycle
Restart
Stop App Add Code Compile
w/ flags
Prebuilt Instruments Custom Instruments
Instrument Validate
Run in
production
Process Collect info
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 9
Sunday, May 31, 2009
10. oh please
Please let me
observe a live
system.
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 10
Sunday, May 31, 2009
11. dynamic tracing
Application Logic
Frameworks c
Presentation c++
12::SELECT id, name, symbol, conversion_rate FROM currencies WHERE
JSP/Javascript/Ajax
status = 'Active' and deleted = 0
12::SELECT category, name, value FROM config
ph
pytho
12::SELECT id FROM outbound_email WHERE type = 'system'
rub
Container Glassfish/Tomcat
perl
Database shell
Native
Operating System Solaris/Linux/OS X/
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 11
Sunday, May 31, 2009
12. dynamic tracing
Application Logic
-> contentAreaClick
-> getPreventDefault
c
<- getPreventDefault
Frameworks
<- contentAreaClick
Presentation c++
JSP/Javascript/Ajax
ph
pytho
rub
Container Glassfish/Tomcat
perl
Database shell
Native
Operating System Solaris/Linux/OS X/
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 12
Sunday, May 31, 2009
13. You can do it with...
DTrace
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 13
Sunday, May 31, 2009
14. poll
Have you heard about it
Have you used it
Have you written d-scripts
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 14
Sunday, May 31, 2009
15. The D - Language
Basics
of
Dynamic Instrumentation
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 15
Sunday, May 31, 2009
16. instrumentation format
d-script
probe
provider : module : probe : name where
/ predicate / when
{
actions do what
}
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 16
Sunday, May 31, 2009
17. command line version
dtrace command line
# dtrace -n probe’/predicate/{action}’
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 17
Sunday, May 31, 2009
18. demo
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 18
Sunday, May 31, 2009
20. dtrace aggregates - demo
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 20
Sunday, May 31, 2009
21. the pid provider
• Dynamically create probes in
provider: pid$<processId> live running applications.
module: name of library
probe: function name
• No extra work needed from
name: entry application developer
return
offset
• Available without any compile
or runtime flags
• Can be created on optimized
Pr
binaries as well
Pi id
ov
• Probes created at function
d er
boundaries and offset
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 21
Sunday, May 31, 2009
22. demo
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 22
Sunday, May 31, 2009
23. probing MySQL using Pid
provider: pid$<mysql-pid>
module: not-used
probe:*dispatch_command* #!/usr/sbin/dtrace -qs
name: entry
arg2 - SQL command pid$1::*dispatch_command*:entry
{
printf("%sn",copyinstr(arg2,arg3));
}
M ue
Q
yS ri
Q es
L
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 23
Sunday, May 31, 2009
24. dtrace and mysql - demo
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 24
Sunday, May 31, 2009
25. php provider
New and improved in OpenSolaris 2009.06
compile-file-entry/-return
function-entry/-return
provider: php$<pid>
module: not-used execution-entry/-return
probe: not-used exception-thrown/-catched
name: <see detail ->
error
request-startup/-shutdown
Ap ov
Pr
Older releases
ac id
he er
function-entry/-return
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 25
Sunday, May 31, 2009
26. dtrace and php - demo
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 26
Sunday, May 31, 2009
27. Apache provider
received-request
provider: apache$<pid>
module: not-used log-request
probe: not-used
name: <see detail -> create-child
accept-connection
check-user-credentials
check-access
Ap ov
Pr
check-authorization
ac id
he er
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 27
Sunday, May 31, 2009
28. gotcha
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 28
Sunday, May 31, 2009
29. dtrace and the webstack
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 29
Sunday, May 31, 2009
30. Observing the entire stack
More details on the scripts we saw earlier...
what are the hot modules in Drupal?
what are the hot hooks in Drupal?
how much of my Drupal load is from anonymous users
how much time am I spending in Apache/MySQL/PHP?
what are the SQL statements that are executed by anon
users
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 30
Sunday, May 31, 2009
31. Give me more!
DTrace landing page:
http://www.opensolaris.org/os/community/dtrace
DTrace Toolkit:
In OpenSolaris - /opt/DTT
Solaris download -
http://www.opensolaris.org/os/community/dtrace/dtracetoolkit/
DTrace Bigadmin page:
http://www.sun.com/bigadmin/content/dtrace/
Lots and lots of info on the web - Google “dtrace”
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 31
Sunday, May 31, 2009
32. Social
My Blog:
http://blogs.sun.com/angelo
Twitter:
rajadurai
DTrace hands on lab
http://developers.sun.com/learning/javaoneonline/j1lab.jsp?
lab=LAB-9400&yr=2008&track=1
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 32
Sunday, May 31, 2009
33. Observing Your App and
Everything Else It Runs On Using
DTrace
session code S308357
Angelo Rajadurai
angelo.rajadurai@sun.com
Sunday, May 31, 2009
34. DTrace and JavaScript
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 34
Sunday, May 31, 2009
35. Observing javascript using the javascript provider
Enter script details
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 35
Sunday, May 31, 2009
36. implementation
2009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 36
Sunday, May 31, 2009