File indexing completed on 2024-04-21 09:32:19
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 #ifndef SUBCOST_H 0010 #define SUBCOST_H 0011 0012 #include <QVector> 0013 #include <QList> 0014 0015 #include "utils.h" 0016 0017 typedef unsigned long long uint64; 0018 0019 /** 0020 * Cost event counter, simple wrapper around a 64bit entity 0021 */ 0022 class SubCost 0023 { 0024 public: 0025 SubCost() { v=0; } 0026 // no "explicit": we allow implicit conversions 0027 SubCost(uint64 i) { v=i; } 0028 SubCost(unsigned i) { v=i; } 0029 SubCost(int i) { v=(unsigned)i; } 0030 SubCost(double d) { v= (uint64)(d + .5); } 0031 0032 SubCost& operator=(uint64 i) { v = i; return *this; } 0033 SubCost& operator=(unsigned i) { v = i; return *this; } 0034 SubCost& operator=(int i) { v = i; return *this; } 0035 SubCost& operator=(double d) { v = (uint64)(d + .5); return *this; } 0036 0037 bool set(const char** s); 0038 bool set(FixString& s) { return s.stripUInt64(v); } 0039 0040 operator uint64&() { return v; } 0041 operator uint64() const { return v; } 0042 0043 bool operator==(unsigned i) const { return v == i; } 0044 bool operator==(int i) const { return v == (unsigned)i; } 0045 bool operator<(unsigned i) const { return v < i; } 0046 bool operator<(int i) const { return v < (unsigned)i; } 0047 bool operator<(const SubCost& s) const { return v < s.v; } 0048 bool operator>(unsigned i) const { return v > i; } 0049 bool operator>(int i) const { return v > (unsigned)i; } 0050 bool operator>(const SubCost& s) const { return v > s.v; } 0051 0052 /** 0053 * Convert SubCost value into a QString, 0054 * spaced every 3 digits. 0055 */ 0056 QString pretty(char sep = ' ') const; 0057 0058 uint64 v; 0059 }; 0060 0061 class ProfileCostArray; 0062 class EventType; 0063 typedef QList<ProfileCostArray*> TraceCostList; 0064 0065 /** 0066 * A class to calculate the maxSize ProfileCostArray items 0067 * with highest cost. 0068 */ 0069 0070 class HighestCostList 0071 { 0072 public: 0073 HighestCostList(); 0074 0075 void clear(int maxSize); 0076 void addCost(ProfileCostArray*, SubCost); 0077 int count() { return _count; } 0078 int realCount() { return (_count > _maxSize) ? _maxSize:_count; } 0079 int maxSize() { return _maxSize; } 0080 bool hasMore() { return _count > _maxSize; } 0081 ProfileCostArray* operator[] (int i) 0082 { return (i>=0 && i<_count && i<_maxSize) ? _item[i] : nullptr; } 0083 0084 private: 0085 TraceCostList _list; 0086 int _maxSize, _count; 0087 EventType* _costType; 0088 QVector<ProfileCostArray*> _item; 0089 QVector<SubCost> _cost; 0090 }; 0091 0092 0093 #endif