software metrics software engineering. definitions measure – the process of assigning numbers to...

36
Software Metrics Software Engineering

Upload: dennis-todd

Post on 01-Jan-2016

222 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Software Metrics

Software Engineering

Page 2: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Definitions

• Measure – the process of assigning numbers to attributes of entities according to some defined rules.– E.g., Number of errors

• Metric – The continuous application of the measurement based techniques to the software development processes and products to supply meaningful information together with use of those techniques to improve software development process and its products– E.g., Number of errors found per person

Page 3: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Software Metrics

Measurement Based

Techniques

Measurement Based

Techniques

Engineering and Management Information

Engineering and Management Information

Processes, Products and

Services

Processes, Products and

Services

Applied to

Applied to

To SupplyTo Supply

To ImproveTo Improve

Page 4: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Why Measure Software?

1. Determine the quality of the current product or process

2. Predict qualities of a product/process

3. Improve quality of a product/process

Page 5: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Types of Measures

• Direct Measures (internal attributes)– Cost, effort, LOC (lines of code), speed,

memory size and defects reported over set period of time.

• Indirect Measures (external attributes)– Functionality, quality, complexity, efficiency,

reliability, maintainability– More difficult to assess

Page 6: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Motivation for Metrics

1. Estimate the cost & schedule of future projects

2. Evaluate the productivity impacts of new tools and techniques

3. Establish productivity trends over time

4. Improve software quality

5. Forecast future staffing needs

6. Anticipate and reduce future maintenance needs

Page 7: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Metric Classification• Product Metrics

– Describe the characteristics of the product, such as size, complexity, design features, performance, efficiency, reliability, portability etc.

• Process Metrics– Activities related to production of software like effort

required in the process, time to produce the product, number of defects found during testing, effectiveness of defect removal during development, maturity of the process

• Project Metrics– Describe the project characteristics and execution like

number of software developers, cost and schedule, productivity

Page 8: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Attributes of Effective Software Metrics

1. Simple and Computable

2. Consistent and objective

3. Consistent in the use of units and dimensions

4. Programming language independent

5. An effective mechanism for high – quality feedback

Page 9: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

9

Halstead's Software Science Metrics

• It is an analytical technique to measure size, development effort and development cost of software products.

• Halstead used a few primitive program parameters to develop the expressions for overall program length, potential minimum value, actual volume, effort and development time.

Page 10: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

10

Halstead's Software Science Metrics

• Halstead (researcher) proposed that program may be considered as a collection of lexical tokens, each of which can be classified as operator or operand.

• Operands are the tokens which have value. Data variables and constants therefore constitute the operands.

• Operators are commas, parenthesis, keywords, arithmetic operators, functions and so on.

• Tokens that appear in pairs are counted as one token eg. "begin...end", "repeat...until“ etc

Page 11: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

11

• Primitive Measures proposed by Halstead are:– the number of unique operators in program – the number of unique operands in program – N1 = total count of all operators in program. – N2 = total count of all operands in program.

1n

2n

Halstead's Software Science Metrics

Page 12: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

12

1. Halstead length : Total number of operators and operands in a program

2. Vocabulary : Defined as the sum of the number of unique operands and operators used in the program

3. Estimated Program Length : This value can be estimated before the program is written.

4. Program Volume : is the minimum number of bits needed to encode the program

21 NNN

21vocabulary nnn

