0% found this document useful (0 votes)
9 views

Java Profiling

The document contains code snippets and discussions around various Java and JVM profiling and performance monitoring techniques. These include using tools like perf to profile CPU usage and identify hotspots, using perf-map-agent to symbolicate perf profiles, generating flame graphs from perf data, setting clocksources, using JVMTI to sample object allocations, and setting heap sampling intervals.

Uploaded by

trialistmail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java Profiling

The document contains code snippets and discussions around various Java and JVM profiling and performance monitoring techniques. These include using tools like perf to profile CPU usage and identify hotspots, using perf-map-agent to symbolicate perf profiles, generating flame graphs from perf data, setting clocksources, using JVMTI to sample object allocations, and setting heap sampling intervals.

Uploaded by

trialistmail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100





• •





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;
}

x = avg(123, 45.67, 890L, 33.3f, 999, 787878L);


enum {
ticks_no_Java_frame = 0,
ticks_no_class_load = -1,
ticks_GC_active = -2,
ticks_unknown_not_Java = -3,
ticks_not_walkable_not_Java = -4,
ticks_unknown_Java = -5,
ticks_not_walkable_Java = -6,
ticks_unknown_state = -7,
ticks_thread_exit = -8,
ticks_deopt = -9,
ticks_safepoint = -10
}; src/share/vm/prims/forte.cpp





• S

S





$ perf record –F 1009 java ...
$ perf report
$ perf record –F 1009 java ...
$ perf report

4.70% java [kernel.kallsyms] [k] clear_page_c


2.10% java libpthread-2.17.so [.] pthread_cond_wait
1.97% java libjvm.so [.] Unsafe_Park
1.40% java libjvm.so [.] Parker::park
1.31% java [kernel.kallsyms] [k] try_to_wake_up
1.31% java perf-18762.map [.] 0x00007f8510e9e757
1.21% java perf-18762.map [.] 0x00007f8510e9e89e
1.17% java perf-18762.map [.] 0x00007f8510e9cc17
github.com/jvm-profiling-tools/perf-map-agent

$ java -agentpath:/usr/lib/libperfmap.so ...

7fe0e91175e0 140 java.lang.String::hashCode


7fe0e9117900 20 java.lang.Math::min
7fe0e9117ae0 60 java.lang.String::length
7fe0e9117d20 180 java.lang.String::indexOf
SP

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];

try (FileInputStream in = new FileInputStream(fileName)) {


int bytesRead;
while ((bytesRead = in.read(buf)) > 0) {
...
} ❑
} ❑


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)








































You might also like