File: subcost.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 (93 lines) | stat: -rw-r--r-- 2,443 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
93
/*
    This file is part of KCachegrind.

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

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

#ifndef SUBCOST_H
#define SUBCOST_H

#include <QVector>
#include <QList>

#include "utils.h"

typedef unsigned long long uint64;

/**
 * Cost event counter, simple wrapper around a 64bit entity
 */
class SubCost
{
public:
    SubCost() { v=0; }
    // no "explicit": we allow implicit conversions
    SubCost(uint64 i) { v=i; }
    SubCost(unsigned i) { v=i; }
    SubCost(int i) { v=(unsigned)i; }
    SubCost(double d) { v= (uint64)(d + .5); }

    SubCost& operator=(uint64 i) { v = i; return *this; }
    SubCost& operator=(unsigned i) { v = i; return *this; }
    SubCost& operator=(int i) { v = i; return *this; }
    SubCost& operator=(double d) { v = (uint64)(d + .5); return *this; }

    bool set(const char** s);
    bool set(FixString& s) { return s.stripUInt64(v); }

    operator uint64&() { return v; }
    operator uint64() const { return v; }

    bool operator==(unsigned i) const { return v == i; }
    bool operator==(int i) const { return v == (unsigned)i; }
    bool operator<(unsigned i) const { return v < i; }
    bool operator<(int i) const { return v < (unsigned)i; }
    bool operator<(const SubCost& s) const { return v < s.v; }
    bool operator>(unsigned i) const { return v > i; }
    bool operator>(int i) const { return v > (unsigned)i; }
    bool operator>(const SubCost& s) const { return v > s.v; }

    /**
     * Convert SubCost value into a QString,
     * spaced every 3 digits.
     */
    QString pretty(char sep = ' ') const;

    uint64 v;
};

class ProfileCostArray;
class EventType;
typedef QList<ProfileCostArray*> TraceCostList;

/**
 * A class to calculate the maxSize ProfileCostArray items
 * with highest cost.
 */

class HighestCostList
{
public:
    HighestCostList();

    void clear(int maxSize);
    void addCost(ProfileCostArray*, SubCost);
    int count() { return _count; }
    int realCount() { return (_count > _maxSize) ? _maxSize:_count; }
    int maxSize() { return _maxSize; }
    bool hasMore() { return _count > _maxSize; }
    ProfileCostArray* operator[] (int i)
    { return (i>=0 && i<_count && i<_maxSize) ? _item[i] : nullptr; }

private:
    TraceCostList _list;
    int _maxSize, _count;
    EventType* _costType;
    QVector<ProfileCostArray*> _item;
    QVector<SubCost> _cost;
};


#endif