jprofiler / an introduction
TRANSCRIPT
![Page 1: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/1.jpg)
JProfiler introductionTommaso Torti
![Page 2: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/2.jpg)
in eXtreme Programming
Make It Work Make It Right Make It Fast
![Page 3: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/3.jpg)
Premature optimization is the root of all evil
in eXtreme Programming
![Page 4: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/4.jpg)
“A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified”
in eXtreme Programming
![Page 5: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/5.jpg)
lulled into complacency
• complacency: a feeling of quiet pleasure or security, often while unaware of some potential danger
• lull: to give or lead to feel a false sense of safety; cause to be less alert, aware, or watchful.
![Page 6: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/6.jpg)
“It is often a mistake to make a priori judgments about what parts of a program are really critical, since the universal experience of programmers who have been using measurement tools has been that their intuitive guesses fail”
in eXtreme Programming
![Page 7: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/7.jpg)
substring
String a =
String b = a.substring(1,3)
![Page 8: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/8.jpg)
substring
![Page 9: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/9.jpg)
Garbage collector
![Page 10: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/10.jpg)
Garbage collector
![Page 11: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/11.jpg)
substring
When a is not more referenced, the original char array is not deallocated, because referenced by another object
![Page 12: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/12.jpg)
substring
![Page 13: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/13.jpg)
Live Examples
![Page 14: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/14.jpg)
Hash Code / EqualsMust implement hash code as a necessary but not sufficient condition for
equality
The default implementation of hashCode() in Object class returns distinct integers for different objects.
![Page 15: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/15.jpg)
Hash Code / Equals
![Page 16: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/16.jpg)
How
•Manually add some System.out.println
•Create some kind of javax.management beans to record time. They can recorded manually and queried with tools later on.
•Use AOP Libraries to build Aspects which record code execution time.
•Build an JVMTI Agent, which uses APIs to add code and record execution time.
![Page 17: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/17.jpg)
Sampling
![Page 18: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/18.jpg)
Sampling
![Page 19: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/19.jpg)
Sampling
![Page 20: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/20.jpg)
Sampling
while (true) sleep …
ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();
threadMXBean.getThreadCpuTime(monitoredThread.getId());
![Page 21: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/21.jpg)
Instrumentation
![Page 22: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/22.jpg)
Overhead• CPU Overhead represents the additional CPU usage caused by
executing monitoring code.
• Memory overhead is caused by the additional data that is stored within the application-> send data to remote server
• Network traffic. All solutions that follow a distributed approach will also utilize the network to send data from the application to where it is stored and processed.
![Page 23: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/23.jpg)
Instrumentation• More accuracy
• More overhead
• May filter own objects
• ‘Recompiling classes’ explained
![Page 24: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/24.jpg)
Instrumentation @Around(" call(void MyApp.method* (..)) ")
public void aroundMethodCall (final ProceedingJoinPoint joinPoint) throws Throwable {
long cpuStart = threadMXBean.getCurrentThreadCpuTime();
joinPoint.proceed();
long cpuEnd = threadMXBean.getCurrentThreadCpuTime();
![Page 25: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/25.jpg)
In Marketplace
• Live instance, continuous listing import running
• looking for classes with filter market*
• memory / cpu use before and after a complete task
![Page 26: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/26.jpg)
Cpu
![Page 27: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/27.jpg)
Cpu
![Page 28: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/28.jpg)
Before…
During…
After…
![Page 29: JProfiler / an introduction](https://reader033.vdocuments.us/reader033/viewer/2022042716/55a692f91a28ab564d8b477c/html5/thumbnails/29.jpg)