• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kcachegrind

  • sources
  • kde-4.14
  • kdesdk
  • kcachegrind
  • libviews
partlistitem.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2003-2011 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3 
4  KCachegrind is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "partlistitem.h"
20 
21 #include <math.h>
22 
23 #include <QPixmap>
24 
25 #include "listutils.h"
26 #include "coverage.h"
27 #include "globalconfig.h"
28 
29 
30 // PartListItem
31 
32 PartListItem::PartListItem(QTreeWidget* parent, TraceCostItem* costItem,
33  EventType* et, ProfileContext::Type gt,
34  TracePart* part)
35  :QTreeWidgetItem(parent)
36 {
37  _partCostItem = costItem->findDepFromPart(part);
38  _part = part;
39  _groupType = gt;
40  _eventType = et;
41 
42  setTextAlignment(0, Qt::AlignRight);
43  setTextAlignment(1, Qt::AlignRight);
44  setTextAlignment(2, Qt::AlignRight);
45 
46  setText(0, _part->prettyName());
47 
48  if (_part->trigger().isEmpty())
49  setText(4, QObject::tr("(none)"));
50  else
51  setText(4, _part->trigger());
52 
53  update();
54 }
55 
56 void PartListItem::setEventType(EventType* et)
57 {
58  if (_eventType == et) return;
59 
60  _eventType = et;
61  update();
62 }
63 
64 void PartListItem::setGroupType(ProfileContext::Type gt)
65 {
66  if (_groupType == gt) return;
67 
68  _groupType = gt;
69  update();
70 }
71 
72 void PartListItem::update()
73 {
74  TracePartFunction* pf;
75  pf = !_partCostItem ? 0 :
76  (_partCostItem->type()==ProfileContext::PartFunction) ?
77  ((TracePartFunction*)_partCostItem) : 0;
78 
79  double total = _part->subCost(_eventType);
80 
81  ProfileCostArray* selfTotalCost = _part;
82  if (pf && GlobalConfig::showExpanded()) {
83  switch(_groupType) {
84  case ProfileContext::Object: selfTotalCost = pf->partObject(); break;
85  case ProfileContext::Class: selfTotalCost = pf->partClass(); break;
86  case ProfileContext::File: selfTotalCost = pf->partFile(); break;
87  default: break;
88  }
89  }
90  double selfTotal = selfTotalCost->subCost(_eventType);
91 
92  _pure = _partCostItem ? _partCostItem->subCost(_eventType) : SubCost(0);
93  _sum = pf ? pf->inclusive()->subCost(_eventType) : SubCost(0);
94 
95  if (selfTotal == 0 || !_partCostItem) {
96  setText(2, QString("-"));
97  setIcon(2, QPixmap());
98  }
99  else {
100  double pure = 100.0 * _pure / selfTotal;
101  if (GlobalConfig::showPercentage()) {
102  setText(2, QString("%1")
103  .arg(pure, 0, 'f', GlobalConfig::percentPrecision()));
104  }
105  else
106  setText(2, _partCostItem->prettySubCost(_eventType));
107 
108  setIcon(2, costPixmap(_eventType, _partCostItem, selfTotal, false));
109  }
110 
111  if (total == 0 || !pf) {
112  setText(1, QString("-"));
113  setIcon(1, QPixmap());
114  }
115  else {
116  double sum = 100.0 * _sum / total;
117  if (GlobalConfig::showPercentage()) {
118  setText(1, QString("%1")
119  .arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
120  }
121  else
122  setText(1, _sum.pretty());
123 
124  setIcon(1, costPixmap(_eventType, pf->inclusive(), total, false));
125  }
126 
127  if (!pf) {
128  setText(3, QString("-"));
129  _callCount = 0;
130  return;
131  }
132 
133  SubCost callCount;
134  QString str;
135 
136  callCount = 0;
137  foreach(TracePartCall* pc, pf->partCallers())
138  callCount += pc->callCount();
139 
140  if ((callCount == 0) && (pf->calledContexts()>0))
141  str = QObject::tr("(active)");
142  else
143  str = callCount.pretty();
144 
145  _callCount = callCount;
146  setText(3, str);
147 }
148 
149 bool PartListItem::operator<(const QTreeWidgetItem& other) const
150 {
151  const PartListItem* pi1 = this;
152  const PartListItem* pi2 = (PartListItem*) &other;
153  int col = treeWidget()->sortColumn();
154 
155  if (col==0)
156  return (*(pi1->_part) < *(pi2->_part));
157 
158  if (col==1)
159  return (pi1->_sum < pi2->_sum);
160 
161  if (col==2)
162  return (pi1->_pure < pi2->_pure);
163 
164  if (col==3)
165  return (pi1->_callCount < pi2->_callCount);
166 
167  return QTreeWidgetItem::operator <(other);
168 }
PartListItem::PartListItem
PartListItem(QTreeWidget *parent, TraceCostItem *costItem, EventType *ct, ProfileContext::Type gt, TracePart *part)
Definition: partlistitem.cpp:32
GlobalConfig::showPercentage
static bool showPercentage()
Definition: globalconfig.cpp:328
partlistitem.h
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
globalconfig.h
QTreeWidget::sortColumn
int sortColumn() const
ProfileContext::File
Definition: context.h:48
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
TracePartFunction::partObject
TracePartObject * partObject()
Definition: tracedata.h:559
ProfileCostArray::prettySubCost
QString prettySubCost(EventType *)
Returns a cost attribute converted to a string (with space after every 3 digits)
Definition: costitem.cpp:601
TraceCostItem
Definition: tracedata.h:980
QTreeWidgetItem::setIcon
void setIcon(int column, const QIcon &icon)
PartListItem
For info tab, trace part list.
Definition: partlistitem.h:33
TraceCallCost::callCount
SubCost callCount()
Definition: tracedata.cpp:125
TracePart::prettyName
QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
Definition: tracedata.cpp:3025
TracePartFunction::calledContexts
int calledContexts()
Definition: tracedata.cpp:752
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
PartListItem::setEventType
void setEventType(EventType *ct)
Definition: partlistitem.cpp:56
EventType
A cost type, e.g.
Definition: eventtype.h:43
ProfileContext::Class
Definition: context.h:47
PartListItem::part
TracePart * part()
Definition: partlistitem.h:43
QTreeWidget
ProfileContext::PartFunction
Definition: context.h:46
TraceInclusiveListCost::findDepFromPart
TraceInclusiveCost * findDepFromPart(TracePart *)
Definition: tracedata.cpp:438
QTreeWidgetItem::operator<
virtual bool operator<(const QTreeWidgetItem &other) const
ProfileCostArray
An array of basic cost metrics for a trace item.
Definition: costitem.h:144
TracePartFunction::partFile
TracePartFile * partFile()
Definition: tracedata.h:561
listutils.h
TracePart::trigger
QString trigger() const
Definition: tracedata.h:669
QString::isEmpty
bool isEmpty() const
coverage.h
PartListItem::setGroupType
void setGroupType(ProfileContext::Type)
Definition: partlistitem.cpp:64
QString
QTreeWidgetItem::treeWidget
QTreeWidget * treeWidget() const
TracePartFunction
Cost of a function, from a single trace file.
Definition: tracedata.h:543
QPixmap
TracePartCall
Cost of a call at a function to another function, from a single trace file.
Definition: tracedata.h:516
TracePart
A Trace Part: All data read from a trace file, containing all costs that happened in a specified time...
Definition: tracedata.h:655
GlobalConfig::showExpanded
static bool showExpanded()
Definition: globalconfig.cpp:333
QTreeWidgetItem
GlobalConfig::percentPrecision
static int percentPrecision()
Definition: globalconfig.cpp:385
ProfileContext::Type
Type
Definition: context.h:36
SubCost
Cost event counter, simple wrapper around a 64bit entity.
Definition: subcost.h:32
QTreeWidgetItem::setText
void setText(int column, const QString &text)
SubCost::pretty
QString pretty(char sep= ' ') const
Convert SubCost value into a QString, spaced every 3 digits.
Definition: subcost.cpp:46
PartListItem::operator<
bool operator<(const QTreeWidgetItem &other) const
Definition: partlistitem.cpp:149
QTreeWidgetItem::setTextAlignment
void setTextAlignment(int column, int alignment)
ProfileContext::Object
Definition: context.h:49
TracePartFunction::partClass
TracePartClass * partClass()
Definition: tracedata.h:560
TracePartFunction::partCallers
const TracePartCallList & partCallers()
Definition: tracedata.h:562
costPixmap
QPixmap costPixmap(EventType *ct, ProfileCostArray *cost, double total, bool framed)
Definition: listutils.cpp:217
PartListItem::update
void update()
Definition: partlistitem.cpp:72
TraceInclusiveCost::inclusive
ProfileCostArray * inclusive()
Definition: tracedata.cpp:163
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:39:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kcachegrind

Skip menu "kcachegrind"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal