You are on page 1of 10

On the Definition of Dynamic Software Measures

Luigi Lavazza, Sandro Morasca, Davide Taibi, Davide Tosi


Dipartimento di Scienze Teoriche e Applicate
Università degli Studi dell’Insubria
Via Mazzini 5, I-21100, Varese, Italy
{luigi.lavazza, sandro.morasca, davide.taibi, davide.tosi}@uninsubria.it

ABSTRACT module A has fewer static connections with the rest of the
The quantification of several software attributes (e.g., size, system than module B does, but that module A at run-time
complexity, cohesion, coupling) is usually carried out in a interacts with the rest of the system much more frequently
static fashion, and several hundreds of measures have been than B does. So, B may be considered to have a higher cou-
defined to this end. However, static measurement may only pling than A from a static perspective, while the converse
be an approximation for the measurement of these attributes may be true from a dynamic point of view. When predicting
during software use. The paper proposes a theoretical frame- the number of faults found due to integration problems, the
work based on Axiomatic Approaches for the definition of dynamic interactions between classes may be more relevant
sensible dynamic software measures that can dynamically than the static ones.
capture these attributes. Dynamic measures based on this As another example, static size measurement does not
framework are defined for dynamically quantifying size and capture the difference between heavily used and lightly used
coupling. In this paper, we also compare dynamic measures software code and may even take into account dead code.
of size and coupling against well-known static measures by Routine A may be longer than another routine B, but it
correlating them with fault-pronenesses of four case studies. may turn out that fewer lines of code are executed in A
than in B at run-time. Again, when estimating the num-
ber of faults found in a routine, dynamic size may be more
Categories and Subject Descriptors relevant than static size, as one may reasonably hypothesize
H.4 [Information Systems Applications]: Miscellaneous; that the number of faults found increases with the number
D.2.8 [Software Engineering]: Metrics—complexity mea- of lines of code exercised, rather than with the sheer number
sures, performance measures of lines of code.
Thus, it should be investigated whether dynamic measures
may be used alongside static measures in the assessment of
General Terms some software quality of interest or even if dynamic mea-
Measurement sures may be more useful than static ones. The distinction
between static and dynamic internal software measures par-
Keywords allels, from a practical point of view, the distinction between
static and dynamic analysis in software verification and val-
Dynamic measures, dynamic coupling, dynamic size, code idation. Both kinds of analysis may be useful when look-
coverage ing for software faults or when assessing some nonfunctional
properties, like maintainability, performance, or usability.
1. INTRODUCTION The definition and use of a new measure for an internal
The vast majority of the measures for internal software software attribute entails two kinds of validation.
attributes (e.g., structural size, structural complexity, cohe- • Theoretical validation. We need to make sure that the
sion, coupling) have been defined in a static way. However, new measure is adequate for quantifying the software
the dynamic aspects of these attributes still remain to be attribute it is supposed to measure, so its values can
largely investigated. For instance, just statically looking at be given a sensible interpretation. This activity can
the potential interactions between a software module and be carried out by using one of the available methods
the rest of a software system may not tell the entire story, used in the Software Measurement literature, namely
when assessing the coupling of the module. Suppose that Measurement Theory. [8, 13] or Axiomatic Approaches
[15, 6, 9].
• Empirical validation. It is necessary to check whether
Permission to make digital or hard copies of all or part of this work for the new measure is practically useful, by showing that
personal or classroom use is granted without fee provided that copies are it is correlated to some variable of industrial interest.
not made or distributed for profit or commercial advantage and that copies
bear this notice and the full citation on the first page. To copy otherwise, to
This activity can be carried out via empirical studies.
republish, to post on servers or to redistribute to lists, requires prior specific However, in the Software Measurement literature, mea-
permission and/or a fee.
ESEM’12, September 19–20, 2012, Lund, Sweden. sures have often been defined without undergoing a theo-
Copyright 2012 ACM 978-1-4503-1056-7/12/09 ...$10.00. retical or an empirical validation. So, there exist literally

39
thousands of measures for which there is no assessment as
to whether they actually measure what they are supposed
to measure or whether they are really useful. The end result
is that the vast majority of measures has not survived the
definition phase.
The contribution of this paper is therefore twofold, as we
define measures for dynamic software attributes and address
both kinds of validation.

• First, we introduce a framework that can be used for


the definition of sensible measures for dynamic soft-
ware attributes, based on Axiomatic Approaches [15,
6, 9]. As such, each dynamic software attribute may
be associated with a set of necessary properties for
the measures that purport to measure that attribute.
These properties can guide software measurers in defin-
ing new measures for dynamic software attributes and Figure 1: A UML-like Class Diagram
assess the adequacy of existing ones. We have cho-
sen size and coupling due to their importance in soft- Definition 1. System. A system S is a pair S =< E, R >,
ware development. Also, size allows us to investigate where
dynamic attributes for software modules in isolation,
regardless of the existence of other modules, and cou- • E represents the set of elements of S
pling allows us to investigate dynamic attributes for
• R ∈ N E×E×T
modules related to other modules in a software sys-
tem. The measures we define for dynamic size and where T is a finite set of types of relationships (N is the set
coupling comply with the properties we proposed. of natural numbers, including 0).

