Java Profiling
Java Profiling
•
•
•
•
• •
•
•
•
•
•
✓
Socket s = new Socket(host, port);
InputStream in = s.getInputStream();
while (in.read(buf) >= 0) {
// keep reading
}
Socket s = new Socket(host, port);
InputStream in = s.getInputStream();
while (in.read(buf) >= 0) {
// keep reading
}
•
•
•
AsyncGetCallTrace(ASGCT_CallTrace *trace,
jint depth,
void* ucontext)
•
•
•
•
•
•
•
•
•
double avg(Number... numbers) {
double sum = 0;
for (Number n : numbers) {
sum += n.doubleValue();
}
return sum / numbers.length;
}
➔
• S
•
S
•
•
•
•
$ perf record –F 1009 java ...
$ perf report
$ perf record –F 1009 java ...
$ perf report
prev FP FP
prev FP
0
SP
•
prev FP FP
•
• prev FP
0
1. perf record
2. perf script
3. FlameGraph/stackcollapse-perf.pl
4. FlameGraph/flamegraph.pl
github.com/brendangregg/FlameGraph
•
•
•
•
•
•
•
•
•
•
•
xfs_file_aio_read S
sys_read S
perf
system_call_fastpath
readBytes
java.io.FileInputStream::readBytes
java.io.FileInputStream::read
JavaApp::main
!
byte[] buf = new byte[bufSize];
51
→
→
# cat /sys/devices/system/clocksource/*/available_clocksource
tsc hpet acpi_pm
# echo tsc > /sys/devices/system/clocksource/*/current_clocksource
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
xen
•
•
•
•
•
•
•
•
•
•
•
•
•
•
synchronized (obj) {
ReentrantLock.lock()
LocalDateTime deadline =
LocalDateTime.now().plusSeconds(10);
while (LocalDateTime.now().isBefore(deadline)) {
iterations++;
}
•
•
•
→ Tracer.recordAllocation(ArrayList.class, 24);
List<String> list = new ArrayList<>();
•
•
•
$ stap -e '
probe hotspot.object_alloc { log(probestr) }
'
•
•
top
Object in Eden
top
Object in Eden
top
•
•
•
•
•
•
SampledObjectAlloc(jvmtiEnv *jvmti_env,
JNIEnv* jni_env,
jthread thread,
jobject object,
jclass object_klass,
jlong size)
SetHeapSamplingInterval(jint sampling_interval)
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•