Transcript
Page 1: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

Analyzing Java Performance Using Hardware Performance Counters

© 2008 by AMD; made available under the EPL v1.0

Gary Frost

AMD Java Labs

[email protected]

Page 2: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

2

Agenda

AMD Java Labs

Hardware Performance Counters

A Workload To Profile

Profiling using hprof

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Profiling using hprof

Profiling with CodeAnalyst™

Profiling with CodeSleuth

Demo

Demo closure

Q&A

Page 3: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

3

AMD Java Labs

An engineering team within AMD dedicated to

improving Java performance on AMD processors

• Provide feedback/assistance in optimization work to

JVM vendors

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

• Create/Evaluate Java performance related tools

• Provide benchmark analysis (SPEC member)

• Routing community feedback to silicon designers to

improve future products

• Participate in Java and open source communities

Page 4: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

4

What Are Hardware Performance Counters?

• Programmable counters inside the processor

• Accessed via device drivers (not from user mode)

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

• Accessed via device drivers (not from user mode)

• Can generate interrupts when trigger value is reached

• System-wide

Page 5: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

5

How Performance Counters Can Help Java Developers

• Understand what the processor is really doing with

your code

• Help isolate cause of bottlenecks

• Provide detail that JVM based profilers can not

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

� hprof takes you to the method, but not into the method

• No need to inject instrumentation

• Help developers make informed code and algorithm

choices

• Measure and analyze as you develop code

Page 6: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

6

A Workload To Profile

Start

Find path between

start and end

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

End

Startstart and end

avoiding obstacles

using ‘Lee routing

algorithm’

Page 7: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

7

Mark starting cell with 1

1

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

for each cell with number ‘n’

mark adjacent empty cells ‘n+1’

until end marked | no empty cells

2

2 1

2

Page 8: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

8

Eventually...

Step onto end cell

4 5 6

5 6 7

8

11 10 9

10

3 2 3

2 1

3 2

4 3

5 4

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Step onto end cell

while (n!=1)

mark as part of path

step on adjacent cell (n-1)

4 5 6

5 6 7

8

11 10 9

10

3 2 3

2 1

3 2

4 3

5 4

Page 9: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

9

Voila !

4 5 6

7

2 3

1

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

7

8

11 10 9

1

Page 10: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

10

Profiling with hprof

Shipped with the JDK easy to use command line tool

java -agentlib:hprof=cpu=samples -cp lee.jar lee.Main

Creates a report

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Creates a report

rank self accum method

1 93% 93% lee.Grid.flood

2 2% 95% java.lang.AbstractStringBuilder.append

3 2% 97% java.util.Collections.unmodifiableList

4 2% 100% sun.nio.cs.UTF_8.newDecoder

Page 11: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

11

hprof

• Reports how much time was spent on various call paths (stacks

traces) to a method

But

• Does not tell us where within the method the time was spent

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

• Does not tell us where within the method the time was spent

• Does not expose what happens in code emitted by the JIT

(compiled methods)

hprof is representative of many Java profilers in that it is limited by the information that can be extracted from the JVM.

Page 12: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

12

How AMD’s CodeAnalyst™ Can Help

CodeAnalyst™ is a profiling tool which can access

hardware performance counters

• Timer- or Event-based Profiling

• Linux 32- and 64-bit and Microsoft® Windows® 32-

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

and 64-bit OSs

• Free! (http://developer.amd.com/tools)

• Maps performance data to address and source

(C++/C/Java)

• Includes code emitted by the JIT

Page 13: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

13

CodeAnalyst From The Command Line

•Coordinate the launching of an executablecaprofile /s /l java –cp my.jar –agentlib:CAJVMTIA32 MyApp

•Profiler (caprofile) collects event data

•JVMTI agent (CAJVMTIA32) collects JIT data

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

• JVMTI agent (CAJVMTIA32) collects JIT data

•Correlates and creates reportscadataanalyze

careport /i profile.tbp.dir/profile.tbp /m MyApp

Page 14: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

14

CodeAnalyst

caprofile /s /l java –cp my.jar –agentlib:CAJVMTIA32 MyApp

caprofile jvm caprof.sys

start collecting

jvmtia agent

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

start collecting

java –agentlib:CAJVMTIA32 MyApp

stop collecting

process ends

method

compilation

dataperformance

data

compilation

events

Page 15: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

15

CodeAnalyst

cadataanalyze

careport /i profile.tbp.dir/profile.tbp /m MyApp

performance

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

method

compilation

data

cadatanalyze

careport

performance data

Page 16: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

16

CodeAnalyst

•Event data, addresses, and methods

vma Timer % total Name

0x9877c0 24269 56.00 lee/Grid::flood

0x98781b 1 0.00

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

0x98781b 1 0.00

0x98784d 6132 14.28

0x987853 474 1.10

0x987857 13135 30.58

0x987859 402 0.94

Page 17: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

17

CodeAnalyst UI

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 18: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

18

CodeSleuth

• Open Source (EPL)

• Brings various CodeAnalyst ‘views’ into Eclipse

• More natural for Java developers

� Same IDE we are used to

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

� SourceView is your Java editor

� ‘Markers’ indicate event data we can expand

� Configure CodeAnalyst TM parameters in Launch

Configuration

� Cross reference architecture documentation from within IDE

• Makes Java analysis easier

Page 19: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

19

CodeSleuth Run Configuration

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 20: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

20

CodeSleuth Navigation View

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 21: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

21

Linking views to Java source

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 22: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

22

CodeSleuth Disassembled Code View

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 23: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

23

Documentation Views

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 24: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

24

Demo CodeSleuth

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Page 25: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

25

Demo Closure

• Code uses a large two dimensional array

• The order ‘x by y’ or ‘y by x’ for traversing this array is

important when arrays are large (cache implications)

• The original scan order does not take advantage of the

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

cache, in fact it ‘pollutes’ its own cache

• By reordering the scan we can decrease cache

pollution and thus improve performance

Page 26: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

26

• If we had 2 cache lines, each of which can hold 4 cells

Y by X (Column Major)

Demo Closure

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

X by Y (Row Major)

Cache miss, load, miss, load, miss, load (last load replaces first line!)

Cache miss, load, hit, hit

Page 27: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

27

Conclusions

• Hardware performance counters can help reveal

performance issues

• CodeAnalyst enables you to analyze CPU level

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

performance of Java applications

• CodeSleuth helps bring the power of this tool into your

favorite IDE

• Promote the inclusion of performance analysis as part

of your development/test cycle

Page 28: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

28

CodeSleuth Links

Site

http://developer.amd.com/codesleuth

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

Source

http://codesleuth.sourceforge.net

Update Site

http://developer.amd.com/codesleuth_1_0_0

Page 29: Gary Frost AMD Java Labs gary.frost@amd...5 How Performance Counters Can Help Java Developers •Understand what the processor is really doing with your code •Help isolate cause

29

Links

• http://developer.amd.com

� Software downloads

� AMD Java Labs blog

� Forum discussions

Analyzing Java Performance Using Hardware Performance Counters | © 2008 by AMD; made available under the EPL v1.0

• Lee, C.Y., "An Algorithm for Path Connections and Its

Applications", IRE Transactions on Electronic Computers, vol.

EC-10, number 2, pp. 364-365, 1961


Top Related