• Second, we have also applied these measures to a few Specifically, << a, b, t >, n >∈ R associates < a, b, t >,
software systems, to carry out an empirical investiga- i.e., a typed relationship between elements a and b, with
tion on whether these measures may be useful in prac- a natural number n, which describes how many times the
tice for estimating fault proneness and compare their typed relationship < a, b, t > occurs in the system.
usefulness with static measures. Our results show that This general representation may be adapted to different
some dynamic measures can estimate fault proneness application cases. For instance, system elements (i.e., the
better than traditional static measures. nodes of the graph) may denote code statements, methods,
classes, etc. The existence of a multiset of typed relation-
ships associated with each arc of the graph allows one to
The remainder of the paper is organized as follows. Sec-
model different kinds of interactions that may exist between
tion 2 summarizes the basic concepts and notation used
system elements. For instance, suppose that a system ele-
throughout the paper, which were introduced in previous
ment represents an OO class. Two OO classes may be linked
work about static attribute measurement. Section 3 intro-
by method calls or by variable uses at run-time, so differ-
duces dynamic aspects needed in the modeling of dynamic
ent kinds of relationships may be needed. Also, each type
attribute measurement, via the notions of execution trace
of relationship associated with an arc may have a different
and its underlying module. Section 4 illustrates our pro-
cardinality. For instance, two OO classes may be linked by
posed approach for the quantification of two specific dy-
5 variable uses and 20 method calls.
namic software attributes: size and coupling. In Section
Figure 1 shows a system, in which we have used capital
5, we define a few dynamic measures for size and coupling
letters to denote elements and lowercase letters to denote
and we show that they comply with the properties required
relationships. For simplicity, all relationships in the graph
for dynamic size and coupling measures proposed in Section
have the same type.
4. Section 6 provides examples of use of the measures de-
In what follows, the same symbol (e.g., ∪ for union) may
fined in Section 5. Related work is concisely reviewed in
denote an operation between sets when sets of elements are
Section 7, both on coverage measures and measures that
involved, or an operation between multisets when multisets
have been defined in the literature for various internal soft-
of typed relationships are involved. Even though these oper-
ware attributes. Conclusions and an outline for future work
ations are different, no confusion will arise because there will
are in Section 8.
never be an operation whose operands are a set of elements
and a multiset of typed relationships.
2. STATIC ATTRIBUTES: BASIC CONCEPTS Some software attributes require that parts of a system
AND NOTATION be identified. For instance, coupling may be defined for a
specific part of the system (e.g., a class or a package) or an
Here, we summarize the basic concepts and notation used entire system. These parts of a system are actually subsys-
in [9] for the Axiomatic Approaches for static attributes, tems that we call modules.
as they are the basis for the proposal of this paper too.
We basically view a system as a multigraph, where each Definition 2. Module. Given a system S =< E, R >, a
arc is associated with a multiset of relationships, and each module m =< Em , Rm > is a system such that Em ⊆ E ∧
relationship has a type. Rm ⊆ R.

40
Thus, for maximum generality and simplicity, a module is machine execution of software code, the inspection of a soft-
simply a subsystem, with no additional characteristics (e.g., ware artifact is a dynamic activity for the software inspector
an interface). that examines the software code (or any software artifact).
Given a module m of a system S =< E, R >, the multiset Any subsystem is a module, based on the definitions of Sec-
of those relationships that involve one element within m and tion 2, so we say that a module is executed in a dynamic
one element outside m is called the set of outer relationships activity.
of m and is denoted as OuterR(m), with OuterR(m) ⊆ R. We assume that, during an execution, the elements and
In Figure 1, UML-like packages 1 m1 , m2 , m3 , m4 , m5 , m6 , relationships of a system are exercised in a sequence, which
may be interpreted as modules. For notational convenience, we now formalize in the notion of execution trace.
it will be implied in the remainder of the paper that the set
of elements and the multiset of relationships of a system or Definition 3. Execution Trace. Given a system S =<
a module have the same subscript as the system or module, E, R > and a finite nonnegative integer number n, an exe-
unless otherwise explicitly specified. For instance, it will be cution trace tr is defined as follows:
implied that m1 has the set of elements E1 and the multiset
of relationships R1 . If no subscript appears in the name • if n > 0, tr is a function
of the system or module, then no subscript appears in the tr : 1..n → E ∪ R
name of its set of elements and multiset of relationships.
We now define an algebra for modules, based on set and that associates a system element or relationship with
typed multiset operations. any index value i ∈ [1..n], in such a way that, if tr(i)
Inclusion. Module m1 is said to be included in module is a relationship, then tr(i − 1) is the start element
m2 (notation: m1 ⊆ m2 ) if E1 ⊆ E2 ∧ R1 ⊆ R2 . In Figure of relationship tr(i) and tr(i + 1) is the end element
1, m5 ⊆ m4 . of relationship tr(i); throughout the paper, such an
Union. The union of modules m1 and m2 (notation: m1 ∪ execution trace is denoted either by its name tr or by
m2 ) is the module < E1 ∪ E2 , R1 ∪ R2 >. In Figure 1, the ordered sequence of its values;
m1 = m2 ∪ m3 .
• if n = 0, tr is the empty trace, which is denoted
Intersection. The intersection of modules m1 and m2
throughout the paper as .
(notation: m1 ∩ m2 ) is the module < E1 ∩ E2 , R1 ∩ R2 >. In
Figure 1, m2 ∩ m3 is the module whose elements are classes For notational convenience, we denote
C and D and whose relationships are < i, 1 > and < h, 1 >.
Empty module. Module < ,  > (denoted by ) is • the length n of execution trace tr as |tr|
the empty module.
• the set of elements appearing as components of an exe-
Disjoint modules. Modules m1 and m2 are said to be
cution trace tr as Etr = {e ∈ E|∃i ∈ [1..|tr|]tr(i) = e}
disjoint if m1 ∩m2 = . In Figure 1, m3 and m6 are disjoint.
Unconnected modules. Two disjoint modules m1 and • the set of component relationships of an execution trace
m2 of a system are said to be unconnected if OuterR(m1 ) ∩ tr as Rtr = {r ∈ E|∃i ∈ [1..|tr|]tr(i) = r}.
OuterR(m2 ) = . In Figure 1, m4 and m6 are unconnected,
while m3 and m6 are not unconnected. For instance, in the system of Figure 1
Sets of axioms have been introduced based on these defini-
tions. Each set of axioms describes the properties expected tr =< A, a, C, i, D, j, B, C, e, J, f, D,
for the measures related to a specific software attribute, e.g., B, x, H, q, G, A, l, B, y, G, L, s, K >
structural size, structural complexity, cohesion, coupling [6,
9]. is an execution trace (Formula 1).
Note that, based on the definition, a relationship may
be included in an execution trace only if it is immediately
3. EXECUTION TRACES AND DYNAMIC preceded in the trace by its start element, and, whenever a
MODULES relationship is included in the trace, it is followed by its end
element. A similar requirement does not apply to elements,
Section 2 introduced the basic concepts used for the def-
though. An element may not necessarily be immediately
inition of static measures. In this section, we introduce the
preceded by a transition in an execution trace, i.e., several
concepts related to the dynamic aspects of systems and mod-
nodes may be contiguously found in an execution trace. For
ules in such a way that we can introduce sets of axioms for
instance, a software inspector may very well sequentially
specific dynamic software attributes (see Section 4) in a way
inspect a number of software classes in isolation without
that is consistent with the axiom sets for static software at-
looking at the relationships that may exist between them.
tributes of [9].
Another implication of the definition of execution trace is
In the context of a system, the dynamic view identifies a
that there the first component of an execution trace is always
specific part of the entire system, i.e., a subsystem that we
an element, if the execution trace is not empty.
say is executed in a dynamic activity. We say that a part of
Given a module m and an execution sequence tr, some of
a system is “executed” to encompass different activities like
the components of tr may belong to m, while others may
running some executable artifact such as software code and
not. We introduce the notion of dynamic module of a static
the inspection of some artifact. Even though it is usually
module under an execution trace, to identify the part of the
classified as “static analysis” because it does not involve the
module that is involved in the execution trace.
1
Note that our definition of “module” is more general than
the definition of packages in UML, which may not share Definition 4. Dynamic Module of a Module under an Ex-
classes. ecution Trace. The dynamic module of a static module

