Software Metrics

Software metrics quantify size, complexity and quality — defect density, cyclomatic complexity and reliability measures like MTBF — to inform decisions about testing effort, maintainability and release readiness.

Key formulas & points

Skim these first — then read the full notes below.

  • LOC and function points measure size differently
  • Halstead metrics derive from operators and operands
  • Metrics guide quality decisions, not individual blame

Topic details

Introduction

This Sommerville topic covers measuring software. You compute size metrics (LOC, function points), complexity metrics (cyclomatic, Halstead), and quality metrics (defect density, MTBF), and interpret them to guide engineering decisions.

Key relations & formulas

Formulas (Indian textbook notation)

  • defectdensity=defectsKLOCdefect density = \frac{defects}{KLOC}

Formulas (Indian textbook notation)

  • cyclomaticcomplexityV(G)=EN+2Pcyclomatic complexity V(G) = E - N + 2P

Formulas (Indian textbook notation)

  • MTBF=totaluptimenumberoffailuresMTBF = total \frac{uptime}{number} of failures

Notation and sign conventions

Relation 1 —
defectdensity=defectsKLOCdefect density = \frac{defects}{KLOC}

Formulas (Indian textbook notation)

  • defectdensity=defectsKLOCdefect density = \frac{defects}{KLOC}
Write this relation with symbols exactly as in Software Engineering — Roger Pressman before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 2 —
cyclomaticcomplexityVcyclomatic complexity V

Formulas (Indian textbook notation)

  • cyclomaticcomplexityV(G)=EN+2Pcyclomatic complexity V(G) = E - N + 2P
Write this relation with symbols exactly as in Software Engineering — Roger Pressman before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 3 —
MTBF=totaluptimenumberoffailuresMTBF = total \frac{uptime}{number} of failures

Formulas (Indian textbook notation)

  • MTBF=totaluptimenumberoffailuresMTBF = total \frac{uptime}{number} of failures
Write this relation with symbols exactly as in Software Engineering — Roger Pressman before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.

Concept in depth

You cannot manage what you cannot measure, but metrics must be interpreted carefully. Size metrics estimate effort and normalise other measures — defect density (defects per KLOC) lets modules of different sizes be compared fairly. Cyclomatic complexity counts the independent paths through code, both flagging hard-to-test modules and setting a lower bound on the number of test cases needed for path coverage. Reliability metrics like MTBF summarise operational quality. The crucial discipline is using metrics to improve the process — targeting testing at complex modules, tracking defect trends — rather than as blunt instruments to rank or blame individuals, which distorts behaviour.

Assumptions and validity limits

State assumptions explicitly before using any relation for software metrics — steady state, uniform properties, linear elastic material, ideal gas, incompressible flow, etc., as applicable.
Wrong assumptions invalidate the entire solution even when the formula is correct. In Software Engineering viva and GATE descriptive questions, listing valid assumptions often earns separate marks.

Step-by-step problem approach

1. Read the question and list given data with SI units (common in Software Engineering papers).
2. Draw a neat labelled diagram where applicable — examiners in Indian universities award diagram marks even when arithmetic slips.
3. Identify which relation from this topic applies to software metrics.
4. Use equation 1:
defectdensity=defectsKLOCdefect density = \frac{defects}{KLOC}
.
5. Use equation 2:
cyclomaticcomplexityVcyclomatic complexity V
.
6. Substitute values, compute, and verify units and sign (direction).
7. State conclusion in one line — e.g. safe/unsafe, stable/unstable, feasible/infeasible.

Applications & exam relevance

Software Metrics appears in product teams and IT services. In Indian it software curricula this topic is tested because it connects theory to SDLC, requirements, and quality.
GATE and semester exams often combine software metrics with earlier units — revise prerequisites before attempting mixed problems.
Industry interview panels sometimes ask: "Where did you use software metrics?" — answer with a lab, mini-project, or plant visit example if possible.

Common mistakes in exams

Students miscompute cyclomatic complexity (forgetting the +2P term or miscounting edges/nodes), compare raw defect counts across differently sized modules instead of defect density, and treat metrics as absolute judgements. Confusing MTBF with MTTR is a frequent slip.

Quick revision checklist

Before attempting software metrics problems, confirm you can:
1. LOC and function points measure size differently
2. Halstead metrics derive from operators and operands
3. Metrics guide quality decisions, not individual blame
Revise the solved examples in Software Engineering — Roger Pressman and one previous-year GATE or university paper for this unit.

Worked examples

Try the problem first — open the solution when you are ready to check.

Defect density

Problem

A module has 45 defects in 30 KLOC. Compute its defect density.

Solution

Defect density = defects / KLOC = 45 / 30 = 1.5 defects per KLOC. Normalising by size lets this be compared against other modules or benchmarks.

Conceptual check — Software Metrics

Problem

In a Software Engineering semester or GATE paper you are asked: "State the main assumption, the governing relation, and one practical consequence of software metrics." What should a complete answer include?

📖 Standard books (India)

  • Software EngineeringRoger Pressman

    Read: Syllabus unit

    SDLC, Agile, and software metrics