JProfiler / an introduction

29
JProfiler introduction Tommaso Torti

Transcript of JProfiler / an introduction

Page 1: JProfiler / an introduction

JProfiler introductionTommaso Torti

Page 2: JProfiler / an introduction

in eXtreme Programming

Make It Work Make It Right Make It Fast

Page 3: JProfiler / an introduction

Premature optimization is the root of all evil

in eXtreme Programming

Page 4: JProfiler / an introduction

“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

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

“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

substring

String a =

String b = a.substring(1,3)

Page 8: JProfiler / an introduction

substring

Page 9: JProfiler / an introduction

Garbage collector

Page 10: JProfiler / an introduction

Garbage collector

Page 11: JProfiler / an introduction

substring

When a is not more referenced, the original char array is not deallocated, because referenced by another object

Page 12: JProfiler / an introduction

substring

Page 13: JProfiler / an introduction

Live Examples

Page 14: JProfiler / an introduction

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

Hash Code / Equals

Page 16: JProfiler / an introduction

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

Sampling

Page 18: JProfiler / an introduction

Sampling

Page 19: JProfiler / an introduction

Sampling

Page 20: JProfiler / an introduction

Sampling

while (true) sleep …

ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();

threadMXBean.getThreadCpuTime(monitoredThread.getId());

Page 21: JProfiler / an introduction

Instrumentation

Page 22: JProfiler / an introduction

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

Instrumentation• More accuracy

• More overhead

• May filter own objects

• ‘Recompiling classes’ explained

Page 24: JProfiler / an introduction

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

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

Cpu

Page 27: JProfiler / an introduction

Cpu

Page 28: JProfiler / an introduction

Before…

During…

After…

Page 29: JProfiler / an introduction