41
either tr1 or tr2 in such a way that ∀i ∈ [1..|tr1 |]tr12 (in(i)) =
tr1 (i), ∀i ∈ [|tr1 | + 1..|tr1 | + |tr2 |]tr12 (in(i)) = tr2 (i), and
∀k ∈ [1..|tr1 | + |tr2 |], ¬∃i ∈ [1..|tr1 |], j ∈ [|tr1 | + 1..|tr1 | +
|tr2 |](in(i) = in(j) ∧ tr1 (i) = tr2 (j)). As a consequence, tr1
and tr2 are subtraces of tr12 . Whenever the specific indexing
chosen is immaterial, we use the abbreviated notation tr12 =
tr1 ∪ tr2 . As an additional property, for any given indexing,
we have tr = tr ∪ , i.e., the empty execution trace is the
null element of this algebra of traces.
Note that, if a specific run-time execution of a software
system is modeled by an execution trace, the effect of a set of
run-time executions of the software system is still modeled
by an execution trace, obtained as the union of the execution
traces corresponding to the individual run-time executions.
For instance, < A, a, C, i, D, j, B, B, x, H, q, G, A, l, B, y, G >
∪ < C, e, J, f, D, L, s, K >= tr for trace tr of Formula (1).
Figure 2: Dynamic Modules Concatenation. Intuitively, the concatenation of traces
tr1 and tr2 is simply the trace obtained by adding trace tr2
at the end of trace tr1 .
m =< Em , Rm > under an execution sequence tr (nota- Formally, the concatenation of traces tr1 and tr2 is the
tion DynM odule(m, tr))is composed of all of the elements trace tr12 = tr1 · tr2 such that |tr12 | = |tr1 | + |tr2 | and
and relationships appearing in both m and tr, i.e., ∀i ∈ [1..|tr1 |]tr12 (i) = tr1 (i) and ∀i ∈ [|tr1 | + 1..|tr1 | +
DynM odule(m, tr) =< EDM , RDM >, where EDM = |tr2 |]tr12 (i + |tr1 |) = tr2 (i). So, a concatenation is a spe-
Em ∩ Etr and RDM = Rm ∩ Rtr The underlying module cial case of union with a specific indexing, in which the
m(tr) of an execution trace tr is composed of all of the ele- components of tr2 all appear in tr12 after the components
ments and relationships appearing in tr. of tr1 . This is the only operation in this algebra that is
not commutative, as we may very well have tr12 = tr1 ·
Also, an execution trace has an underlying static mod- tr2 = tr2 · tr1 = tr21 . For instance, < A, a, C, i, D, j, B, >
ule composed of all the elements and the relationships that · < C, e, J, f, D, B, x, H, q, G, A, l, B, y, G, L, s, K >= tr for
appear in the execution trace. trace tr of Formula (1).
Intersection. Intuitively, the intersection of traces tr1
Definition 5. Underlying Module of an Execution Trace.
and tr2 is the longest trace that is included in both tr1 and
The underlying module m(tr) of an execution trace tr is
tr2 .
composed of all of the elements and relationships appearing
Formally, the intersection of traces tr1 and tr2 is the max-
in tr.
imal subtrace tr12 (notation: tr12 = tr1 ∩ tr2 ) such that
tr12 ⊆ tr1 ∧ tr12 ⊆ tr2 . Specifically, tr12 is maximal in the
For instance, Figure 2 shows the entire underlying module 
sense that there does not exist another trace tr12 such that
m(tr) of the execution trace tr of Formula (1). The dynamic   
tr12 ⊆ tr1 ∧ tr12 ⊆ tr2 and tr12 ⊆ tr12 . As a consequence,
module of module m1 in Figure 2 under execution trace tr
the intersection of any trace with the empty trace is the
of Formula (1) is the portion of Figure 2 strictly contained
empty trace . For instance, < A, a, C, i, D, j, B, C, e, J >
within the border of module m1 .
∩ < C, e, J, f, D, B, x, H, q, G, A, l, B, y, G >=< C, e, J >
Like with modules, we now introduce an algebra that can
for trace tr of Formula (1).
be used to work with execution traces. We introduce the
Disjoint traces. Intuitively, two traces are disjoint if
operations of that algebra intuitively and formally.
their intersection is empty.
Inclusion. Intuitively, an execution trace tr1 is included
Formally, traces tr1 and tr2 are said to be disjoint if tr1 ∩
in execution trace tr2 if it is possible to obtain tr1 by elimi-
tr2 = . For instance, < A, a, C, i, D, j, B > ∩ < I, c, J >=
nating elements of tr2 .
.
Formally, execution trace tr1 is said to be included in exe-
Unconnected traces. Intuitively, two disjoint traces tr1
cution trace tr2 (notation: tr1 ⊆ tr2 ) if ∀i, j ∈ 1..|tr1 |, ∃s, t ∈
and tr2 are unconnected if their underlying modules are also
1..|tr2 |(i < j ∧ s < t ∧ tr1 (i) = tr2 (s) ∧ tr1 (j) = tr2 (t)). Exe-
unconnected.
cution trace tr1 ⊆ tr2 is also said to be a subtrace of execu-
Two disjoint traces tr1 and tr2 of a system are said to be
tion trace tr2 . As a consequence, given any trace tr,  ⊆ tr,
unconnected if OuterR(m(tr1 ))∩OuterR(m(tr2 )) = . For
i.e., the empty trace is included in all other traces. For in-
instance, < A, a, C, i, D, j, B > ∩ < H, q, G >= .
stance, < C, i, D, j, B, C, e, J, H, q, G, A, l, B, y, G >⊆ tr for
The algebra of traces and the algebra of their underlying
trace tr of Formula (1).
modules are related, as we now show. Suppose that m is
Union. Intuitively, the union of two traces tr1 and tr2
any module of a system S.
combines those two traces by interleaving the elements of
tr1 and tr2 in a specified way. Inclusion: tr1 ⊆ tr2 ⇒ DynM odule(m, tr1 )
Formally, the union of traces tr1 and tr2 according to ⊆ DynM odule(m, tr2 ).
indexing in (i.e., the function that specifies how the two
Union: ∀in, tr12 = tr1 ∪in tr2 ⇒ DynM odule(m, tr12 ) =
traces are to be interleaved) is a trace tr12 (notation: tr12 =
DynM odule(m, tr1 ) ∪ DynM odule(m, tr2 ).
tr1 ∪in tr2 ) such that the indexing schema in is a surjective
function in : [1..|tr1 | + |tr2 |] → [1..n] for some integer value Intersection: tr12 = tr1 ∩ tr2 ⇒ DynM odule(m, tr12 ) =
of n that provides an index in tr12 for each component of DynM odule(m, tr1 ) ∩ DynM odule(m, tr2 ).

