ThoughtWorks
visualizations for
code metrics
NEAL FORD software architect / meme wrangler
ThoughtWorks
nford@[Link]
3003 Summit Boulevard, Atlanta, GA 30319
[Link]
[Link]
blog: [Link]
twitter: neal4d
housekeeping
ask questions anytime
download slides from
[Link]
download samples from [Link]/nealford
what was that?
code_swarm
[Link]
point it to a subversion repository
visualization of check-ins over time
useful? cool!
[Link]
wtf’s/min
external
perspective
is the software valuable to its users?
internal perspective
how appropriate is the design?
how amenable is emergent design?
how easy is it to understand & extend?
how maintainable is it?
is it salvageable?
30,000 feet ground level
[Link]
where are the defects?
which way do the
messages flow?
where do the pictures
come from?
models created up front convey a vision but
usually don’t reflect reality
generating a complete model for large systems
is nearly impossible
systems evolve locally, often uncontrolled
the best picture very much depends on the
question you are trying to answer
need tools to create ad-hoc models more
easily
1. select a meta-model
a model that describes a model
example: meta-model for a class diagram
a class is a box with name, methods, fields,...
available connectors: association,
inheritance, aggregation…
rules: no circles in inheritance, etc.
common meta-models
Metrics (Quantitative) Directed Graph
M1
xyz
Foo Clas M1 M2 M3
s
Bar
M2 Foo 3.4 3.8 6.5
Bar 5.0 0.0 10.0
M1
… … … …
Tree Process Model
(e.g. Petri Net)
2. inspection /
instrumentation
static analysis
source code
byte code
dynamic analysis
profiling, listen to messages, log files,
network sniffer, etc.
3. mapping to the
model
Senders Receivers
example: messaging system Comp. Channel Comp. Channel
A X C X
B Y C Y
capture send/receive actions
Mapper
map onto directed graph Nodes: A, B, C
Edges: X(A!C)
Y(B!C)
Graph Model
4. visualization &...
Graphviz
...validation
don’t simply observe
verify & alert
enforce rules or best practices
detect cycles
islands on a dependency graph
the hawthorne effect
the hawthorne effect
measure and let it be known that
you are measuring
metrics
cyclomatic complexity
measures complexity of a function
V(G)= e - n + 2
V(G) = cyclomatic complexity of G
e= # edges
n= # of nodes
start
1 if (c1)
1
2 f1() 3 f2()
4
4
3
if (c2)
5 6
nodes
5 f3() 6 f4()
edges
7
8
7
end
chidamber & kemerer
object-oriented metrics
shyam r chidamber
chris 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
number of public
npm # public methods in class
methods
very useful
weighted methods/
wmc ∑ of cyclomatic complexity
class
# of methods executed due to
rfc response for class
method call
∑ of sets of methods not shared
lcom lack of cohesion
via sharing fields
cbo/ ∑ of other classes this class uses
efferent couplings
ce (outgoing calls)
∑ of how many other classes
ca afferent couplings
use this class (incoming calls)
visualizations
source monitor
freeware tool for gathering metrics
metrics:
lines, statements, % branches, calls, %
comments, classes, methods/class, avg stmts/
method, max complexity, max depth, average
depth, average complexity
graphical user interface, windows only!
source monitor:
kiviat graphs
source monitor:
class summary
source monitor w/ c#
looking for...
classes that violate several kiviat graph ranges
really odd shapes
“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.”
panopticode parts
code coverage with emma
1-line change to switch to cobertura
checkstyle
1-line switch for custom rule sets
jdepend code duplication using simian
javancss aggregator & reports
volatility treemaps
complexity treemap
code coverage
looking for...
20,000 foot view along a single dimension
simple view of one dimension
information radiators
size & complexity
pyramid
developed at Universities of Berne and Lugano
shows key metrics and their relationships
allows comparison to “industry standards”
created by iPlasma tool from source code
pyramid
5.75 NOP 224
6.13 NOC 1289
5.69 NOM 7905 7905 NOM 2.79
0.26 LOC 44988 22039 CALLS 0.40
CYCLO 11602 8798 FANOUT
iPlasma + Struts
vuze
looking for...
adherence to industry standards
low number of lines / method
(see composed method pattern)
low cyclomatic complexity / line
GraphViz
e
v d
e o
n t
t
l f
i i
s l
t e
output
generating dot files
untangling
jars
jar analyzer
Kirk Knoernschild
[Link]
xml output
t
r
a
n
s
f
o
r
m
e
d
graphical
struts 1.0
looking for...
not that!
small number of one-
way dependencies
no “rats’ nests”
no cycles
Vizant
ant task to create a GraphViz
DOT file from an ant build file
[Link]
ant 1.5
log4j
tomcat 3.3.1
from=“dist”
to=“prepare”
look for...
hot spots
more even distribution
networks around common dependent elements
think about extracting
via macrodef
SpringViz
XSLT => DOT for spring
dependencies
[Link]
SpringViz
look for...
regularity
symmetry
overloaded dependencies
isolated pockets
toxicity chart
provides easy to compare
overview of quality
created with checkstyle +
excel
30.0
35.0
40.0
20.0
25.0
0.0
5.0
10.0
15.0
SessionFactory [Link]
AbstractBeanFactory .java
[Link] a
DispatcherServ [Link]
SchedulerFactory [Link]
[Link] a
[Link] a
[Link] a
[Link] a
PropertiesBeanDef [Link] a
[Link]
Lazy ConnectionDataSourceProxy .java
BooleanExpressionComplexity
Def [Link]
[Link] a
[Link] a
ScriptFactory [Link]
TransactionAwareConnectionFactory [Link]
[Link] a
[Link] a
SpringSessionSy [Link] a
BeanDef initionValueResolv [Link]
ExtendedEntity [Link] a
ParameterMethodNameResolv [Link]
[Link]
BeanFactory [Link]
[Link] a
[Link] a
GenericCollectionTy peResolv [Link]
ArgumentConv ertingMethodInv [Link]
SharedEntity [Link] a
FreeMarkerConf [Link]
[Link] a
ClassDataAbstractionCoupling ClassFanOutComplexity
MockHttpServ [Link]
[Link] a
ResourceArray Property [Link]
AspectJWeav [Link]
[Link] a
SingleConnectionFactory .java
[Link] a
[Link] a
[Link]
Velocity [Link] a
[Link]
[Link] a
CyclomaticComplexity FileLength
PortletRequestHandledEv [Link]
[Link] a
TxAdv iceBeanDef [Link]
ArgTy [Link] a
Ref [Link]
[Link]
MethodLength
[Link]
[Link] a
[Link] a
[Link] a
Def aultBeanDef [Link]
NestedIfDepth
[Link]
[Link] a
[Link] a
[Link] a
AbstractSingletonProxy [Link]
LocalSlsbInv [Link]
BeansDtdResolv [Link]
AnonInnerLength
[Link] a
AbstractDependency [Link]
toxicity chart
[Link]
LocalContainerEntity [Link]
ResourceEntity [Link]
[Link] a
[Link]
[Link] a
[Link]
ResourceServ [Link]
Adv [Link] a
EhCacheFactory [Link]
[Link]
[Link] a
OpenEntity [Link] a
[Link] a
MethodInv [Link]
Def [Link]
[Link] a
[Link] a
ParameterNumber MissingSwitchDefault TreeWalker
HessianServ [Link]
Property [Link]
InstantiationModelAwarePointcutAdv [Link]
0.80
1.00
1.20
1.40
1.60
1/4/06
15/4/06
29/4/06
1
13/5/06
27/5/06
10/6/06
2
24/6/06
8/7/06
22/7/06
5/8/06
19/8/06
2/9/06
3
16/9/06
30/9/06
14/10/06
28/10/06
3.05
3.1
11/11/06
Releases
25/11/06
9/12/06
23/12/06
4
6/1/07
20/1/07 5
3/2/07
6
Unit test LOC/LOC
17/2/07
3/3/07
7
17/3/07
31/3/07
Lines of unit test code per line of production code
8 9
14/4/07
10
28/4/07
12/5/07
26/5/07
created using unix tools + excel
11 12 13
9/6/07
14
test to code ratio
23/6/07
15
7/7/07
16
21/7/07
17
4/8/07
18/8/07
cc / loc / releases
look for...
notifications along your key dimension
toxicity: high-spikes
test-to-code ratio: higher is better
complexity / loc: trends
deltas more interesting than
raw numbers
“Unveiling the beauty of statistics for a fact
based world view.”
time-based statistical view of chart data
founded in Stockholm by Ola Rosling, Anna
Rosling Rönnlund and Hans Rosling
now realized in the google spreadsheet motion
gadget
the data
motion chart gadget
look for...
time-based trends
odd outliers along
dimensions
symmetry
fluidity
CodeCrawler
[Link]/faculty/lanza/[Link]
CodeCrawler
CodeCrawler
academic graphical metrics tool
language independent
written in VisualAge Smalltalk
based on the Moose platform
quirky but powerful
x-ray
graduate student project written by Jacopo
Malnati ([Link]
open-source software visualization plug-in for
eclipse
provides system complexity view, class &
package dependency view
model of the underlying Java project can be
triggered and used by other plug-ins
x-ray visualizing itself through via system complexity view
using x-ray
install the plug-in
choose the Analyze Current Project action
from the package explorer
x-ray creates textual information and actions
visualizations characterized by entities
positioned according to layouts and criterions
actions show/hide
# packages nodes
# methods
open selected
show
classes
dependencies
lines of code color tag
project name
snapshot image
# classes
show/hide
package content
polymetric views
system complexity view
class dependency view
package dependency view
system complexity view
system complexity view
tries to illustrate disharmonies in the design
and implementation of a system.
identify big nodes (compared to the others)
anomalies of shape (provided by the inheritance
tree)
view provides several different dimensions of
metrics
positional metrics
system complexity view
color metrics
system complexity view
Azureus 3.0
(more than
500,000 lines of
code)
x-ray itself
dependencies
outgoing
incoming
class & package
dependency views
class dependency view
package dependency
Azureus packages
filtering (< 30 weight)
proximity alert
look for...
towers (=> lots of code, lots of methods)
tangled dependencies
exuberant responsibility
natural partitions
balance
10,000 ft view (literally)
CodeCity by
Richard Wettel
[Link]
CodeCity
integrated environment for software analysis
software systems are visualized as interactive,
navigable 3D cities
written in VisualWorks Smalltalk, atop the
Moose platform
classes => buildings
packages => districts
citylyzer
Citylyzer
written atop x-ray
inspired by CodeCity
building height => number of methods
width/length => number of attributes
packages => districts
look for...
“real” cityscape
buildings that wouldn’t
exist in the real world
overly crowded neighborhoods
abandoned parts of town
would you live there?
metrics + agility
wire metrics & analysis into
continuous integration
manually check often
discuss on iteration boundaries
fail the build with:
xpath expressions & plugins
jdepend-like unit tests
summary
intermediate altitude
information radiators
single dimensions
compelling evidence
cool!
ThoughtWorks
?’s
please fill out the session evaluations
samples at [Link]/nealford
NEAL FORD software architect / meme wrangler
ThoughtWorks
This work is licensed under the Creative Commons nford@[Link]
Attribution-Share Alike 3.0 License. 3003 Summit Boulevard, Atlanta, GA 30319
[Link]
[Link]
[Link] blog: [Link]
twitter: neal4d