51
Software Metrics Software Engineering 2007 SourceKibitzer Anton Litvinenko

Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

Software MetricsSoftware Engineering 2007

SourceKibitzer

Anton Litvinenko

Page 2: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

2/5114.11.07

Software MetricsSourceKibitzer

SourceKibitzer

Page 3: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

3/5114.11.07

Software MetricsSourceKibitzer

Page 4: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

4/5114.11.07

Software MetricsSourceKibitzer

“You can’t control what you can’t measure”Tom DeMarco

“Controlling Software Projects”

Page 5: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

5/5114.11.07

Software MetricsSourceKibitzer

Measurement• Assignment of quantitative indications

to product's attributes– “Mapping from real world to numbers“–Preserves empirical relation

• Quantitative attribute – „objective“–Variety of magnitudes–Stand in relation to one another

• Not quantitative – „subjective“–Feelings, emotions

Page 6: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

6/5114.11.07

Software MetricsSourceKibitzer

Example

• Empirical relation–I am higher than Bill Gates

Page 7: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

7/5114.11.07

Software MetricsSourceKibitzer

Example

• Empirical relation–I am higher than Bill Gates

• Measurement–My height is 192cm–Bill's height is 178cm

Page 8: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

8/5114.11.07

Software MetricsSourceKibitzer

Metrics – quantitative representation of otherwise vague attributes

GOAL – IMPROVEMENT

Page 9: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

9/5114.11.07

Software MetricsSourceKibitzer

One-timer

• Contribution size–How much code developer has

contributed during the last week

• 29. Aug. 2007 – Anton's contribution was 600 lines of code– What this number tells us?

Page 10: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

10/5114.11.07

Software MetricsSourceKibitzer

Page 11: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

11/5114.11.07

Software MetricsSourceKibitzer

Iterative I

01.08.07 08.08.07 15.08.07 22.08.07 29.08.07 05.09.070

200

400

600

800

1000

1200

1400AntonTeam Avg

• Sequence of steps executed multiple times (periodic, cyclic)–not iterative as iterative development

Page 12: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

12/5114.11.07

Software MetricsSourceKibitzer

Iterative II

01.08.07 08.08.07 15.08.07 22.08.07 29.08.07 05.09.07 12.09.07 19.09.07 26.09.070

200

400

600

800

1000

1200

1400

1600

AntonTeam Avg

• Gave Anton one week off (12.09.2007)

Page 13: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

13/5114.11.07

Software MetricsSourceKibitzer

Applications of Metrics

• Project progress estimation –Product size, velocity, ...

• Evaluation of tools and methods–Growth of productivity and quality, ...

• Product quality evaluation–Quality of design and code, number of

bugs, ...

• Provide feedback to project team–Developer reputation, ...

Page 14: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

14/5114.11.07

Software MetricsSourceKibitzer

What software metrics do you know?

Page 15: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

15/5114.11.07

Software MetricsSourceKibitzer

Lines of Code• Product size – LOC, SLOC, CLOC, ...

Page 16: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

16/5114.11.07

Software MetricsSourceKibitzer

Lines of Code II

Page 17: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

17/5114.11.07

Software MetricsSourceKibitzer

Lines of Code III

• Accurate, easy to measure

• How to interpret ...–Empty lines–Comments–Several statements on one line

• Depends on the language• Doesn't respect complexity and

content

Page 18: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

18/5114.11.07

Software MetricsSourceKibitzer

Function Points• Product size• Use-Case evaluation

–Each use-case screened for:• External Input: add new purchase• External Output: monthly purchase breakdown• External Inquiries: view client data• Internal Logical Files: DB table with client data• External Interface Files: warehouse interface

• For each such concept –> complexity–Low, Average, High

• Number of F-points using formula

Page 19: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

19/5114.11.07

Software MetricsSourceKibitzer

Function Points II

Low Average High

External Input _ × 3 _ × 4 _ × 6External Output _ × 4 _ × 5 _ × 7External Inquiries _ × 3 _ × 4 _ × 6Internal Logical Files _ × 7 _ × 10 _ × 15External Interface Files _ × 10 _ × 15 _ × 25

Unweighted Number of F-points: Σ

Page 20: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

20/5114.11.07

Software MetricsSourceKibitzer

Function Points III: Example

• Ökonoom saab hallata ladu–Võimalus lisada uut kaupa–Võimalus eemaldada kaupa süsteemist–Võimalus muuta kauba hinda, kogust ja

nime

NB! Given example is simplified

Page 21: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

21/5114.11.07

Software MetricsSourceKibitzer

Function Points IV

• Independent of programming language

• Can be applied earlier in the project–No source code needed