42
Disjoint traces tr1 ∩ tr2 =  ⇒ DynM odule(m, tr1) ∩ 4.2 Dynamic Coupling
DynM odule(m, tr2 ) =  Dynamic coupling is about the amount of relationships
between the elements of the dynamic module (of a mod-
4. AN AXIOMATIC APPROACH FOR TWO ule under an execution trace) and the elements of the other
dynamic modules under the same execution trace. We de-
DYNAMIC SOFTWARE ATTRIBUTES: note a dynamic coupling measure as for a given module m
SIZE AND COUPLING under execution trace tr as DynCoupling(m, tr), to denote
Here, we focus on dynamic size and coupling, by provid- the dependence of the dynamic coupling of module m on the
ing definitions for what we believe are necessary properties specific execution trace tr.
for their measures. Therefore, we provide an axiom set for
dynamic size and an axiom set for dynamic coupling. It can Dynamic Coupling Axiom 1. Monotonicity.
be shown that these two axiom sets are consistent with the Adding a new relationship to a module m1 or to its set of
necessary properties for static size and coupling of [9]. outer relationships OuterR(m1 ) does not decrease its dy-
namic coupling if the added relationship is added to an ex-
4.1 Dynamic Size ecution trace. So, if m2 is a module such that E2 = E1 and
Dynamic size is based on the multisets of elements appear- tr1 ⊆ tr2 we have
ing in an execution trace of a module, as described by the
following axioms. We denote a dynamic size measure for a OuterR(m1 ) ⊆ OuterR(m2 ) ∧ R1 ⊆ R2 ∧ tr1 ⊆ tr2 ⇒
given module m under execution trace tr as DynSize(m, tr), DynCoupling(m1 , tr1 ) ≤ DynCoupling(m2 , tr)
to denote the dependence of the dynamic size of module m
on the specific execution trace tr. A module with no outer relationships has zero dynamic
First, the dynamic size DynSize(m, tr) of module m com- coupling under all execution traces, regardless of its internal
posed of two possibly overlapping modules, under execution relationships.
trace tr, is not greater than the sum of the dynamic sizes of
the two modules, each taken in isolation, under tr.
Dynamic Coupling Axiom 2. Null Value. The coupling of
Dynamic Size Axiom 1. Union of Modules. Suppose we a module with no outer relationships is null under all exe-
have two modules m1 and m2 and an execution trace tr. cution traces.
The dynamic size of m = m1 ∪ m2 under tr is never greater
than the sum of the dynamic sizes of m1 and m2 under tr, When two modules are merged in a single module, the
i.e., relationships that connect them to each other become inter-
nal ones, so the dynamic coupling of the new module is not
m = m1 ∪ m2 ⇒ DynSize(m, tr) ≤ higher than the sum of the dynamic couplings of the two
DynSize(m1 , tr) + DynSize(m2 , tr) modules.

For instance, DynSize(m2 ∪ m3 , tr) ≤ DynSize(m2 , tr) + Dynamic Coupling Axiom 3. Merging of Modules. The
DynSize(m3 , tr) in Figure 2. dynamic coupling of the union of two dynamic modules m1
The basic idea is that the intersection of the two dynamic and m2 under any specific execution trace tr is not greater
modules may or may not be taken into account twice when than the sum of the dynamic couplings of the two modules
m is executed under tr. However, when the two dynamic under tr
modules are disjoint, dynamic size is additive.
∀tr(DynCoupling(m1 ∪ m2 , tr) ≤
Dynamic Size Axiom 2. Dynamic Size Additivity. Sup- DynCoupling(m1 , tr) + Coupling(m2 , tr))
pose we have two disjoint modules m1 and m2 and an exe-
cution trace tr. The dynamic size of m = m1 ∪ m2 under
tr is equal to the sum of the dynamic sizes of m1 and m2 Thus, DynCoupling(m2 ∪m3 , tr) ≤ DynCoupling(m2 , tr)
under tr, i.e., + Coupling(m3 , tr) in Figure 2.
Coupling is additive for a system composed of two uncon-
m = m1 ∪ m2 ⇒ DynSize(m, tr) = nected modules.
DynSize(m1 , tr) + DynSize(m2 , tr)
Dynamic Coupling Axiom 4. Unconnected Modules. The
Thus, DynSize(m2 ∪ m4 , tr) = dynamic coupling of the union of two unconnected dynamic
DynSize(m2 , tr) + DynSize(m4 , tr) in Figure 2. modules under an execution trace tr is equal to the sum of
Several properties can be derived from these axioms. We their couplings.
now list a few.
OuterR(DynM odule(m1 , tr)) ∩ OuterR(DynM odule(m2 , tr))
1. The dynamic size of the empty module under any ex- =  ⇒ ∀tr(DynCoupling(m1 ∪ m2 , tr) = DynCoupling(m1 , tr)
ecution trace is zero. +DynCoupling(m2 , tr))
2. The dynamic size of a module under any execution
trace is nonnegative. Thus, DynCoupling(m4 ∪m6 , tr) = DynCoupling(m4 , tr)
+ Coupling(m6 , tr) in Figure 2.
3. Adding elements to a module cannot decrease its dy- As a derived property, the dynamic coupling of a module
namic size under any execution trace. under any execution trace is nonnegative.

