www.redlizards.com Software Metrics in Static Program Analysis ICFEM, 11/18/2010 Andreas Vogelsang 1, Ansgar Fehnker 2, Ralf Huuck 2, Wolfgang Reif 3 1 Technical University of Munich 2 NICTA, Sydney 3 University of Augsburg
Motivation Problems Maintainability Complexity Extensibility Causes Detection Localization Impact Measures Controlling Quality Continuous Early detection Software Metrics Static Program Analysi 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 2
Software Metrics You can t control what you can t measure Tom DeMarco. Controlling Software Projects. 1986 IEEE Standard 1061: Input: SW data Output: single numerical value degree to which a software possesses a given attribute Challenges: Definition, Visualization, Computation 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 3
Example Cyclomatic Complexity Thomas J. McCabe, 1976 Number of linearly independent paths through the control flow of a function If-then-else branching increases the possible ways through the function Cyclomatic Complexity is 2 int foo (int i) { if (i > 0) { return i; } else { return i; } } 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 4
Static Program Analysis Analyzing without executing Input: program code Early detection of bugs and design flaws Goanna 1 Bug detection for C/C++ programs Control Flow Extraction Model Checking 1 www.redlizards.com Fehnker et al. Model Checking Software at Compile Time Proceedings of the 1st IEEE & IFIP International Symposium on Theoretical Aspects of Software Engineering 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 5
Contributions Metric definition language Syntax Denotational semantics Automatic computation Generic visualization 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 6
Definition - GMSL Syntax Goanna Metric Specification Language Definition of metrics using AST query functions METRIC name (scope) WITH counting_variables DEF expression METRIC nb_methods (c IN classes()) WITH @n=methods_of_class(c) DEF @n AST classes() @n=2 @n=3 methods_of_class 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 7
GMSL examples METRIC largest_method(c IN classes()) WITH @lm = MAX loc(m) OVER m IN methods_of_class(c) DEF @lm METRIC cyclomatic_complexity(c IN classes()) WITH @cc = SUM cyc_comp(m) OVER m IN methods_of_class(c) DEF @cc METRIC LCOM_HS(c IN classes()) WITH @m = methods_of_class(c), @a = fields_of_class(c), Henderson-Sellers. Object-oriented metrics Prentice-Hall, pp.142-147, 1996. @s = SUM method_access(f,c) OVER f IN fields_of_class(c) DEF (@s/@a - @m)/(1 - @m) 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 8
Denotational semantics for GMSL General idea: A metric declaration describes a function that, given a certain environment, maps some nodes of a program to real numbers 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 9
Visualizations Time view: Metric view: Scope view: Correlation view: 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 10
Summary and Future Work Integration of Software Metrics in Static Program Analysis User-defined metrics Case study on Audacity (~90,000 LOC) Detection of several design flaws Future work Integration into commercial product Performance Tuning Language extensions 11/18/2010 Software Metrics in Static Program Analysis - Andreas Vogelsang 11
www.redlizards.com Thanks for listening Any questions?