• Complexity estimation is subjective–Not accurate

Page 22: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

22/5114.11.07

Software MetricsSourceKibitzer

Lines of Code and F-points

• Size and productivity estimation and evaluation

• Previous project–1337 F-points and 24 man-months

• New project–876 F-points –> … man-months

Page 23: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

23/5114.11.07

Software MetricsSourceKibitzer

McCabe’s Cyclomatic Complexity• Thomas McCabe, 1976• Measures complexity

–Number of linearly independent paths through a program (or method)

–Usually measured on the flow graph• V(G) = e – n + 2

– e – num of edges, n – num of vertices

• V(G) = d + 1– d – num of conditional statements

(if, for, throw(s), ...)

Page 24: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

24/5114.11.07

Software MetricsSourceKibitzer

McCabe’s Cyclomatic Complexity II

Page 25: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

25/5114.11.07

Software MetricsSourceKibitzer

McCabe’s Cyclomatic Complexity III2: System.out.println("----------");

4-5: System.out.println(c.getId() + " " + c.getFirstName());

8: System.out.println("\tNothing");

10: System.out.println("----------");

for (Client c : clients)

if (clients.size() == 0)

• e = 7• n = 6• V(G) = 3

Page 26: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

26/5114.11.07

Software MetricsSourceKibitzer

McCabe’s Cyclomatic Complexity IV• Comprehensibility

–V(G) >10 –> probability of bugs rises

• Relation to software testing–Lower bound for the number of paths

through method –Upper bound for the number of branches

in the method

• Doesn't respect other complexities–Data structure, data flows, interfaces

Page 27: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

27/5114.11.07

Software MetricsSourceKibitzer

Software Metric Classification

Measurement Subject

Page 28: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

28/5114.11.07

Software MetricsSourceKibitzer

Software Development Process

• Measuring the efficiency of process application

• Examples of metrics–Length of (development) iteration–Number of changes in requirements–Number of finished tasks

Page 29: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

29/5114.11.07

Software MetricsSourceKibitzer

Resources

• Measuring resource usage and properties

• Examples of metrics–Personnel competency–Personnel fluctuation–Personnel know-how in the project*

Page 30: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

30/5114.11.07

Software MetricsSourceKibitzer

Product

• Measuring product attributes–Size, complexity, performance, ...

• Examples of metrics–LOC, SLOC, CLOC, function points– (McCabe’s) cyclomatic complexity–Code coverage (with tests)–Code stability*

Page 31: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

31/5114.11.07

Software MetricsSourceKibitzer

Software Metric Classification II

Measuring vs Combining

Page 32: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

32/5114.11.07

Software MetricsSourceKibitzer

Direct Metrics

• Directly measurable• One measured attribute or entity

• Examples of Metrics–LOC, SLOC, CLOC

• (entity: product)

–Number of methods–Number of requirements

• (entity: requirement specification)

Page 33: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

33/5114.11.07

Software MetricsSourceKibitzer

Indirect Metrics• Derived metrics – not possible to

measure directly• Combination of several metrics

–Involves many attributes or entities

• Examples of Metrics–Requirement stability:

• initial num of req.-s/total num of req.-s

–Bug Density: • number of bugs/LOC

Page 34: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

34/5114.11.07

Software MetricsSourceKibitzer

Software Metric Classification III

Internal vs External

Page 35: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

35/5114.11.07

Software MetricsSourceKibitzer

Internal Attributes

• Measured in terms of only the entity itself–Measurement environment is not

relevant

• Examples of Metrics–LOC, Density of Comments–Code coverage (with tests)–Code reuse

Page 36: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

36/5114.11.07

Software MetricsSourceKibitzer

External Attributes

• Measured with respect to environment

• Examples of Metrics–Performance–Usability–Maintainability

Page 37: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

37/5114.11.07

Software MetricsSourceKibitzer

Are software metrics good or evil?Why?

Page 38: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

38/5114.11.07

Software MetricsSourceKibitzer

Critics

• People evaluation by numbers–Emotions, people adjust

• Easy to mistreat• Either meaningful or accurate

–Not both: LOC vs F-points

• Solution: set up clear goals and choose corresponding metrics

Page 39: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

39/5114.11.07

Software MetricsSourceKibitzer

Software Metrics Frameworks

• GQM:–Goal – Question – Metric

• PSM: –Practical Software Measurement

• AMI: –Application of Metrics in Industry

• ...

Page 40: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

40/5114.11.07

Software MetricsSourceKibitzer

Goal–Question–Metric Framework

Goal 1 Goal 2

Q1 Q2 Q3 Q4

M5M4M3M2M1

