File indexing completed on 2024-04-28 09:36:46
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 /* 0010 * Function Coverage Analysis 0011 */ 0012 0013 #ifndef COVERAGE_H 0014 #define COVERAGE_H 0015 0016 #include "tracedata.h" 0017 0018 /** 0019 * Coverage of a function. 0020 * When analysis is done, every function involved will have a 0021 * pointer to an object of this class. 0022 * 0023 * This function also holds the main routine for coverage analysis, 0024 * Coverage::coverage(), as static method. 0025 */ 0026 class Coverage : public TraceAssociation 0027 { 0028 public: 0029 /* Direction of coverage analysis */ 0030 enum CoverageMode { Caller, Called }; 0031 0032 // max depth for distance histogram 0033 #define maxHistogramDepthValue 40 0034 static const int maxHistogramDepth; 0035 0036 static const int Rtti; 0037 0038 Coverage(); 0039 0040 int rtti() override { return Rtti; } 0041 void init(); 0042 0043 TraceFunction* function() { return _function; } 0044 double self() { return _self; } 0045 double inclusive() { return _incl; } 0046 double firstPercentage() { return _firstPercentage; } 0047 double& callCount() { return _callCount; } 0048 int minDistance() { return _minDistance; } 0049 int maxDistance() { return _maxDistance; } 0050 int inclusiveMedian(); 0051 int selfMedian(); 0052 double* selfHistogram() { return _selfHisto; } 0053 double* inclusiveHistogram() { return _inclHisto; } 0054 bool isActive() { return _active; } 0055 bool inRecursion() { return _inRecursion; } 0056 0057 void setSelf(float p) { _self = p; } 0058 void setInclusive(float p) { _incl = p; } 0059 void setCallCount(float cc) { _callCount = cc; } 0060 void setActive(bool a) { _active = a; } 0061 void setInRecursion(bool r) { _inRecursion = r; } 0062 0063 /** 0064 * Calculate coverage of all functions based on function f. 0065 * If mode is Called, the coverage of functions called by 0066 * f is calculated, otherwise that of functions calling f. 0067 * SubCost type ct is used for the analysis. 0068 * Self values are undefined for Caller mode. 0069 * 0070 * Returns list of functions covered. 0071 * Coverage degree of returned functions can be get 0072 * with function->coverage()->percentage() 0073 */ 0074 static TraceFunctionList coverage(TraceFunction* f, CoverageMode m, 0075 EventType* ct); 0076 0077 private: 0078 void addCallerCoverage(TraceFunctionList& l, double, int d); 0079 void addCallingCoverage(TraceFunctionList& l, double, double, int d); 0080 0081 double _self, _incl, _firstPercentage, _callCount; 0082 int _minDistance, _maxDistance; 0083 bool _active, _inRecursion; 0084 double _selfHisto[maxHistogramDepthValue]; 0085 double _inclHisto[maxHistogramDepthValue]; 0086 0087 // temporary set for one coverage analysis 0088 static EventType* _costType; 0089 }; 0090 0091 #endif 0092