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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/* This file is part of KCachegrind.
Copyright (c) 2002-2015 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.
*/
/*
* Items for caller/callee view.
*/
#include "callitem.h"
#include <QPixmap>
#include "globalguiconfig.h"
#include "listutils.h"
#include "callview.h"
// CallItem
CallItem::CallItem(CallView* view, QTreeWidget* parent, TraceCall* c)
: QTreeWidgetItem(parent)
{
for (int i = 0 ; i < 5; ++i)
setTextAlignment(i, Qt::AlignRight);
_call = c;
_view = view;
_active = _view->activeFunction();
bool baseIsCycle = (_active && (_active == _active->cycle()));
QString fName;
if (_view->showCallers()) {
_shown = _call->caller(true);
fName = c->callerName(!baseIsCycle);
}
else {
_shown = _call->called(true);
fName = c->calledName(!baseIsCycle);
}
_shown->addPrettyLocation(fName);
setText(5, fName);
updateGroup();
updateCost();
}
void CallItem::updateGroup()
{
QColor c = GlobalGUIConfig::functionColor(_view->groupType(), _shown);
setIcon(5, colorPixmap(10, 10, c));
}
void CallItem::updateCost()
{
bool sameCycle = _shown->cycle() && (_active->cycle() == _shown->cycle());
bool shownIsCycle = (_shown == _shown->cycle());
bool selectedIsCycle = (_active == _active->cycle());
if (_call->isRecursion()) sameCycle=true;
QString cStr;
if ((selectedIsCycle || shownIsCycle) && sameCycle)
cStr = "-";
else {
_cc = _call->callCount();
if (_cc == 0)
cStr = QObject::tr("(active)");
else
cStr = _call->prettyCallCount();
}
setText(4, cStr);
ProfileCostArray* totalCost;
if (GlobalConfig::showExpanded()) {
if (_active->cycle())
totalCost = _active->cycle()->inclusive();
else
totalCost = _active->inclusive();
}
else
totalCost = _active->data();
EventType* ct = _view->eventType();
_sum = _call->subCost(ct);
double total = totalCost->subCost(ct);
if (total == 0.0) {
QString str = "-";
setText(0, str);
setIcon(0, QPixmap());
}
else {
double sum = 100.0 * _sum / total;
if (GlobalConfig::showPercentage())
setText(0, QString("%1")
.arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
else {
setText(0, _call->prettySubCost(ct));
}
setIcon(0, costPixmap(ct, _call, total, false));
setText(1, _call->prettySubCostPerCall(ct, _cc));
}
// Cost Type 2
EventType* ct2 = _view->eventType2();
if (ct2) {
_sum2 = _call->subCost(ct2);
double total = totalCost->subCost(ct2);
if (total == 0.0) {
QString str = "-";
setText(2, str);
setIcon(2, QPixmap());
}
else {
double sum = 100.0 * _sum2 / total;
if (GlobalConfig::showPercentage())
setText(2, QString("%1")
.arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
else {
setText(2, _call->prettySubCost(ct2));
}
setIcon(2, costPixmap(ct2, _call, total, false));
setText(3, _call->prettySubCostPerCall(ct2, _cc));
}
}
QPixmap p;
if (sameCycle && !selectedIsCycle && !shownIsCycle) {
QString icon = "edit-undo";
#if 0 // TODO
KIconLoader* loader = KIconLoader::global();
p= loader->loadIcon(icon, KIconLoader::Small, 0,
KIconLoader::DefaultState, QStringList(), 0, true);
#endif
}
setIcon(4, p);
}
bool CallItem::operator<(const QTreeWidgetItem& other) const
{
int col = treeWidget()->sortColumn();
const CallItem* ci1 = this;
const CallItem* ci2 = (CallItem*) &other;
if (col==0)
return ci1->_sum < ci2->_sum;
if (col==1) {
uint64 cc1 = ci1->_cc;
uint64 cc2 = ci2->_cc;
if (cc1 == 0) cc1 = 1;
if (cc2 == 0) cc2 = 1;
return (ci1->_sum / cc1) < (ci2->_sum / cc2);
}
if (col==2)
return ci1->_sum2 < ci2->_sum2;
if (col==3) {
uint64 cc1 = ci1->_cc;
uint64 cc2 = ci2->_cc;
if (cc1 == 0) cc1 = 1;
if (cc2 == 0) cc2 = 1;
return (ci1->_sum2 / cc1) < (ci2->_sum2 / cc2);
}
if (col==4)
return ci1->_cc < ci2->_cc;
return QTreeWidgetItem::operator <(other);
}
|