Halstead's Software Science Metrics - Measures

)(log 212 nnNV

222121 loglog nnnnH

Page 13: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

13

5. Effort Equation : The effort E required to implement the program P is

Effort = (n1N2/2n2) (Nlog2n)

It correlates with the effort needed for maintenance for small programs. Unit for effort is elementary mental discriminators (emd).

6. Time Equation: Halstead also estimated the time T required to implement the program as

T = (E/18) seconds

Halstead's Software Science Metrics - Measures

Page 14: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

14

1. Simple to calculate

2. Do not require in depth analysis of programming structure

3. Measure overall quality of programs

4. Predicts maintenance effort

5. Useful in scheduling the projects

Halstead's Software Science Metrics - Advantages

Page 15: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Q. Consider the program code given below

PROGRAMint sum, i;

sum = 0;

for (i=1; i<=20; i++)

sum = sum + i;

printf(sum);

For this program compute Halstead software science metrics n1 n2 N1 N2 n V E and T.

Page 16: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

16

PROGRAM

Int sum,i;

Sum = 0;

For (i=1; i<=20; i++)

sum = sum + i;

Printf(sum);

Halstead's Software Science Metrics - Example

List of Operators : List of Operands :

Operator

frequency

Int 1

, 1

; 6

= 3

() 2

<= 1

++ 1

For 1

+ 1

Printf 1

Operands

frequency

Sum 5

i 5

0 1

1 1

20 1

Page 17: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

• n1 = number of distinct operators = 10

• n2 = number of distinct operands = 5

• N1 = total number of operator occurrences = 18

• N2 = total number of operand occurrences = 13

1. Vocabulary (n) of program = n1 + n2 = 15

2. Length of the program = N1 + N2 = 31

3. Estimated Program Length : n1log2n1 + n2log2n2

= 10log210 + 5log25 = 10*3.32 + 5*2.32 = 44.8

4. Volume (V) = Nlog2n = 31 log215 = 31*3.91 = 121.21 bits

Halstead's Software Science Metrics - Example

Page 18: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

• n1 = number of distinct operators = 10

• n2 = number of distinct operands = 5

• N1 = total number of operator occurrences = 18

• N2 = total number of operand occurrences = 13

5. Effort = (n1N2/2n2) (Nlog2n) = ((10*13)/(2*5))(31log215) = 1583.79 emd

6. Time = E/18 = 1583.79/18 = 87.98 seconds

Halstead's Software Science Metrics - Example

Page 19: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Size-Oriented Metrics - LOC• LOC - Lines Of Code is the simplest among all metrics

available to estimate project size.• KLOC - 1000 Lines Of Code• SLOC – Statement Lines of Code (ignore whitespace)• Project size is estimated by counting the number of

source instructions in the developed program.• Typical Measures:

– Errors/KLOC, – Defects/KLOC, – Cost/LOC, – Documentation Pages/KLOC

Page 20: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Size Metric- Lines of Code(LOC)

The basic and simplest metric for the size is Lines of code(LOC) often quoted in 1000’s (KLOC). In a real sense this metric measures the length of a program which is a logical characteristic but not size which is physical characteristic of the program. While number of lines, normally researchers are of the view that comments and blank lines should not be counted. Comments used in the program make the program understandable and easier to maintain but effort required for writing the comments is not as much as writing the code. According to some researchers LOC mat be computed by counting the new-line characters in the program. This metric can also be used in other indirect measures as well, such as

Productivity = LOC/Effort

Page 21: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

LOC Metrics• Advantages

– Easy to use– Easy to compute

• Disadvantages– Language & programmer dependent – Bad software design may cause excessive

line of code– Defined on code– User cannot easily understand it

Page 22: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Measuring Functionality – Function Point Analysis (FPA)

• FPA is a popular method which uses complexity and the number of functions supported by the software to compute the size of the software in terms of Function Point Count (FPC).

• Concept : the size of the software being developed is directly proportional to the number of functions it will support.

• Each of these functions are characterized by the inputs taken, outputs given, interfaces and the number of files used. All these factors contribute in calculating total function points.

Page 23: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Flowchart for computing Function PointsStartStart

EndEnd

Specify the Functional Requirement ProjectSpecify the Functional Requirement Project

Count Data Function Type and Transaction Function TypeCount Data Function Type and Transaction Function Type

Compute Unadjusted Function Point (UFP)Compute Unadjusted Function Point (UFP)

Apply General CharacteristicsApply General Characteristics

Compute Value Adjustment Factor (VAF)Compute Value Adjustment Factor (VAF)

Adjusted Compute Function Point from UFP and VAFAdjusted Compute Function Point from UFP and VAF

Page 24: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Steps for Computing Function Points1. Identify and Count following functions :

a) External Inputs (EI) : user or control data entering the system.

b) External Outputs (EO) : user or control data coming out of the system.

c) External Inquiries (EIQ) : they do not change the system data. They represent input – output combination.

d) Internal Files (IF) : maintained and understood by customers

e) External Interface (EIF) : files which are shared by the system and other programs. They are not maintained by the software.

Page 25: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Steps for Computing Function Points2. Calculate Unadjusted Function Points :• Identify the complexity level of data function type and

transaction function type• Their complexity depends on the number of data

element types and file types referenced.• Once the unadjusted function points are computed,

then based on their complexity level they are multiplied by the weighing factors as follows:

Simple Average Complex

EI 3 4 6

EO 4 5 7

EIQ 3 4 6

IF 7 10 15

EIF 5 7 10

