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

kcachegrind

  • sources
  • kde-4.12
  • kdesdk
  • kcachegrind
  • libviews
eventtypeitem.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2003 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 /*
20  * Items of event type view.
21  */
22 
23 #include "eventtypeitem.h"
24 
25 #include <QPixmap>
26 
27 #include "globalconfig.h"
28 #include "listutils.h"
29 
30 
31 // EventTypeItem
32 
33 
34 EventTypeItem::EventTypeItem(TraceCostItem* costItem,
35  EventType* ct, ProfileContext::Type gt)
36 {
37  _costItem = costItem;
38  _eventType = ct;
39  _groupType = gt;
40 
41  setTextAlignment(1, Qt::AlignRight);
42  setTextAlignment(2, Qt::AlignRight);
43  setTextAlignment(3, Qt::AlignRight);
44  setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
45 
46  if (ct) {
47  setText(0, ct->longName());
48  setText(3, ct->name());
49  setText(5, ct->parsedFormula());
50  QString formula = ct->formula();
51  if (!ct->isReal()) {
52  setText(4, "=");
53  // we have a virtual type: allow editing
54  // FIXME: How to enable this only for columns 0,3,5 ?!
55  setFlags(flags() | Qt::ItemIsEditable);
56  }
57  }
58  else {
59  setText(0, QObject::tr("Unknown Type"));
60  }
61  update();
62 }
63 
64 void EventTypeItem::setGroupType(ProfileContext::Type gt)
65 {
66  if (_groupType == gt) return;
67 
68  _groupType = gt;
69  update();
70 }
71 
72 void EventTypeItem::update()
73 {
74  TraceData* d = _costItem ? _costItem->data() : 0;
75  double total = d ? ((double)d->subCost(_eventType)) : 0.0;
76 
77  if (total == 0.0) {
78  setText(1, "-");
79  setIcon(1, QIcon());
80  setText(2, "-");
81  setIcon(2, QIcon());
82  return;
83  }
84 
85  TraceFunction* f = (_costItem && _costItem->type()==ProfileContext::Function) ?
86  (TraceFunction*)_costItem : 0;
87 
88  ProfileCostArray* selfTotalCost = f ? f->data() : d;
89  if (f && GlobalConfig::showExpanded()) {
90  ProfileCostArray* parent = 0;
91  switch(_groupType) {
92  case ProfileContext::Object: parent = f->object(); break;
93  case ProfileContext::Class: parent = f->cls(); break;
94  case ProfileContext::File: parent = f->file(); break;
95  case ProfileContext::FunctionCycle: parent = f->cycle(); break;
96  default: break;
97  }
98  if (parent) selfTotalCost = parent;
99  }
100  if (_costItem && _costItem->type()==ProfileContext::FunctionCycle) {
101  f = (TraceFunction*)_costItem;
102  selfTotalCost = f->data();
103  }
104 
105  double selfTotal = selfTotalCost->subCost(_eventType);
106 
107  // for all cost items there is a self cost
108  _pure = _costItem ? _costItem->subCost(_eventType) : SubCost(0);
109  double pure = 100.0 * _pure / selfTotal;
110  if (GlobalConfig::showPercentage()) {
111  setText(2, QString("%1")
112  .arg(pure, 0, 'f', GlobalConfig::percentPrecision()));
113  }
114  else if (_costItem)
115  setText(2, _costItem->prettySubCost(_eventType));
116 
117  setIcon(2, QIcon(costPixmap(_eventType, _costItem, selfTotal, false)));
118 
119  if (!f) {
120  setText(1, "-");
121  setIcon(1, QIcon());
122  return;
123  }
124 
125  _sum = f->inclusive()->subCost(_eventType);
126  double sum = 100.0 * _sum / total;
127  if (GlobalConfig::showPercentage()) {
128  setText(1, QString("%1")
129  .arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
130  }
131  else
132  setText(1, _sum.pretty());
133 
134  setIcon(1, QIcon(costPixmap(_eventType, f->inclusive(), total, false)));
135 }
136 
137 bool EventTypeItem::operator<(const QTreeWidgetItem &other) const
138 {
139  int col = treeWidget()->sortColumn();
140  EventTypeItem* o = (EventTypeItem*) &other;
141  if (col==0)
142  return _sum < o->_sum;
143  if (col==1)
144  return _pure < o->_pure;
145 
146  return QTreeWidgetItem::operator<(other);
147 }
148 
149 QVariant EventTypeItem::data(int column, int role) const
150 {
151  if ((column == 5) && (role == Qt::EditRole))
152  return QVariant(_eventType->formula());
153  return QTreeWidgetItem::data(column, role);
154 }
155 
156 
GlobalConfig::showPercentage
static bool showPercentage()
Definition: globalconfig.cpp:328
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
globalconfig.h
ProfileContext::FunctionCycle
Definition: context.h:46
ProfileContext::File
Definition: context.h:48
EventType::parsedFormula
QString parsedFormula()
Definition: eventtype.cpp:161
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
EventTypeItem::data
QVariant data(int column, int role) const
Definition: eventtypeitem.cpp:149
ProfileCostArray::prettySubCost
QString prettySubCost(EventType *)
Returns a cost attribute converted to a string (with space after every 3 digits)
Definition: costitem.cpp:601
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceCostItem
Definition: tracedata.h:980
TraceFunction::object
TraceObject * object() const
Definition: tracedata.h:1164
TraceFunction::cycle
TraceFunctionCycle * cycle()
Definition: tracedata.h:1200
EventType
A cost type, e.g.
Definition: eventtype.h:43
ProfileContext::Class
Definition: context.h:47
TraceFunction::cls
TraceClass * cls() const
Definition: tracedata.h:1162
EventTypeItem
Definition: eventtypeitem.h:30
ProfileCostArray
An array of basic cost metrics for a trace item.
Definition: costitem.h:144
eventtypeitem.h
listutils.h
EventType::formula
const QString & formula()
Definition: eventtype.h:67
EventTypeItem::setGroupType
void setGroupType(ProfileContext::Type)
Definition: eventtypeitem.cpp:64
EventTypeItem::EventTypeItem
EventTypeItem(TraceCostItem *costItem, EventType *ct, ProfileContext::Type gt)
Definition: eventtypeitem.cpp:34
CostItem::data
virtual TraceData * data()
Definition: costitem.cpp:111
TraceFunction::file
TraceFile * file() const
Definition: tracedata.h:1163
EventType::isReal
bool isReal()
Definition: eventtype.h:70
EventTypeItem::operator<
bool operator<(const QTreeWidgetItem &other) const
Definition: eventtypeitem.cpp:137
QTreeWidgetItem
EventTypeItem::update
void update()
Definition: eventtypeitem.cpp:72
GlobalConfig::showExpanded
static bool showExpanded()
Definition: globalconfig.cpp:333
GlobalConfig::percentPrecision
static int percentPrecision()
Definition: globalconfig.cpp:385
EventTypeItem::costItem
TraceCostItem * costItem()
Definition: eventtypeitem.h:38
ProfileContext::Type
Type
Definition: context.h:36
SubCost
Cost event counter, simple wrapper around a 64bit entity.
Definition: subcost.h:32
EventType::longName
const QString & longName()
Definition: eventtype.h:66
SubCost::pretty
QString pretty(char sep= ' ') const
Convert SubCost value into a QString, spaced every 3 digits.
Definition: subcost.cpp:46
ProfileContext::Object
Definition: context.h:49
TraceData
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
Definition: tracedata.h:1363
costPixmap
QPixmap costPixmap(EventType *ct, ProfileCostArray *cost, double total, bool framed)
Definition: listutils.cpp:217
TraceInclusiveCost::inclusive
ProfileCostArray * inclusive()
Definition: tracedata.cpp:163
EventType::name
const QString & name()
Definition: eventtype.h:65
ProfileContext::Function
Definition: context.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:27 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
  • okteta
  • 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