Conceptual Level:Goals

Operational Level:

Questions

Quantitative Level:Metrics

DEFIN

ITION A

NA

LYSI

S

Page 41: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

41/5114.11.07

Software MetricsSourceKibitzer

GQM Exercise

Any burning trouble in SE lab teams?

Page 42: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

42/5114.11.07

Software MetricsSourceKibitzer

GQM Exercise

Any burning trouble in SE lab teams?

Some team members are much more committed than the others

Page 43: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

43/5114.11.07

Software MetricsSourceKibitzer

GQM Naive ExampleGoal:

90% koodi keerukus on alla 10

Q1:Milline koodi keerukus

hetkel on?

Q2:Kuidas koodi keerukus

paraneb?

M1:Koodi keskmine

keerukus

M2:Koodi keerukus

moodulite kaupa

M3:Koodi keerukus

meetodite kaupa

M5:Koodi

keerukuse muutus kuus

M4:Koodi keerukus autorite kaupa

Page 44: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

44/5114.11.07

Software MetricsSourceKibitzer

Some Tools• Metrics for Java Open Source Teams*

– http://www.sourcekibitzer.org/• Metrics Eclipse Extension

– http://metrics.sourceforge.net/• JDepend

– http://clarkware.com/software/JDepend.html• Chidamber and Kemerer Java Metrics

– http://www.spinellis.gr/sw/ckjm/• RefactorIT

– http://refactorit.com/• ...

Page 45: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

45/5114.11.07

Software MetricsSourceKibitzer

Exercise

• Calculate following metrics for the given code sample–LOC, SLOC–McCabe's Cyclomatic Complexity

CODE SAMPLE• Solution

–McCabe's Cyclomatic Complexity

FLOW GRAPH

Page 46: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

46/5114.11.07

Software MetricsSourceKibitzer

Question

• Where is the highest probability of undetected bugs? (Given that all modules are tested equally well)– in modules showing LARGEST number of

known bugs– in modules showing SMALLEST number of

known bugs

Page 47: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

47/5114.11.07

Software MetricsSourceKibitzer

Exercise

• Make up 10 metrics for evaluation of these slides:–Metric–Attribute of measurement

• Example–Number of slides -> Presentation Size–Ratio of pictures to the number of slides

-> Presentation Complexity

Page 48: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

48/5114.11.07

Software MetricsSourceKibitzer

Software Metrics• Metric is ...

–Goal: ...–The most important aspect of

application: ...

• If software metrics topic seems interesting to you:Anton Litvinenko

email: [email protected]

skype: anton.a.litvinenko

Page 49: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

49/5114.11.07

Software MetricsSourceKibitzer

Please Keep in Mind

Software Metrics is a tool helping us to perform better

• BUT it is NOT a SILVER BULLET!• You have to be careful and know the

context of measurements–Otherwise you might end up with wrong

interpretation of metrics values

Page 50: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

50/5114.11.07

Software MetricsSourceKibitzer

References• Wikipedia

– http://en.wikipedia.org/wiki/Software_metric

• C. Lange, Metrics in Software Architecting– http://www.win.tue.nl/~mchaudro/sa2007/Metrics%20Architecting%202005.pdf

• M. Gökmen, Software Process and Project Metrics– http://www3.itu.edu.tr/~gokmen/SE-lecture-2.pdf

• H. Nestra, Metrics, Software Engineering 2005– http://courses.cs.ut.ee/2005/tvt/uploads/Main/software_engineering_21.pdf

• GQM Approach– http://www.goldpractices.com/practices/gqm/index.php

• More...– http://www.laynetworks.com/Software%20Engineering.htm– http://www.parlezuml.com/metrics/OO%20Design%20Principles%20&%20Metrics.pdf

Page 51: Software Metrics - ut · 5/51 14.11.07 SourceKibitzer Software Metrics Measurement •Assignment of quantitative indications to product's attributes –“Mapping from real world

51/5114.11.07

Software MetricsSourceKibitzer

References II

• Lines of Code– http://en.wikipedia.org/wiki/Source_lines_of_code

• McCabe's Cyclomatic Complexity– http://en.wikipedia.org/wiki/Cyclomatic_complexity– http://www.sei.cmu.edu/str/descriptions/cyclomatic_body.html– http://www.stsc.hill.af.mil/crosstalk/1994/12/xt94d12b.asp

• Function Points– http://www.csee.umbc.edu/~mikeg/cmsc645/function_point.html– http://www.softwaremetrics.com/Function%20Point%20Training%20Booklet%20New.pdf– http://www.codeproject.com/gen/design/Softwarecosting.asp– http://www.ifpug.com/fpafund.htm