vizualizations for code metrics - jfokus...thoughtworks neal ford software architect / meme wr angle...
TRANSCRIPT
ThoughtWorksThoughtWorks
NEAL FORD software architect / meme wrangler
ThoughtWorks
[email protected] 3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
blog: memeagora.blogspot.com
twitter: neal4d
visualizations for code metrics
housekeepingask questions anytime
download slides from nealford.com
download samples from github.com/nealford
point it to a subversion repository
code_swarm
http://code.google.com/p/codeswarm/
useful? cool!
visualization of check-ins over time
what was that?
http://www.wired.com/wired/issue/16-07
wtf’s/min
external perspective
is the software valuable to its users?
how easy is it to understand & extend?
how appropriate is the design?
how amenable is emergent design?
is it salvageable?
how maintainable is it?
internal perspective
30,000 feet ground level
http://opensimulator.org/wiki/Grid_Architecture_Diagram
where are the defects?
which way do the messages flow?
systems evolve locally, often uncontrolled
models created up front convey a vision but usually don’t reflect reality
generating a complete model for large systems is nearly impossible
need tools to create ad-hoc models more easily
the best picture very much depends on the question you are trying to answer
where do the pictures come from?
a class is a box with name, methods, fields,...
a model that describes a model
example: meta-model for a class diagram
rules: no circles in inheritance, etc.
available connectors: association, inheritance, aggregation…
1. select a meta-model
common meta-models
Clas
s
M1 M2 M3
Foo 3.4 3.8 6.5
Bar 5.0 0.0 10.0
… … … …
M1
M2
Foo
Bar
xyz
M1
Metrics (Quantitative) Directed Graph
Tree Process Model (e.g. Petri Net)
byte code
static analysis
source code
profiling, listen to messages, log files, network sniffer, etc.
dynamic analysis
2. inspection / instrumentation
3. mapping to the model
Mapper
Comp. Channel
A X
B Y
Comp. Channel
C X
C Y
Senders Receivers
Nodes: A, B, CEdges: X(A!C) Y(B!C)
Graph Model
example: messaging system
capture send/receive actions
map onto directed graph
4. visualization &...
Graphviz
enforce rules or best practices
don’t simply observe
verify & alert
islands on a dependency graph
detect cycles
...validation
the hawthorne effect
measure and let it be known that you are measuring
the hawthorne effect
metrics
cyclomatic complexitymeasures complexity of a function
V(G)= e - n + 2V(G) = cyclomatic complexity of Ge= # edgesn= # of nodes
start
if (c1)
f1() f2()
if (c2)
f3() f4()
end
start
if (c1)
f1() f2()
if (c2)
f3() f4()
end
7
65
4
32
1
8
7
65
4
3
2
1
nodes
edges
chidamber & kemererobject-oriented metrics
shyam r chidamberchris f kemerer
easy but not terribly useful very useful
easy (but trivial)
dit depth of inheritance tree # levels of inheritance
noc number of children # immediate descendants
npm number of public methods
# public methods in class
very usefulwmc weighted methods/
class ∑ of cyclomatic complexity
rfc response for class # of methods executed due to method call
lcom lack of cohesion ∑ of sets of methods not shared via sharing fields
cbo/ce
efferent couplings ∑ of other classes this class uses (outgoing calls)
ca afferent couplings ∑ of how many other classes use this class (incoming calls)
visualizations
lines, statements, % branches, calls, % comments, classes, methods/class, avg stmts/method, max complexity, max depth, average depth, average complexity
freeware tool for gathering metrics
metrics:
graphical user interface, windows only!
source monitor
source monitor:kiviat graphs
source monitor:class summary
source monitor w/ c#
classes that violate several kiviat graph ranges
really odd shapes
looking for...
“A project dedicated to making code metrics so widely understood, valuable, and simple that their use becomes ubiquitous, thus raising the quality of software across
the industry.”
jdepend
code coverage with emma1-line change to switch to cobertura
checkstyle1-line switch for custom rule sets
volatility
javancss
panopticode parts
code duplication using simian
aggregator & reports
treemaps
complexity treemap
code coverage
20,000 foot view along a single dimension
simple view of one dimension
information radiators
looking for...
allows comparison to “industry standards”
developed at Universities of Berne and Lugano
shows key metrics and their relationships
created by iPlasma tool from source code
size & complexity pyramid
pyramid5.75 NOP 224
6.13 NOC 12895.69 NOM 7905 7905 NOM 2.79
0.26 LOC 44988 22039 CALLS 0.40CYCLO 11602 8798 FANOUT
iPlasma + Struts
vuze
low cyclomatic complexity / line
adherence to industry standards
low number of lines / method (see composed method pattern)
looking for...
GraphViz
e v e n t l i s t
d o t
f i l e
output
generating dot files
untangling jars
Kirk Knoernschildwww.kirkk.com
jar analyzer
xml output
t r a n s f o r m e d
graphical
struts 1.0
no “rats’ nests”
not that!
small number of one-way dependencies
no cycles
looking for...
Vizantant task to create a GraphViz DOT file from an ant build file
http://vizant.sourceforge.net/
ant 1.5
log4j
tomcat 3.3.1
from=“dist”
to=“prepare”
networks around common dependent elements
hot spots
more even distribution
think about extracting via macrodef
look for...
SpringVizXSLT => DOT for spring
dependencies
http://www.samoht.com/wiki/wiki.pl?SpringViz
SpringViz
overloaded dependencies
regularity
symmetry
isolated pockets
look for...
toxicity chart
provides easy to compare overview of quality
created with checkstyle + excel
toxicity chart
0.0
5.0
10.0
15.0
20.0
25.0
30.0
35.0
40.0
Ses
sio
nF
acto
ryU
tils
.jav
a
Abs
tra
ctB
ea
nF
ac
tory
.java
Bea
nW
rapp
erI
mp
l.ja
va
Dis
pa
tch
erS
erv
let.
java
Sch
ed
ule
rFa
cto
ryB
ea
n.ja
va
AntP
ath
Ma
tch
er.
jav
a
SQ
LE
rro
rCo
de
SQ
LE
xc
eptio
nT
rans
lato
r.ja
va
Hib
ern
ate
Te
mp
late
.ja
va
Re
load
able
Re
so
urc
eB
und
leM
ess
age
So
urc
e.ja
va
Pro
pe
rtie
sB
ea
nD
efi
nitio
nR
ead
er.
jav
a
Sta
tem
entC
reato
rUtils
.jav
a
Lazy
Co
nn
ec
tio
nD
ata
So
urc
eP
rox
y.ja
va
De
fau
ltM
ess
ag
eL
iste
ne
rCo
nta
ine
r.ja
va
Jd
oTra
ns
actio
nM
an
ag
er.
jav
a
To
pLin
kT
rans
actio
nM
an
ag
er.
jav
a
Scrip
tFa
cto
ryP
os
tPro
ce
sso
r.ja
va
Tra
ns
ac
tio
nA
wa
reC
on
ne
ctio
nF
acto
ryP
roxy
.jav
a
Nu
mb
erU
tils
.ja
va
Hib
ern
ate
Acc
ess
or.
jav
a
Sprin
gS
ess
ionS
yn
ch
ron
iza
tio
n.ja
va
Bea
nD
efi
nitio
nV
alu
eR
eso
lve
r.ja
va
Exte
nde
dE
ntity
Ma
nag
erC
reato
r.ja
va
Para
me
terM
eth
od
Na
me
Re
so
lve
r.ja
va
Ca
llab
leS
tate
me
ntC
reato
rFa
cto
ry.jav
a
Bea
nF
acto
ryA
sp
ec
tJA
dvis
ors
Build
er.
java
Cu
sto
miz
able
Tra
ce
Inte
rce
pto
r.ja
va
Abs
tra
ctX
slt
Vie
w.ja
va
Gen
eric
Co
llectio
nT
yp
eR
eso
lve
r.ja
va
Arg
um
entC
onv
ert
ingM
eth
od
Inv
oke
r.ja
va
Sha
red
Entity
Ma
nag
erC
reato
r.ja
va
Fre
eM
ark
erC
onfi
gura
tio
nF
acto
ry.ja
va
Sele
cte
dV
alu
eC
om
pa
rato
r.ja
va
Mo
ck
Htt
pS
erv
letR
eq
ue
st.ja
va
Fra
me
wo
rkP
ort
let.
jav
a
Re
so
urc
eA
rra
yP
rope
rty
Edit
or.
java
Asp
ec
tJW
ea
ve
rMe
ss
ag
eH
and
ler.
java
Me
tho
dM
apT
rans
ac
tio
nA
ttrib
ute
Sou
rce
.ja
va
Sin
gle
Co
nne
ctio
nF
ac
tory
.ja
va
Me
ss
age
Lis
ten
erA
dap
ter.
jav
a
Jd
oTe
mp
late
.ja
va
Da
taS
ou
rce
Utils
.ja
va
Velo
cit
yV
iew
.ja
va
Abs
tra
ctM
es
sa
ge
Lis
ten
erC
onta
iner.
java
SqlL
ob
Valu
e.ja
va
Port
letR
eq
ue
stH
an
dle
dE
ve
nt.
jav
a
Jd
bcO
pe
ratio
ns
.ja
va
Tx
Adv
ice
Bea
nD
efi
nitio
nP
ars
er.
java
Arg
Ty
pe
Pre
pare
dS
tate
me
ntS
ett
er.
jav
a
Re
fre
sh
ab
leP
ag
edL
istH
old
er.
java
Abs
tra
ctJ
asp
erR
ep
ort
sS
ing
leF
orm
atV
iew
.ja
va
Cla
ss
Utils
.ja
va
Sim
ple
Ma
ilMe
ss
age
.ja
va
Jm
sT
rans
ac
tio
nM
ana
ge
r.ja
va
Tra
ns
ac
tio
nA
ttrib
ute
Edit
or.
jav
a
De
fau
ltB
ea
nD
efi
niti
onD
oc
um
entR
ea
de
r.ja
va
Abs
tra
ctI
nte
rce
pto
rDriv
en
Be
an
De
fin
itio
nD
eco
rato
r.ja
va
Re
su
ltS
etW
rapp
ing
Sq
lRo
wS
et.
jav
a
Hs
qlM
ax
Valu
eIn
cre
me
nte
r.ja
va
Co
deb
as
eA
wa
reO
bje
ctI
np
utS
tre
am
.ja
va
Abs
tra
ctS
ing
leto
nP
roxy
Fa
cto
ryB
ea
n.jav
a
Loc
alS
lsb
Inv
oke
rIn
terc
ep
tor.
java
Bea
ns
Dtd
Re
so
lve
r.ja
va
Abs
tra
ctM
es
sa
ge
So
urc
e.ja
va
Abs
tra
ctD
ep
en
de
nc
yIn
ject
ionS
prin
gC
onte
xtT
es
ts.ja
va
To
mc
atI
ns
tru
me
nta
ble
Cla
ss
Loa
de
r.ja
va
Loc
alC
onta
inerE
ntity
Ma
na
gerF
acto
ryB
ea
n.ja
va
Re
so
urc
eE
ntity
Re
solv
er.
java
Re
dire
ctV
iew
.ja
va
Htm
lCh
ara
cte
rEn
tity
Ref
ere
nce
s.ja
va
Abs
tra
ctP
ath
Ma
pH
an
dle
rMa
pp
ing
.ja
va
Asp
ec
tJP
rec
ed
en
ce
Co
mp
ara
tor.
java
Re
so
urc
eS
erv
let.
java
Adv
ise
dS
upp
ort
.ja
va
EhC
ach
eF
ac
tory
Bea
n.ja
va
Cu
sto
mC
olle
ctio
nE
dit
or.
java
Co
mm
ons
Mu
ltip
art
File
.ja
va
Ope
nE
ntity
Ma
na
ge
rIn
Vie
wF
ilte
r.ja
va
To
pLin
kIn
terc
epto
r.ja
va
Me
tho
dIn
vo
kin
gJ
ob
De
tailF
acto
ryB
ea
n.ja
va
De
fau
ltN
am
es
pa
ce
Ha
ndle
rRe
solv
er.
jav
a
Xm
lValid
atio
nM
od
eD
ete
cto
r.ja
va
Gen
eric
Filt
erB
ea
n.ja
va
He
ss
ianS
erv
ice
Exp
ort
er.
java
Pro
pe
rty
Acc
es
so
rUtils
.jav
a
Insta
ntia
tio
nM
ode
lAw
are
Poin
tcu
tAdv
iso
rIm
pl.
java
BooleanExpressionComplexity ClassDataAbstractionCoupling ClassFanOutComplexity CyclomaticComplexity FileLength MethodLength NestedIfDepth AnonInnerLength ParameterNumber MissingSwitchDefault TreeWalker
test to code ratioLines of unit test code per line of production code
1 2 3 3.053.1 4 5 6 7 8 9 10 11 12 13 14 15 16 17
0.80
1.00
1.20
1.40
1.60
1/4/06
15/4/06
29/4/06
13/5/06
27/5/06
10/6/06
24/6/06
8/7/06
22/7/06
5/8/06
19/8/06
2/9/06
16/9/06
30/9/06
14/10/06
28/10/06
11/11/06
25/11/06
9/12/06
23/12/06
6/1/07
20/1/07
3/2/07
17/2/07
3/3/07
17/3/07
31/3/07
14/4/07
28/4/07
12/5/07
26/5/07
9/6/07
23/6/07
7/7/07
21/7/07
4/8/07
18/8/07
Releases Unit test LOC/LOC
created using unix tools + excel
cc / loc / releases
test-to-code ratio: higher is better
notifications along your key dimension
toxicity: high-spikes
deltas more interesting than raw numbers
complexity / loc: trends
look for...
founded in Stockholm by Ola Rosling, Anna Rosling Rönnlund and Hans Rosling
“Unveiling the beauty of statistics for a fact based world view.”
time-based statistical view of chart data
now realized in the google spreadsheet motion gadget
the data
motion chart gadget
symmetry
time-based trends
odd outliers along dimensions
fluidity
look for...
CodeCrawlerwww.inf.unisi.ch/faculty/lanza/codecrawler.html
CodeCrawler
written in VisualAge Smalltalk
academic graphical metrics tool
language independent
quirky but powerful
based on the Moose platform
CodeCrawler
provides system complexity view, class & package dependency view
graduate student project written by Jacopo Malnati (http://atelier.inf.unisi.ch/~malnatij/xray.php)
open-source software visualization plug-in for eclipse
model of the underlying Java project can be triggered and used by other plug-ins
x-ray
x-ray visualizing itself through via system complexity view
x-ray creates textual information and actions
install the plug-in
choose the Analyze Current Project action from the package explorer
visualizations characterized by entities positioned according to layouts and criterions
using x-ray
actions
project name
# classes
# methods# packages
lines of code
show dependencies
color tag
show/hide nodes
show/hide package content
open selected classes
snapshot image
class dependency view
system complexity view
package dependency view
polymetric views
system complexity view
anomalies of shape (provided by the inheritance tree)
tries to illustrate disharmonies in the design and implementation of a system.
identify big nodes (compared to the others)
view provides several different dimensions of metrics
system complexity view
positional metrics
system complexity view
color metrics
system complexity view
Azureus 3.0 (more than
500,000 lines of code)
x-ray itself
dependencies
incoming
outgoing
class & package dependency views
class dependency view
package dependency
Azureus packages
filtering (< 30 weight)
proximity alert
exuberant responsibility
towers (=> lots of code, lots of methods)
tangled dependencies
balance
natural partitions
look for...
10,000 ft view (literally)
CodeCity by Richard Wettel
http://www.inf.unisi.ch/phd/wettel/codecity.html
written in VisualWorks Smalltalk, atop the Moose platform
integrated environment for software analysis
software systems are visualized as interactive, navigable 3D cities
packages => districts
classes => buildings
CodeCity
citylyzer
building height => number of methods
written atop x-ray
inspired by CodeCity
packages => districts
width/length => number of attributes
Citylyzer
overly crowded neighborhoods
“real” cityscape
buildings that wouldn’t exist in the real world
would you live there?
abandoned parts of town
look for...
discuss on iteration boundaries
wire metrics & analysis into continuous integration
manually check often
fail the build with: xpath expressions & plugins jdepend-like unit tests
metrics + agility
single dimensions
intermediate altitude
information radiators
cool!
compelling evidence
summary
ThoughtWorks
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License.
http://creativecommons.org/licenses/by-sa/3.0/us/
?’splease fill out the session evaluationssamples at github.com/nealford
NEAL FORD software architect / meme wrangler
ThoughtWorks
[email protected] 3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
blog: memeagora.blogspot.com
twitter: neal4d