JProfiler introductionTommaso Torti
in eXtreme Programming
Make It Work Make It Right Make It Fast
Premature optimization is the root of all evil
in eXtreme Programming
“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
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.
“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
substring
String a =
String b = a.substring(1,3)
substring
Garbage collector
Garbage collector
substring
When a is not more referenced, the original char array is not deallocated, because referenced by another object
substring
Live Examples
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.
Hash Code / Equals
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.
Sampling
Sampling
Sampling
Sampling
while (true) sleep …
ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();
threadMXBean.getThreadCpuTime(monitoredThread.getId());
Instrumentation
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.
Instrumentation• More accuracy
• More overhead
• May filter own objects
• ‘Recompiling classes’ explained
Instrumentation @Around(" call(void MyApp.method* (..)) ")
public void aroundMethodCall (final ProceedingJoinPoint joinPoint) throws Throwable {
long cpuStart = threadMXBean.getCurrentThreadCpuTime();
joinPoint.proceed();
long cpuEnd = threadMXBean.getCurrentThreadCpuTime();
In Marketplace
• Live instance, continuous listing import running
• looking for classes with filter market*
• memory / cpu use before and after a complete task
Cpu
Cpu
Before…
During…
After…
Top Related