Danilo Poccia - Tecnologia et al.
Monitorare Java con DTrace
Con la disponibilità di Java SE 6 (JDK 6) è possibile monitorare il comportamento delle applicazioni Java utilizzando i provider DTrace hotspot e hotspot_jni,
il primo focalizzato sul monitoraggio della HotSpot Java Virtual Machine (JVM), il secondo delle
chiamate Java Native Interface (JNI). Inoltre è stata introdotta in
DTrace l'azione jstack che permette di stampare uno stack completo per le applicazioni Java.
Con la distribuzione del JDK 6 si trovano alcuni D script di esempio nella directory:
- $JAVA_HOME/sample/dtrace/hotspot/
Sul mio portatile (con Solaris 10 11/06) si può provare uno degli
script con il comando (vado a capo a causa della lunghezza):
# /usr/jdk/instances/jdk1.6.0/sample/dtrace/hotspot/method_invocation_stat.d -c \
"java UnFilePuntoClass"
Provando la classe "RandomPI", compilata a partire dal sorgente RandomPI.java (vedi post precedente), l'output che si ottiene è il seguente:
# /usr/jdk/instances/jdk1.6.0/sample/dtrace/hotspot/method_invocation_stat.d -c \
"java RandomPI"
BEGIN hotspot method invocation tracing
n = 1000000 c = 786057 -> PI =~ 3.144228
n = 2000000 c = 1571619 -> PI =~ 3.143238
n = 3000000 c = 2356441 -> PI =~ 3.1419213333333333
n = 4000000 c = 3142022 -> PI =~ 3.142022
n = 5000000 c = 3927190 -> PI =~ 3.141752
n = 6000000 c = 4712735 -> PI =~ 3.1418233333333334
n = 7000000 c = 5498000 -> PI =~ 3.141714285714286
n = 8000000 c = 6283328 -> PI =~ 3.141664
n = 9000000 c = 7069532 -> PI =~ 3.142014222222222
n = 10000000 c = 7854909 -> PI =~ 3.1419636
^C
System calls:
1 exece
1 getcwd
1 gtime
1 lseek
1 mkdir
1 pathconf
1 setrlimit
1 sigpending
1 uname
2 getuid
2 lwp_wait
2 lxstat
2 sysi86
2 systeminfo
3 getpid
3 getrlimit
3 lwp_cond_broadcast
4 access
4 doorfs
4 fsat
4 getdents64
5 fcntl
5 open64
6 lwp_cond_signal
6 lwp_mutex_wakeup
6 priocntlsys
7 lwp_park
8 lwp_mutex_timedlock
9 lwp_continue
9 lwp_create
9 lwp_self
10 schedctl
12 llseek
13 fstat64
14 sysconfig
15 mprotect
16 memcntl
17 read
17 setcontext
20 lwp_cond_wait
20 stat64
20 write
21 lwp_sigmask
25 sigaction
32 munmap
37 resolvepath
68 brk
114 pollsys
145 mmap
180 ioctl
207 open
208 close
354 xstat
528 lwp_exit
8000 yield
JNI calls:
1 CallIntMethod-entry
1 CallStaticBooleanMethod-entry
1 CallStaticObjectMethod-entry
1 CallStaticObjectMethodV-entry
1 CallStaticVoidMethod-entry
1 CreateJavaVM-entry
1 ExceptionCheck-entry
1 ExceptionClear-entry
1 GetDefaultJavaVMInitArgs-entry
1 GetJavaVM-entry
1 GetStringRegion-entry
1 NewByteArray-entry
1 NewLocalRef-entry
1 NewObject-entry
1 NewObjectV-entry
1 SetLongField-entry
1 ToReflectedMethod-entry
2 DeleteGlobalRef-entry
2 IsSameObject-entry
3 GetStaticFieldID-entry
3 NewObjectArray-entry
3 SetByteArrayRegion-entry
3 SetStaticObjectField-entry
4 GetStaticMethodID-entry
4 NewGlobalRef-entry
5 EnsureLocalCapacity-entry
5 GetObjectArrayElement-entry
5 SetIntField-entry
6 GetFieldID-entry
6 GetMethodID-entry
9 GetObjectClass-entry
9 RegisterNatives-entry
10 GetSuperclass-entry
10 SetObjectArrayElement-entry
11 FindClass-entry
13 GetStringUTFLength-entry
13 GetStringUTFRegion-entry
15 GetStringUTFChars-entry
15 ReleaseStringUTFChars-entry
21 GetByteArrayRegion-entry
23 GetArrayLength-entry
30 CallObjectMethod-entry
31 GetStringCritical-entry
31 ReleaseStringCritical-entry
45 GetStringLength-entry
54 NewString-entry
54 NewStringUTF-entry
59 ExceptionOccurred-entry
82 GetObjectField-entry
112 DeleteLocalRef-entry
Top packages calls:
Top class calls:
Top method calls:
=======================================
JAVA_CALLS: 0
JNI_CALLS: 715
SYS_CALLS: 10207
Run time: 10920943942
Syscall time: 49643071
Java+JNI time: 10871300871
END hotspot method invocation tracing
Probabilmente l'esempio precedente non è il migliore che si potesse immaginare per testare le funzionalità di monitoraggio, ma è utile per dare una idea delle potenzialità dei provider hotspot per DTrace.
Per ulteriori informazioni:
Posted at 02:20PM gen 18, 2007 by danilop in Java | Comments[2]



The second URL is missing the first "J"
<li><a href="http://ava.sun.com/j2se/reference/whitepapers/java-dtrace-whitepaper.pdf">Dynamic Tracing Support in the Java HotSpot Virtual Machine</a></li>
Posted by IanM on febbraio 09, 2008 at 06:31 PM CET #
Thanks IanM, I just fixed the link.
Posted by Danilo Poccia on febbraio 11, 2008 at 10:09 AM CET #