summaryrefslogtreecommitdiffstats
path: root/tdecachegrind/tdecachegrind/coverage.h
blob: 50c5936a781de8f329635168816fcc3182044fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* This file is part of KCachegrind.
   Copyright (C) 2002 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/*
 * Function Coverage Analysis
 */

#ifndef COVERAGE_H
#define COVERAGE_H

#include "tracedata.h"

/**
 * Coverage of a function.
 * When analysis is done, every function involved will have a
 * pointer to an object of this class.
 *
 * This function also holds the main routine for coverage analysis,
 * Coverage::coverage(), as static method.
 */
class Coverage : public TraceAssoziation
{
public:
  /* Direction of coverage analysis */
  enum CoverageMode { Caller, Called };

  // max depth for distance histogram
#define maxHistogramDepthValue 40
  static const int maxHistogramDepth;

  static const int Rtti;

  Coverage();

  virtual int rtti() { return Rtti; }
  void init();

  TraceFunction* function() { return _function; }
  double self() { return _self; }
  double inclusive() { return _incl; }
  double firstPercentage() { return _firstPercentage; }
  double& callCount() { return _callCount; }
  int minDistance() { return _minDistance; }
  int maxDistance() { return _maxDistance; }
  int inclusiveMedian();
  int selfMedian();
  double* selfHistogram() { return _selfHisto; }
  double* inclusiveHistogram() { return _inclHisto; }
  bool isActive() { return _active; }
  bool inRecursion() { return _inRecursion; }

  void setSelf(float p) { _self = p; }
  void setInclusive(float p) { _incl = p; }
  void setCallCount(float cc) { _callCount = cc; }
  void setActive(bool a) { _active = a; }
  void setInRecursion(bool r) { _inRecursion = r; }

  /**
   * Calculate coverage of all functions based on function f.
   * If mode is Called, the coverage of functions called by
   * f is calculated, otherwise that of functions calling f.
   * SubCost type ct is used for the analysis.
   * Self values are undefined for Caller mode.
   *
   * Returns list of functions covered.
   * Coverage degree of returned functions can be get
   * with function->coverage()->percentage()
   */
  static TraceFunctionList coverage(TraceFunction* f, CoverageMode m,
                                    TraceCostType* ct);

private:
  void addCallerCoverage(TraceFunctionList& l, double, int d);
  void addCallingCoverage(TraceFunctionList& l, double, double, int d);

  double _self, _incl, _firstPercentage, _callCount;
  int _minDistance, _maxDistance;
  bool _active, _inRecursion;
  double _selfHisto[maxHistogramDepthValue];
  double _inclHisto[maxHistogramDepthValue];

  // temporary set for one coverage analysis
  static TraceCostType* _costType;
};

#endif