43
5. DYNAMIC MEASURES FOR SIZE AND and initialized. The proof that T ypes is is a size measure is
COUPLING analogous to the previous proofs.
We now provide a few examples of dynamic measures for 5.2 Dynamic Coupling Measures
size and coupling, which we use in the experiments of Section We collected three dynamic coupling measures, defined in
6. Thus, an execution trace is related to a specific execution [4].
or a set of executions of a module. Here, we show that these Distinct method invocations: The count, within a
measures are dynamic size and coupling measures according runtime session, of the total number of distinct methods
to the axiom sets of Section 4. invoked by each method in each object. By modeling each
5.1 Dynamic Size Measures method as a module, each statement in the module as an
element, and each control flow transfer within the method
Blocks: The number of blocks (i.e., the sequence of byte- or to another method, the proof that Distinct method in-
code instructions without any jumps or jump targets) ex- vocations is a dynamic coupling measure according to the
ercised by the test suite. A block is considered as exer- axiom set of Section 4.2, can be carried out as follows: As
cised when its last instruction has been executed. A module for Axiom 1, adding a new invocation within the class or to
in this case is statically modeled as a block control-flow,
its set of invocations of methods of other classes does not de-
in which bytecode blocks are represented by the nodes of
crease its dynamic coupling if the added invocation is added
the graph (i.e., the elements of the system) and control- to any execution trace. A class that is not linked to any
flow transfers between blocks are represented by the arcs other classes has no direct method invocations, so Distinct
of the graph (i.e., the relationships of the system). We method invocations is null and Axiom 2 is satisfied. Let us
now show that Blocks is a size measure according to the
now examine Axiom 3. If two classes c1 and c2 are merged
axiom set in Section 4.1. First, given an execution trace
into a single class c, the invocations of methods between c1
tr and the corresponding DynM odule(m, tr), let us take
and c2 are no longer counted as contributing to the coupling
two execution traces tr1 and tr2 such that tr = tr1 ∪ tr2 of c towards the rest of the system in any execution trace,
and, therefore DynM odule(m, tr) = DynM odule(m, tr1 ) ∪ so the dynamic coupling of c is not greater than the sum of
DynM odule(m, tr2 ). The number of blocks in DynM odule(m, tr) the dynamic couplings of c and c . Finally, if, in a specific
1 2
is clearly never greater than the sum of the numbers of blocks
execution there are no methods invoked between c1 and c2 ,
in DynM odule(m, tr1 ) and DynM odule(m, tr2 ), since
the number of distinct method invocations of c is the sum of
DynM odule(m, tr1 ) and DynM odule(m, tr2 ) may have some the distinct method invocations of c1 and c2 , and Axiom 4 is
blocks in common. So, Axiom 1 is satisfied. Likewise, if satisfied. So, Distinct method invocations is a coupling
modules DynM odule(m, tr1 ) and DynM odule(m, tr2 ) are measure according to the axiom set of Section 4.2.
disjoint, no overlap of blocks exist and the number of blocks Dynamic messages: The count, within a runtime ses-
in DynM odule(m, tr) is equal to the sum of the numbers
sion, of the total number of distinct messages sent from one
of blocks in DynM odule(m, tr1 ) and DynM odule(m, tr2 ).
object of a class to other objects. Two messages are not
So, Axiom 2 is satisfied too and Blocks is a size measure distinct if their source and target classes, the method in-
according to the axiom set in Section 4.1. voked in the target class, and the statement from which it
Instructions: The number of bytecode instructions ex- is invoked in the source class are the same. The proof that
ercised. A module in this case is statically modeled as a Dynamic messages is a dynamic coupling measure can be
control-flow graph, in which bytecode instructions are rep-
carried out along the lines as the previous proof.
resented by the nodes of the graph and control-flow transfers
Distinct classes: The count of the distinct number of
between bytecode instructions are represented by the arcs of classes that a method uses within a runtime session. Here,
the graph. We can prove that Instructions is a size measure we can use the same modeling as for Distinct method in-
in much the same way as we proved that N umberOf Blocks vocations and we can show that Distinct classes is a
is a size measure according to the axiom set in Section 4.1, dynamic coupling measure in a similar way.
by replacing blocks with instructions.
SLOC: The number of Java source lines of code exercised.
A module in this case is statically modeled as a control-flow
6. EXPERIMENTING
graph, in which source lines of code are represented by the DYNAMIC MEASURES
nodes of the graph and control-flow transfers between source This section presents the results of four case studies we
lines of code are represented by the arcs of the graph. We can conducted to provide a first empirical validation of the dy-
prove that SLOC is a size measure in much the same way namic measures we discussed above. Firstly, we present the
as we proved that Blocks and Instructions size measures methodology we follow, the environmental setup and the ob-
according to the axiom set in Section 4.1. jectives of this experimentation. Secondly, we provide and
Methods: The number of distinct methods exercised. A we discuss quantitative results about size and coupling dy-
method is considered as exercised if at least one statement namic measures when compared against well-known static
of the method has been executed. A module is statically measures.
modeled as a sheer sequence of methods declared in a class,
so methods are represented by the nodes of the graph. The 6.1 Methodology
node representing a method is linked to the next node (which We selected four open-source Java projects, specifically
represents the next method in the sequence) by an arc. The HttpUnit v1.7, Jakarta Commons IO v1.4, Log4J v1.2.16
proof that M ethods is a size measure is analogous to the and PMD v4.2.5 to evaluate dynamic size and coupling as-
previous proofs. pects.
Types: The number of distinct Java type exercised. A HttpUnit is a tool to emulate the relevant portions of
Java type is considered as exercised if it has been loaded browser behavior and allows Java test code to examine re-

44
turned pages either as text, an XML DOM, or containers of We used the AJDT Eclipse plugin (based on the AspectJ
forms, tables, and links. The considered HttpUnit release runtime library) [1] to define an aspect (i.e., a stand-alone
consists of 19810 lines of code (SLOC) in 10 source pack- module that contains cross-cutting concerns), a pointcut
ages, 286 classes and 3764 methods (after removing classes (i.e., a set of join points that are able to capture well-defined
related to test cases and methods used to profile the source moments in the execution of a program, like method call, ob-
code of the application). In our experiments, we used all the ject instantiation, or variable access), and an advice (i.e., the
10 packages contained in the src folder of HttpUnit. How- code to run before, after, or around the specified join point)
ever, two of them were excluded from the final computation able to trace all the calling classes and methods, the called
due to the lack of test cases. classes and methods, and the statements from which calls
Jakarta Commons IO is a library of utilities (such as originate. The pseudo code of the most relevant part of the
Input, Output, Filters, Comparators and Monitor classes) defined aspect looks like as follows:
to assist with developing IO functionality. The considered
Commons IO release consists of 2931 lines of code (SLOC) in public aspect DynamicCouplingAspect {
pointcut executionTree():
5 source packages, 74 classes and 422 methods (after remov- within(TestClass_a) ||
ing classes related to test cases and methods used to profile ... ...
the source code of the application). As for this experiment, within(TestClass_n) &&
we collected data for all the 5 packages contained in the src call (* *(..));
folder of Jakarta. Object around(): executionTree() {
Log4J is a package to enable logging of an application print(thisJointPointStaticPart.getSignature);
print(thisJointPointStaticPart.getDeclaringType);
context at runtime without modifying the application bi- ... ...
nary. The considered Log4J release consists of 11774 lines }
of code (SLOC) in 22 source packages, 181 classes and 1032 ... ...
methods (after removing classes related to test cases and }
methods used to profile the source code of the application).
As for this experiment, we collected data only for the 10 As for collecting bugs data, we manually surfed the bug
packages contained in the src folder of Log4J equipped with tracker system of each case study to identify all the valid
test cases. bugs (i.e., open, closed, confirmed with the exception of un-
PMD is a library to scan Java applications and look for confirmed bugs) that refer to the version of the target ap-
possible bugs, dead / suboptimal / duplicate code, and over- plication. Each identified bug has been manually classified
complicated expressions. The considered PMD release con- in the package it belongs to. To avoid biases, we try to
sists of 49162 lines of code (SLOC) in 17 source packages, reduce subjectivity in the manual analysis of each bug as
642 classes and 4439 methods (after removing classes related much as possible, and we also try to replicate step by step
to test cases and methods used to profile the source code of the methodology we used for surfing each bug tracker. In
the application). As for this experiment, we collected data any case, we are aware that bugs data are often non ho-
for all the 17 packages contained in the src folder of PMD. mogeneous due to different policies of each community in
However, one package was excluded from the final compu- collecting, reporting and tracking bugs. For instance, the
tation due to the lack of test cases. Jakarta Commons IO project uses the JIRA bug tracker,
We focused on collecting different types of data referring HttpUnit and PMD use the Sourceforge bug tracker, while
to the static, dynamic size, dynamic coupling measures, and Log4J uses the Bugzilla bug tracker system. For each pack-
number of bugs for each case study at a package granularity. age, we computed the
We collected the following static measures (by means of the 6.2 Objectives and Results
Metrics plugin [3] v1.3.8): Number of Methods, Number
of Classes, Afferent Coupling (Ca), Efferent Coupling (Ce), With these experiments, we are interested in collecting
Package Instability (i.e., Ce / (Ca+Ce)) , Coupling Between data to show:
Objects (CBO max and mean), and McCabe Complexity Q1: whether there is a correlation between dynamic size
(max and mean.) and coupling measures with some relevant static mea-
As for collecting dynamic size measures, we used the EclEmma sures;
Eclipse plugin [2]. EclEmma is a free Java code coverage
tool for Eclipse that does not require modifying the source Q2: whether dynamic measures are better than static mea-
code of the applications. We used the test cases provided sures in predicting some software quality aspects. In
along with each application to exercise the system of each this paper, we limited our experimentation in inves-
case study, and by means of EclEmma we are able to com- tigating the fault-proneness aspect, thus we used as
pute at run-time the measures we discussed in subsection dependent variable the number of bugs of each appli-
5.1. Specifically, we compute the percentage of blocks, in- cation. We correlated dynamic measures and static
structions, SLOCs, methods and types exercised by the test measures with these bug data, and we compared the
cases. computed coefficients of correlation to understand the
As for collecting the dynamic coupling measures (i.e., dy- ability that dynamic and static measures have in pre-
namic messages, distinct methods, and distinct classes), we dicting the fault-proneness of an application;
profiled each application by means of Aspect-Oriented Pro-
To answer question Q1 we used non parametric test, be-
gramming (AOP) and we exercised the system by means of
cause distributions are generally not normal.
each test suite. The test cases have been used to simulate
Table 1 reports the results of the Kendall’s and Spear-
the users’ interactions with the application in order to exer-
man’s tests applied to Log4J dynamic size measures with
cise as much functionalities of the application as possible.
all the seven static measures we listed above. We are not

45
Table 1: Correlation between static and dynamic size measures for Log4J (10 data points)
Blocks Instructions SLOC Methods Types
Num. Methods — tau = 0.511 — — —
rho = 0.661
Num. Classes tau = 0.688 tau = 0.777 tau = 0.733 — —
rho = 0.794 rho = 0.903 rho = 0.854
CBO max tau = 0.539 tau = 0.449 tau = 0.494 tau = 0.494 —
rho = 0.705 rho = 0.656 rho = 0.693 rho = 0.669

able to find any significant correlation for HttpUnit, PMD


