MASTER'S THESIS Automatic Measurement of Source Code Complexity Hassan Raza Bhatti Master of Science Computer Science and Engineering Luleå University of Technology Department of Computer Science, Electrical and Space Engineering ABSTRACT The aim of this master thesis is to explore the area of software metrics and to identify software metrics related to the code complexity. In this thesis, thorough study is made to determine whether or not the automatic measurement of source code complexity is possible. A tool for automatic measurement of source code complexity is implemented during this thesis to prove the idea that the automatic measurement is achievable. This report summaries the theory about software metrics, purpose and classification of the metrics, and the areas where metrics can be helpful to use. Detail description about some selected metrics (like Cyclomatic Complexity and Halstead metrics) is also a part of this report. Three core requirements of this thesis are: 1) Measurement of code complexity for the code written in C. 2) Measurement should perform automatically on the code base and on a regular basis for new code releases. 3) Run on Solaris. Some of the existing complexity measurement tools (open-source and commercial) are evaluated in this thesis. QA-C is an existing commercially available tool for the code complexity of C code. The tool implemented in this thesis uses QA-C as a foundation for analyzing C code on Solaris. Web interfaces are designed to present the results of code complexity measurement. ii TABLE OF CONTENTS ABSTRACT .............................................................................................................. ii TABLE OF CONTENTS .............................................................................................. iii ACKNOWLEDGEMENTS ............................................................................................ vi INTRODUCTION ......................................................................................................... 1 1.1 Background ....................................................................................................... 1 1.2 Problem Area .................................................................................................... 1 1.2.1 Research ..................................................................................................... 1 1.2.2 Implementation ........................................................................................... 2 1.3 The Given System .............................................................................................. 2 1.4 The Method ....................................................................................................... 2 1.4.1 Pre-study .................................................................................................... 2 1.4.2 Implementation of tool .................................................................................. 2 1.5 Delimitation ...................................................................................................... 3 SOFTWARE METRICS .................................................................................................. 4 2.1 Uses of Software Metrics ..................................................................................... 4 2.2 Classification of Software Metrics ......................................................................... 5 2.2.1 Process metrics ............................................................................................ 5 2.2.2 Product metrics ............................................................................................ 5 2.2.3 Resource metrics .......................................................................................... 6 2.3 Software Code Metrics ........................................................................................ 6 2.3.1 Quantitative metrics ..................................................................................... 6 2.3.2 Metrics of program flow complexity ................................................................ 6 2.3.3 Metrics of data control flow's complexity ......................................................... 7 2.3.4 Metrics of control flow and data flow complexity ............................................... 7 2.3.5 Object-oriented metrics................................................................................. 7 2.3.6 Safety metrics ............................................................................................. 7 2.3.7 Hybrid metrics ............................................................................................. 7 2.4 Code Complexity ................................................................................................ 7 SELECTION OF METRICS ............................................................................................. 9 3.1 Source Line of Code (SLOC) ................................................................................ 9 3.1.1 Advantages ................................................................................................. 9 3.1.2 Disadvantages ............................................................................................. 9 3.1.3 Motivation ................................................................................................. 10 3.2 Halstead Software Science ................................................................................ 10 3.2.1 Halstead formulas ...................................................................................... 11 3.2.2 Problems with Halstead metrics .................................................................... 14 iii 3.2.3 Motivation ................................................................................................. 14 3.3 ABC Metric ...................................................................................................... 15 3.3.1 Advantages ............................................................................................... 15 3.3.2 Disadvantages ........................................................................................... 15 3.3.3 Motivation ................................................................................................. 15 3.4 McCabe Cyclomatic Complexity .......................................................................... 15 3.4.1 Advantages ............................................................................................... 16 3.4.2 Disadvantages ........................................................................................... 16 3.4.3 Motivation ................................................................................................. 17 3.5 Henry and Kafura's Information Flow Metric ........................................................ 17 3.5.1 Advantages ............................................................................................... 18 3.5.2 Disadvantages ........................................................................................... 18 3.5.3 Motivation ................................................................................................. 18 3.6 Maintainability Index (MI) ................................................................................. 18 3.6.1 Construction of MI ...................................................................................... 18 3.6.2 Advantages ............................................................................................... 20 3.6.2 Disadvantages ........................................................................................... 20 3.6.3 Motivation ................................................................................................. 20 3.7 Other Metrics .................................................................................................. 20 3.7.1 Variants of Line of Code metric .................................................................... 21 3.7.2 Function metrics......................................................................................... 21 3.7.3 File/Project metrics ..................................................................................... 22 3.8 Combination of Metrics ..................................................................................... 22 3.8.1 Proposed metric suite ................................................................................. 22 EXISTING TOOLS FOR CODE COMPLEXITY ................................................................... 24 4.1 Understand ..................................................................................................... 25 4.1.1 Tool evaluation .......................................................................................... 25 4.2 Resource Standard Metrics (RSM) ...................................................................... 25 4.2.1 Tool evaluation .......................................................................................... 25 4.3 Testwell CMT++ .............................................................................................. 26 4.3.1 Tool evaluation .......................................................................................... 26 4.4 QA-C Source Code Analyzer .............................................................................. 27 4.4.1 Tool evaluation .......................................................................................... 27 4.5 Other Tools ....................................................................................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages93 Page
-
File Size-