Visualizations For Code Metrics (Neal Ford)
Visualizations For Code Metrics (Neal Ford)
visualizations for
code metrics
NEAL FORD software architect / meme wrangler
ThoughtWorks
nford@thoughtworks.com
3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
blog: memeagora.blogspot.com
twitter: neal4d
housekeeping
ask questions anytime
http://code.google.com/p/codeswarm/
useful? cool!
http://www.wired.com/wired/issue/16-07
wtf’s/min
external
perspective
is it salvageable?
30,000 feet ground level
http://opensimulator.org/wiki/Grid_Architecture_Diagram
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
source code
byte code
dynamic analysis
Graph Model
4. visualization &...
Graphviz
...validation
don’t simply observe
detect cycles
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
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
volatility treemaps
complexity treemap
code coverage
looking for...
20,000 foot view along a single dimension
information radiators
size & complexity
pyramid
developed at Universities of Berne and Lugano
jar analyzer
Kirk Knoernschild
www.kirkk.com
xml output
t
r
a
n
s
f
o
r
m
e
d
graphical
struts 1.0
looking for...
not that!
no “rats’ nests”
no cycles
Vizant
ant 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”
look for...
hot spots
symmetry
overloaded dependencies
isolated pockets
toxicity chart
20.0
25.0
0.0
5.0
10.0
15.0
SessionFactory Utils.java
AbstractBeanFactory .java
BeanWrapperImpl.jav a
DispatcherServ let.java
SchedulerFactory Bean.java
AntPathMatcher.jav a
SQLErrorCodeSQLExceptionTranslator.jav a
HibernateTemplate.jav a
ReloadableResourceBundleMessageSource.jav a
PropertiesBeanDef initionReader.jav a
StatementCreatorUtils.java
Lazy ConnectionDataSourceProxy .java
BooleanExpressionComplexity
Def aultMessageListenerContainer.java
JdoTransactionManager.jav a
TopLinkTransactionManager.jav a
ScriptFactory PostProcessor.java
TransactionAwareConnectionFactory Proxy.java
NumberUtils.jav a
HibernateAccessor.jav a
SpringSessionSy nchronization.jav a
BeanDef initionValueResolv er.java
ExtendedEntity ManagerCreator.jav a
ParameterMethodNameResolv er.java
CallableStatementCreatorFactory.java
BeanFactory AspectJAdvisorsBuilder.java
CustomizableTraceInterceptor.jav a
AbstractXsltView.jav a
GenericCollectionTy peResolv er.java
ArgumentConv ertingMethodInv oker.java
SharedEntity ManagerCreator.jav a
FreeMarkerConf igurationFactory.java
SelectedValueComparator.jav a
ClassDataAbstractionCoupling ClassFanOutComplexity
MockHttpServ letRequest.java
FrameworkPortlet.jav a
ResourceArray Property Editor.java
AspectJWeav erMessageHandler.java
MethodMapTransactionAttributeSource.jav a
SingleConnectionFactory .java
MessageListenerAdapter.jav a
JdoTemplate.jav a
DataSourceUtils.java
Velocity View.jav a
AbstractMessageListenerContainer.java
SqlLobValue.jav a
CyclomaticComplexity FileLength
PortletRequestHandledEv ent.java
JdbcOperations.jav a
TxAdv iceBeanDef initionParser.java
ArgTy pePreparedStatementSetter.jav a
Ref reshablePagedListHolder.java
AbstractJasperReportsSingleFormatView.java
MethodLength
ClassUtils.java
SimpleMailMessage.jav a
JmsTransactionManager.jav a
TransactionAttributeEditor.jav a
Def aultBeanDef initionDocumentReader.java
NestedIfDepth
AbstractInterceptorDrivenBeanDefinitionDecorator.java
ResultSetWrappingSqlRowSet.jav a
HsqlMaxValueIncrementer.jav a
CodebaseAwareObjectInputStream.jav a
AbstractSingletonProxy FactoryBean.java
LocalSlsbInv okerInterceptor.java
BeansDtdResolv er.java
AnonInnerLength
AbstractMessageSource.jav a
AbstractDependency InjectionSpringContextTests.java
toxicity chart
TomcatInstrumentableClassLoader.java
LocalContainerEntity ManagerFactoryBean.java
ResourceEntity Resolver.java
RedirectView.jav a
HtmlCharacterEntityReferences.java
AbstractPathMapHandlerMapping.jav a
AspectJPrecedenceComparator.java
ResourceServ let.java
Adv isedSupport.jav a
EhCacheFactory Bean.java
CustomCollectionEditor.java
CommonsMultipartFile.jav a
OpenEntity ManagerInViewFilter.jav a
TopLinkInterceptor.jav a
MethodInv okingJobDetailFactoryBean.java
Def aultNamespaceHandlerResolver.java
XmlValidationModeDetector.jav a
GenericFilterBean.jav a
ParameterNumber MissingSwitchDefault TreeWalker
HessianServ iceExporter.java
Property AccessorUtils.java
InstantiationModelAwarePointcutAdv isorImpl.java
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
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
symmetry
fluidity
CodeCrawler
www.inf.unisi.ch/faculty/lanza/codecrawler.html
CodeCrawler
CodeCrawler
academic graphical metrics tool
language independent
snapshot image
# classes
show/hide
package content
polymetric views
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
http://www.inf.unisi.ch/phd/wettel/codecity.html
CodeCity
integrated environment for software analysis
inspired by CodeCity
information radiators
single dimensions
compelling evidence
cool!
ThoughtWorks
?’s
please fill out the session evaluations
samples at github.com/nealford
ThoughtWorks
This work is licensed under the Creative Commons nford@thoughtworks.com
Attribution-Share Alike 3.0 License. 3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
http://creativecommons.org/licenses/by-sa/3.0/us/ blog: memeagora.blogspot.com
twitter: neal4d