and Jakarta. Contrariwise, we found several correlations for Table 4: Correlation between static and dynamic
Log4J (see Table 1 ). Due to the heterogeneity in the ob- coupling measures for Log4J (10 data points)
tained results, no general conclusions can be derived. Dynamic Distinct Distinct
Tables 2 to 4 report the results of the Kendall’s and Spear- Messages Methods Classes
man’s tests applied to HttpUnit, PMD and Log4J dynamic Num. tau = 0.556 tau = 0.644 tau = 0.629
coupling measures with all the seven static measures we Methods rho = 0.721 rho = 0.794 rho = 0.754
listed above, respectively. For the Jakarta project no sig- Num. tau = 0.644 tau = 0.556 tau = 0.539
nificant correlation could be found, but this is probably due Classes rho = 0.782 rho = 0.721 rho = 0.711
to the small number of available datapoints (5). As a matter Afferent tau = 0.540 — tau = 0.523
of fact, for Dynamic Messages vs. NumClasses and Distinct Coupling rho = 0.657 rho = 0.640
Methods vs. NumClasses fairly high values of Kendall’s tau Efferent tau = 0.540 tau = 0.540 tau = 0.523
and Spearman’s rho were found, but with p-value well above Coupling rho = 0.669 rho = 0.669 rho = 0.659
the chosen threshold (0.05). McCabe tau = 0.523 tau = 0.523 tau = 0.598
As for the correlations between static measures and dy- max rho = 0.689 rho = 0.665 rho = 0.731
namic coupling measures, we can weakly state that dynamic McCabe tau = 0.584 tau = 0.674 tau = 0.705
messages, distinct methods and distinct classes correlate well mean rho = 0.760 rho = 0.815 rho = 0.826
with the number of methods, number of classes, efferent cou-
pling, and McCabe (max) static measures (this can be de-
rived by intersecting the HttpUnit results with the Log4J • dependent variables representing defect density at the
results). These results are limited to HttpUnit and Log4J, package level: the absolute number of bugs (Num-
the only two projects that provide some correlations. Bugs); the relative number of bugs (NumRelBugs),
obtained as the ratio between the number of bugs of
a package and the total number of bugs of the appli-
Table 2: Correlation between static and dynamic cation; the number of bugs per LOC (BugsPerLOC);
coupling measures for HttpUnit (8 data points) the ratio between the number of bugs and the number
Dynamic Distinct Distinct of classes (NumBugs/NumClasses); the ratio between
Messages Methods Classes the number of bugs and the number of methods (Num-
Num. tau = 0.786 tau = 0.929 tau = 0.857 Bugs/NumMethods).
Methods rho = 0.905 rho = 0.976 rho = 0.929
Num. tau = 0.786 tau = 0.929 tau = 0.857 • independent variables representing all the seven static
Classes rho = 0.905 rho = 0.976 rho = 0.929 measures and the dynamic measures of size and cou-
Efferent rho = 0.762 rho = 0.810 rho = 0.786 pling.
Coupling We built both linear models and models obtained by ap-
CBO max — tau = 0.618 — plying OLS regression to log-log transformed data.
rho = 0.778 Not all the possible pairs of independent and dependent
Package tau = 0.643 tau = 0.643 tau = 0.714 variables provided statistically significant models. The sig-
Instability rho = 0.833 rho = 0.810 rho = 0.881 nificant models obtained via OLS regression after log-log
McCabe tau = 0.593 tau = 0.667 tau = 0.593 transformation are synthetically reported in Table 5.
max rho = 0.711 rho = 0.795 rho = 0.730 In Table 5 we have reported for completeness also the
models for Jakarta Commons IO, but we must remember
that such model is based on 5 data points only, therefore it
is not very reliable.
Table 3: Correlation between static and dynamic Table 5 shows that the number of distinct methods and
coupling measures for PMD (16 data points) distinct classes executed are the measures that in general
correlate better with the various measures of defects for most
Dynamic Distinct Distinct
projects, while static measures in general do not provide a
Messages Methods Classes
reliable indicator on fault-proneness of a project (e.g., static
CBO mean — rho = 0.538 —
measures provided heterogeneous results if comparing the
models of the four case studies).
To answer question Q2, we built models –via Ordinary We are aware that the quality of the found models depends
Least Squares (OLS) regression– involving strongly on the quality of the partial results computed by

46
Table 5: Independent variables of log-log models (R2 in parentheses)
Dep. Var. Indip. Var. (R2 )
HTTPunit Jakarta PMD Log4J
Distinct Methods(0.604) Distinct Methods(0.928) CBO max(0.466) Distinct Methods(0.738)
Distinct Classes(0.529) Distinct Classes(0.932) Distinct Classes(0.741)
Pack. Instability(0.564) McCabe max(0.545)
Num. Methods(0.887)
Num. Bugs
Afferent Coupling(0.637)
Efferent Coupling(0.817)
Instructions Perc.(0.529)
SLOC Perc.(0.493)
Afferent Coupling(0.665) Distinct Methods(0.928) Afferent Coupling(0.698) Distinct Methods(0.732)
Distinct Classes(0.932) Instructions Perc.(0.819) Distinct Classes(0.735)
Methods Perc.(0.757) McCabe max(0.542)
Num. Methods(0.883)
Num. rel. Bugs
Afferent Coupling(0.646)
Efferent Coupling(0.817)
Instructions Perc.(0.544)
SLOC Perc.(0.51)
Distinct Methods(0.895) Num. Methods(0.968)
Bugs per LOC
Distinct Classes(0.891) Blocks Perc.(0.604)
Num. Bugs / McCabe Max(0.869) Methods Perc.(0.772) Distinct Methods(0.816)
N.Classes Distinct Classes(0.906)
Num. Bugs / Instructions Perc.(0.517)
N.Methods

each intermediate tool, on the accuracy of each community cally simulating the behavior of the system and the coupling
in collecting and reporting bugs data, and on the number of measures defined in their work are not compliant with our
case studies and data points available. We are extending this axiomatic framework. In our work, we describe how to use
work by collecting new data (at a class granularity instead aspect-oriented programming to instrument the source code
of at the package granularity), to increase significantly the of the system and how to collect traces at runtime to com-
number of data points. pute dynamic size and coupling attributes.
In [4], a set of dynamic coupling measures has been defined
and validated against static size measures. We extended this
7. RELATED WORK work, by adding and formally defining, in an operational
Several works exist on the measurement of static prop- form, dynamic size measures, and we provide a set of ex-
erties for software systems. In addition to classical works periments with the aim of demonstrating the potentialities
that define static measures such as lines of code, cohesion, of dynamic measures. We also show, by means of four case
coupling and other measures [14], a lot of recent works for- studies, how AOP can actually support the computation of
mally define static attributes [10, 9, 6] for object-oriented dynamic measure.
systems, while other works empirically evaluate the correla- In [7], the authors propose a way to estimate dynamic
tion among static attributes with subjective aspects such as coupling metrics early in the software development lifecycle.
maintainability and trustworthiness of object-oriented open- They introduce the concept of ”pseudo dynamic metrics”,
source software systems [5]. which are static metrics adjusted to reflect the operational
Recently, the introduction of profiling and probing mech- profile of the expected software usage. They draw their ap-
anisms based on assertions, invariants, and aspects to mon- proach starting from the assumption that dynamic metrics
itor the dynamic behavior of software systems has shown can only be computed at an advanced stage of the software
how software systems often do not behave at run-time as ex- development, because they need additional code to be wrote
pected at design-time [12]. Static measures are not able to to detect dynamic behaviors. In our work, we demonstrated
detect misbehaviors and unexpected properties of the soft- how it is simple to define advices and pointcuts able to mon-
ware, thus they need to be complemented with measures itor at run-time the behavior of the software system. Of
that work at run-time. course, our approach needs the availability of external in-
Starting from these considerations, some dynamic mea- puts (such as test cases) that trigger and stimulate the sys-
sures have been defined in the literature. For example, Ya- tem. We think that these external inputs are early available
coub et al. define dynamic object-oriented coupling mea- because test cases are normally coded in parallel with the de-
sures based on executable Real-time Object Oriented Mod- velopment of the system, as software engineering guidelines
eling (ROOM) [16]. These models are a specialization of se- and best practices suggest.
quence diagrams that allow execution simulations of the soft- Other dynamic measures have been informally defined.
ware system, thus providing a way to calculate the number of For example, Munson et al. [11] obtained a sort of dynamic
messages sent between two distinct objects in a given ROOM complexity (they call ”relative complexity”) starting from
diagram. Unfortunately, the proposed approach works stati- the static complexity of a software component and its fre-

