Multi-Dimensional
Execution Profiling
Alexandre Bergel
University of Chile, Chile
Saturday 13 November 2010
2
2009
2009
Saturday 13 November 2010
3
}
{
}
{
}
{
}
{
}
{
Saturday 13 November 2010
4
}
{
}
{
}
{
}
{
}
{
1.4
5.2
5.6
2.3
0.5
...
Saturday 13 November 2010
5
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
1.4
5.2
5.6
2.3
0.5
... Understanding why
Saturday 13 November 2010
6
Saturday 13 November 2010
7
Saturday 13 November 2010
8
2010
2010
Saturday 13 November 2010
gprof: flat profile
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
33.34 0.02 0.02 7208 0.00 0.00 open
16.67 0.03 0.01 244 0.04 0.12 offtime
16.67 0.04 0.01 8 1.25 1.25 memccpy
16.67 0.05 0.01 7 1.43 1.43 write
16.67 0.06 0.01 mcount
0.00 0.06 0.00 236 0.00 0.00 tzset
0.00 0.06 0.00 192 0.00 0.00 tolower
0.00 0.06 0.00 47 0.00 0.00 strlen
0.00 0.06 0.00 45 0.00 0.00 strchr
9
Saturday 13 November 2010
gprof: call graph (~1984)
index % time self children called name
<spontaneous>
[1] 100.0 0.00 0.05 start [1]
0.00 0.05 1/1 main [2]
0.00 0.00 1/2 on_exit [28]
0.00 0.00 1/1 exit [59]
-----------------------------------------------
0.00 0.05 1/1 start [1]
[2] 100.0 0.00 0.05 1 main [2]
0.00 0.05 1/1 report [3]
-----------------------------------------------
0.00 0.05 1/1 main [2]
[3] 100.0 0.00 0.05 1 report [3]
0.00 0.03 8/8 timelocal [6]
0.00 0.01 1/1 print [9]
0.00 0.01 9/9 fgets [12]
0.00 0.00 12/34 strncmp <cycle 1> [40]
0.00 0.00 8/8 lookup [20]
0.00 0.00 1/1 fopen [21]
0.00 0.00 8/8 chewtime [24]
0.00 0.00 8/16 skipspace [44]
-----------------------------------------------
[4] 59.8 0.01 0.02 8+472 <cycle 2 as a whole>! [4]
0.01 0.02 244+260 offtime <cycle 2> [7]
0.00 0.00 236+1 tzset <cycle 2> [26]
-----------------------------------------------
10
Saturday 13 November 2010
YourKit
11
Saturday 13 November 2010
YourKit
12
Saturday 13 November 2010
JProfiler
13
Saturday 13 November 2010
JProfiler
14
Saturday 13 November 2010
JProfiler
15
Saturday 13 November 2010
Retrospective on profiling
16
Information conveyed hasn’t evolved since gprof
Useful to understand what happened
But is of little help to understand why and how
Is there a “slow” function that is called too often?
What makes a function “slow”?
Saturday 13 November 2010
Roadmap
1.Polymetric views
2.Profiling Blueprint
3.Implementation
17
Saturday 13 November 2010
Polymetric view can map up to 5
dimensions
width property
height
property
color
property
X property
Y
property
18
[Lanza 2003]
Saturday 13 November 2010
19
KaiProfiler
viewProfiling: [
| view |
! view := MOViewRenderer new.
! view
nodes: (1 to: 100)
forEach: [:each |
view nodes: (1 to: 100)].
! view root applyLayout
! ]
Saturday 13 November 2010
Structural blueprint
legend for methods
(color)
#different
receiver
# executions
execution
time
20
Saturday 13 November 2010
Structural blueprint
legend for methods
(color)
#different
receiver
# executions
execution
time
bounds
21
Saturday 13 November 2010
Behavioral blueprint
legend for methods
gray =
return
self
yellow =
constant
on return
value
# executions
execution
time
m2
m1
invokes
m2 and m3
m1 m3
22
Saturday 13 November 2010
Behavioral blueprint
legend for methods
gray =
return
self
yellow =
constant
on return
value
# executions
execution
time
m2
m1
invokes
m2 and m3
m1 m3
bounds
23
Saturday 13 November 2010
Detailed behavioral blueprint
MOGraphElement>>
origin
shapeBoundsAt:ifPresent:
Called by #bounds
Calling #bounds
bounds
computeExtentHavingChildrenFor:
24
Saturday 13 November 2010
Code of the bounds method
MOGraphElement>>bounds
"Answer the bounds of the receiver."
| basicBounds |
self shapeBoundsAt: self shape ifPresent: [ :b | ^ b ].
basicBounds := shape computeBoundsFor: self.
self shapeBoundsAt: self shape put: basicBounds.
^ basicBounds
25
Saturday 13 November 2010
Memoizing
MOGraphElement>>bounds
"Answer the bounds of the receiver."
| basicBounds |
boundsCache ifNotNil: [ ^ boundsCache ].
self shapeBoundsAt: self shape ifPresent: [ :b | ^ b ].
basicBounds := shape computeBoundsFor: self.
self shapeBoundsAt: self shape put: basicBounds.
^ boundsCache := basicBounds
26
Saturday 13 November 2010
A
B
C
Upgrading
MOGraphElement>>bounds
27
Saturday 13 November 2010
A
B
C
Upgrading
MOGraphElement>>bounds
43%
speedup
28
Saturday 13 November 2010
B
A
Upgrading
MOGraphElement>>bounds
29
Saturday 13 November 2010
A
B C
cached
absoluteBounds
ins
A'
C'
B'
C'
30
Saturday 13 November 2010
A
B C D
cached
absoluteBounds
make display:on:
call absoluteBounds
instead of absoluteBoundsFor:
A'
C'
B'
C'
30
Saturday 13 November 2010
B C D
make display:on:
call absoluteBounds
instead of absoluteBoundsFor:
C'
B'
C'
30
Saturday 13 November 2010
Implementation
We use the following metrics:
execution time for a method (% and ms)
number of executions
number of different object receivers
Dynamic properties
a method performs a side effect
31
Saturday 13 November 2010
Naive (but effective) implementation
Code to profile is executed twice
using a sampling method to get the execution time
instrumentation to get all the remaining metrics
Use hash values to distinguish between different
receiver objects
Built a kind of AOP mechanism for the low level
instrumentation (the Spy framework)
32
Saturday 13 November 2010
Implementation techniques
Visualizations are generated using a scripting
languages
... in Mondrian
33
Saturday 13 November 2010
34
Saturday 13 November 2010
35
2011
2011
Saturday 13 November 2010
Behavioral blueprint
legend for methods
gray =
return
self
yellow =
constant
on return
value
# executions
execution
time
m2
m1
invokes
m2 and m3
m1 m3
36
Saturday 13 November 2010
37
0
100000000
200000000
300000000
400000000
0 10000 20000 30000 40000
times (ms)
message
sends
Counting messages instead of time
sampling
Saturday 13 November 2010
Counting messages: cache warming
38
0
7500
15000
22500
30000
0 10000 20000 30000 40000
times (ms)
MR
α,c
Saturday 13 November 2010
Counting messages per methods
39
times (ms)
number of
message sends
0
2500000
5000000
7500000
10000000
0 75 150 225 300
Saturday 13 November 2010
40
Differentiation profiling
Saturday 13 November 2010
Test coverage
41
Saturday 13 November 2010
Memory blueprint
42
MetacelloProject>>
currentVersion
MetacelloProject>>
sortedAndFilteredVersions
Saturday 13 November 2010
A
B
C
www.moosetechnology.org/tools/Spy
Alexandre Bergel, Romain Robbes,
Walter Binder
Thanks to Mariano, Fabian, Felipe, ...
abergel@dcc.uchile.cl
43
Saturday 13 November 2010

Multi dimensional profiling