Page 26: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Steps for Computing Function Points3. Apply 14 general characteristics :• The 14 characteristics are : data communications,

performance, transaction rate, processing, reusability, end user efficiency, online update, configuration, multiple sites, operations, change requirements, distributed processing, online data entry and installation.

• These characteristics have rating 0 – 5 which influence Function Point Count (FPC)

• Sum of these 14 general characteristics rating can be between 0 – 70 and is called Total Degree of Influence (TDI)

Page 27: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Steps for Computing Function Points

4. Compute the Value Adjustment Factor (VAF)

VAF = (TDI * 0.01) + 0.65

5. Calculate Function Point count (FPC)

FPC = UFP * VAF

FP are not suitable for algorithmically intensive systems such as embedded systems and real time systems. In such type of systems function points called feature points are used for estimating the size.

Page 28: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Advantages of Function Point Technique

1. Function Points(FP) can be computed early in the project and are directly derived from SRS.

2. FP are independent of the technology (ie. Programming languages, database etc. ) used to develop the software.

3. It can be used as a technique to measure the productivity of the projects written in different languages.

Page 29: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Function Point Technique - ExampleConsider a project with following data:

Number of external inputs with low complexity = 10

Number of external inputs with high complexity = 10

Number of external outputs with average complexity = 15

Number of external inquiries with average complexity = 13

Number of internal logical files with high complexity = 2

Number of internal logical files with low complexity = 2

Number of external interface files with average complexity = 7

The system has a very high transaction rate and supports several multiple communication protocols. Calculate the unadjusted as well as adjusted function points.

Page 30: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Function Point Technique - ExampleSolution: Total unadjusted function points (UFP) after

considering the weighting factors are given by :

UFP = 3 * 10 + 6 * 10 + 5 * 15 + 4* 13 + 15 * 2 + 7 * 2 + 7 * 7 = 30 + 60 + 75 + 52 + 30 + 14 + 49 = 310

The software also supports high transaction rate and multiple communication protocols. Hence these two system characteristics can be assigned a rating of 5.

TDI = 5 + 5 =10

VAF = (TDI * 0.01) + 0.65 = (10 * 0.01) + 0.65 = 0.75

Adjusted function points FPC = UFP * VAF

= 310 * 0.75 = 232.5

Page 31: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

McCabe’s Cyclomatic Complexity Metric

• It is a metric to measure logical complexity of the program.• McCabe’s metrics are based on a control flow representation of the

program.• It defines the number of independent paths in the program to be

executed in order to ensure that all statements in the program are executed at least once.

• In other words it gives us the value for maximum number of est cases to be designed.

• A program graph is used to depict control flow.• Nodes represent processing tasks (one or more code statements)• Edges represent control flow between nodes

Page 32: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Flow Graph Notation

Sequence

If-then-else

While

Until

Case

Page 33: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Ways to compute Cyclomatic Complexity

The cyclomatic complexity C(G) of a graph G can be computed using one of the following ways: 1.C(G) = E – N + 2

– E is the number of flow graph edges– N is the number of nodes

2.C(G) = number of regions in the flow graph. Regions are the areas bounded by nodes and edges in a flow graph. While counting regions, area outside the graph is also counted as one region.

3.C(G) = P + 1– P is the number of predicate nodes

Page 34: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Example1. main() { 2. int num_student, marks, subject, total;3. float average;4. num_student = 1;5. while(num_student <=25) {6. total = 0;7. subject = 1;8. while(subject<=5){9. scanf(“Enter marks:%d”, &marks);10. total = total + marks11. subject ++;12. }13. average = total/5;14. If(average>=50)15. printf(“Pass...Average is %f”, average);16. else17. printf(“Fail...Average is %f”, average);18. num_student++;19. } 20. 20. printf({“End of Program”); 21. }

Nodes Statement

Numbers

a 2-4

b 5

e 6-7

f 8

z 9-12

g 13-14

h 15

i 17

j 18

c 19

d 20

Page 35: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Flow Graph

e

g

ih

j

f

b

z

d

c

a

Page 36: Software Metrics Software Engineering. Definitions Measure – the process of assigning numbers to attributes of entities according to some defined rules

Ways to compute Cyclomatic Complexity

The cyclomatic complexity C(G) of a graph G can be computed using one of the following ways: 1.C(G) = E – N + 2

E =13, N=11C(G)=13-11+2=4

2.C(G) = number of regions in the flow graph= 4 3.C(G) = P + 1 =3+1 =4