File: coverage.h

package info (click to toggle)
kcachegrind 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,964 kB
  • sloc: cpp: 32,149; xml: 403; perl: 325; python: 235; sh: 8; makefile: 6
file content (92 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download | duplicates (2)
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
/*
    This file is part of KCachegrind.

    SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

    SPDX-License-Identifier: GPL-2.0-only
*/

/*
 * 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 TraceAssociation
{
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();

    int rtti() override { 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,
                                      EventType* 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 EventType* _costType;
};

#endif