47
quency of execution. Our axiomatic framework for dynamic [5] V. D. Bianco, L. Lavazza, S. Morasca, D. Taibi, and
measures is open to new formal definitions. We are extend- D. Tosi. An investigation of the users perception of
ing this work by formally defining other dynamic measures OSS quality. In International Conference on Open
and the properties that characterize these measures. Source Systems (OSS), 2010.
In the research filed of software testing, a lot of work exists [6] L. C. Briand, S. Morasca, and V. R. Basili.
about how software systems are exercised at runtime by a Property-based software engineering measurement.
test suite. This field studies coverage criteria to understand IEEE Trans. Software Eng., 22(1):68–86, 1996.
how good and adequate is a test suite in exercising all the [7] R. Gunnalan, M. Shereshevsky, and H. H. Ammar.
criticisms of a software system. Several coverage and ade- Pseudo dynamic metrics [software metrics]. In
quacy criteria have been defined in the literature. In [17] a International Conference on Computer Systems and
comprehensive survey of these criteria is provided. For ex- Applications (AICCSA), page 117, 2005.
ample, the Statement Coverage criteria reports whether each [8] D. Krantz, R. Luce, P. Suppes, and A. Tversky.
executable statement of the system is encountered when exe- Foundations of measurement, volume 1: Additive and
cuting the test suite; the Condition Coverage criteria reports polynomial representations. Academic Press, New
the true or false outcome of each boolean sub-expression, York, 1971.
separated by logical-and and logical-or if they occur; the [9] S. Morasca. Refining the axiomatic definition of
Path Coverage criteria reports whether each of the possible internal software attributes. In Proceedings of the
paths in each function have been followed. Several other Second International Symposium on Empirical
criteria are available, and to the best of our knowledge, we Software Engineering and Measurement (ESEM),
think that these criteria should be investigated and adapted pages 188–197, 2008.
to collect dynamic software measures.
[10] S. Morasca. A probability-based approach for
measuring external attributes of software artifacts. In
8. CONCLUSIONS AND FUTURE WORK Proceedings of the Second International Symposium on
In this paper, we have proposed a framework for the defi- Empirical Software Engineering and Measurement
nition of sensible measures of dynamic internal software at- (ESEM), pages 44–55, 2009.
tributes. The framework is based on Axiomatic Approaches [11] J. C. Munson and T. M. Khoshgoftaar. Measuring
and is consistent with previous work about static measures dynamic program complexity. IEEE Software,
[9]. We have also provided examples to show how dynamic 9(6):48–55, 1992.
measures may be defined, collected, and used. [12] J. H. Perkins and M. D. Ernst. Efficient incremental
Future work will address several avenues of research, in- algorithms for dynamic detection of likely invariants.
cluding: In Proceedings of the International Symposium on
• definition of axiom sets for other dynamic attributes Foundations of Software Engineering (FSE), pages
like dynamic complexity and dynamic cohesion 23–32, 2004.
[13] F. Roberts. Measurement theory, with applications to
• definition of additional measures and refinement of ex- Decision Making, Utility and the Social Sciences.
isting ones according to the axiom sets defined Addison-Wesley, Boston, 1979.
[14] D. Stavrinoudis and M. N. Xenos. Comparing internal
• additional empirical studies (collecting data at the class
and external software quality measurements. In
granularity) to assess the practical usefulness of these
Knowledge-Based Software Engineering, Proceedings of
measures.
the Eighth Joint Conference on Knowledge-Based
Software Engineering, (JCKBSE), pages 115–124,
9. ACKNOWLEDGMENT 2008.
The research presented in this paper has been partially [15] E. J. Weyuker. Evaluating software complexity
funded by the IST project “QualiPSo,” funded by the EU in measures. IEEE Trans. Software Eng.,
the 6th FP (IST-034763); the FIRB project “ARTDECO,” 14(9):1357–1365, 1988.
sponsored by the Italian Ministry of Education and Uni- [16] S. M. Yacoub, H. H. Ammar, and T. Robinson.
versity; and the projects “Elementi metodologici per la de- Dynamic metrics for object oriented designs. In IEEE
scrizione e lo sviluppo di sistemi software basati su modelli” International Software Metrics Symposium
and “La qualità nello sviluppo software,” funded by the Uni- (METRICS), pages 50–61, 1999.
versità degli Studi dell’Insubria. [17] H. Zhu, P. A. V. Hall, and J. H. R. May. Software unit
test coverage and adequacy. ACM Comput. Surv.,
10. REFERENCES 29(4):366–427, 1997.
[1] AJDT: AspectJ Development Tools. Web published:
www.eclipse.org/ajdt/. Accessed: March 2012.
[2] The EclEmma Eclipse Plugin. Web published:
www.eclemma.org. Accessed: March 2012.
[3] Metrics. Web published:
http://metrics2.sourceforge.net/. Accessed: March
2012.
[4] E. Arisholm, L. C. Briand, and A. Føyen. Dynamic
coupling measurement for object-oriented software.
IEEE Trans. Software Eng., 30(8):491–506, 2004.

48

You might also like