• 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
coverageview.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  * Coverage Views
21  */
22 
23 
24 #include "coverageview.h"
25 
26 #include <QAction>
27 #include <QMenu>
28 #include <QHeaderView>
29 #include <QKeyEvent>
30 
31 #include "globalconfig.h"
32 #include "coverageitem.h"
33 #include "coverage.h"
34 
35 
36 //
37 // CoverageView
38 //
39 
40 
41 CoverageView::CoverageView(bool showCallers, TraceItemView* parentView, QWidget* parent)
42  : QTreeWidget(parent), TraceItemView(parentView)
43 {
44  _showCallers = showCallers;
45 
46  QStringList labels;
47  labels << tr( "Incl." );
48  if (_showCallers) {
49  setColumnCount(4);
50  labels << tr( "Distance" ),
51  labels << tr( "Called" ),
52  labels << tr( "Caller" );
53  }
54  else {
55  setColumnCount(5);
56  labels << tr( "Self" ),
57  labels << tr( "Distance" ),
58  labels << tr( "Calling" ),
59  labels << tr( "Callee" );
60  }
61  setHeaderLabels(labels);
62 
63  // forbid scaling icon pixmaps to smaller size
64  setIconSize(QSize(99,99));
65  setAllColumnsShowFocus(true);
66  setRootIsDecorated(false);
67  setUniformRowHeights(true);
68  // sorting will be enabled after refresh()
69  sortByColumn(0, Qt::DescendingOrder);
70  setMinimumHeight(50);
71 
72  this->setWhatsThis( whatsThis() );
73 
74  connect( this,
75  SIGNAL( currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
76  SLOT( selectedSlot(QTreeWidgetItem*,QTreeWidgetItem*) ) );
77 
78  setContextMenuPolicy(Qt::CustomContextMenu);
79  connect( this,
80  SIGNAL(customContextMenuRequested(const QPoint &) ),
81  SLOT(context(const QPoint &)));
82 
83  connect(this,
84  SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
85  SLOT(activatedSlot(QTreeWidgetItem*,int)));
86 
87  connect(header(), SIGNAL(sectionClicked(int)),
88  this, SLOT(headerClicked(int)));
89 }
90 
91 QString CoverageView::whatsThis() const
92 {
93  return _showCallers ?
94  tr( "<b>List of all Callers</b>"
95  "<p>This list shows all functions calling the "
96  "current selected one, either directly or with "
97  "several functions in-between on the stack; the "
98  "number of functions in-between plus one "
99  "is called the <em>Distance</em> (e.g. "
100  "for function A,B,C there exists a call from "
101  "A to C when A calls B and B calls C, i.e. "
102  "A => B => C. The distance here is 2).</p>"
103 
104  "<p>Absolute cost shown is the cost spent in the "
105  "selected function while a listed function is active; "
106  "relative cost is the percentage of all cost spent in "
107  "the selected function while the listed one is "
108  "active. The cost graphic shows logarithmic "
109  "percentage with a different color for each "
110  "distance.</p>"
111 
112  "<p>As there can be many calls from the same function, "
113  "the distance column sometimes shows "
114  "the range of distances for all "
115  "calls happening; then, in parentheses, there is the "
116  "medium distance, i.e. the distance where most of the "
117  "call costs happened.</p>"
118 
119  "<p>Selecting a function makes it the current selected "
120  "one of this information panel. "
121  "If there are two panels (Split mode), the "
122  "function of the other panel is changed instead.</p>") :
123 
124  tr( "<b>List of all Callees</b>"
125  "<p>This list shows all functions called by the "
126  "current selected one, either directly or with "
127  "several function in-between on the stack; the "
128  "number of function in-between plus one "
129  "is called the <em>Distance</em> (e.g. "
130  "for function A,B,C there exists a call from "
131  "A to C when A calls B and B calls C, i.e. "
132  "A => B => C. The distance here is 2).</p>"
133 
134  "<p>Absolute cost shown is the cost spent in the "
135  "listed function while the selected is active; "
136  "relative cost is the percentage of all cost spent in "
137  "the listed function while the selected one is active. "
138  "The cost graphic always shows logarithmic "
139  "percentage with a different color for each "
140  "distance.</p>"
141 
142  "<p>As there can be many calls to the same function, "
143  "the distance column sometimes shows "
144  "the range of distances for all "
145  "calls happening; then, in parentheses, there is the "
146  "medium distance, i.e. the distance where most of the "
147  "call costs happened.</p>"
148 
149  "<p>Selecting a function makes it the current selected "
150  "one of this information panel. "
151  "If there are two panels (Split mode), the "
152  "function of the other panel is changed instead.</p>");
153 }
154 
155 void CoverageView::context(const QPoint & p)
156 {
157  int c = columnAt(p.x());
158  QTreeWidgetItem* i = itemAt(p);
159  QMenu popup;
160 
161  TraceFunction* f = 0;
162  if (i) {
163  f = _showCallers ?
164  ((CallerCoverageItem*)i)->function() :
165  ((CalleeCoverageItem*)i)->function();
166  }
167 
168  QAction* activateFunctionAction = 0;
169  if (f) {
170  QString menuText = tr("Go to '%1'").arg(GlobalConfig::shortenSymbol(f->prettyName()));
171  activateFunctionAction = popup.addAction(menuText);
172  popup.addSeparator();
173  }
174 
175  if ((c == 0) || (!_showCallers && c == 1)) {
176  addEventTypeMenu(&popup, false);
177  popup.addSeparator();
178  }
179  addGoMenu(&popup);
180 
181  QAction* a = popup.exec(mapToGlobal(p + QPoint(0,header()->height())));
182  if (a == activateFunctionAction)
183  TraceItemView::activated(f);
184 }
185 
186 void CoverageView::selectedSlot(QTreeWidgetItem* i, QTreeWidgetItem*)
187 {
188  TraceFunction* f = 0;
189  if (i) {
190  f = _showCallers ?
191  ((CallerCoverageItem*)i)->function() :
192  ((CalleeCoverageItem*)i)->function();
193  }
194 
195  if (f) {
196  _selectedItem = f;
197  selected(f);
198  }
199 }
200 
201 void CoverageView::activatedSlot(QTreeWidgetItem* i, int)
202 {
203  TraceFunction* f = 0;
204  if (i) {
205  f = _showCallers ?
206  ((CallerCoverageItem*)i)->function() :
207  ((CalleeCoverageItem*)i)->function();
208  }
209 
210  if (f) TraceItemView::activated(f);
211 }
212 
213 void CoverageView::headerClicked(int col)
214 {
215  // distance and name columns should be sortable in both ways
216  if (_showCallers) {
217  if ((col == 1) || (col==3)) return;
218  }
219  else {
220  if ((col == 2) || (col==4)) return;
221  }
222 
223  // all others only descending
224  sortByColumn(col, Qt::DescendingOrder);
225 }
226 
227 void CoverageView::keyPressEvent(QKeyEvent* event)
228 {
229  QTreeWidgetItem *item = currentItem();
230  if (item && ((event->key() == Qt::Key_Return) ||
231  (event->key() == Qt::Key_Space)))
232  {
233  TraceFunction* f;
234  f = _showCallers ?
235  ((CallerCoverageItem*)item)->function() :
236  ((CalleeCoverageItem*)item)->function();
237  TraceItemView::activated(f);
238  }
239  QTreeView::keyPressEvent(event);
240 }
241 
242 CostItem* CoverageView::canShow(CostItem* i)
243 {
244  ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
245 
246  switch(t) {
247  case ProfileContext::Function:
248  case ProfileContext::FunctionCycle:
249  return i;
250  default:
251  break;
252  }
253  return 0;
254 }
255 
256 void CoverageView::doUpdate(int changeType, bool)
257 {
258  // Special case ?
259  if (changeType == selectedItemChanged) {
260 
261  if (!_selectedItem) {
262  clearSelection();
263  return;
264  }
265 
266  TraceFunction* f = 0;
267  QTreeWidgetItem* i = currentItem();
268  if (i) {
269  f = _showCallers ?
270  ((CallerCoverageItem*)i)->function() :
271  ((CalleeCoverageItem*)i)->function();
272  }
273  if (f == _selectedItem) return;
274 
275  QTreeWidgetItem *item;
276  for (int i=0; i<topLevelItemCount(); i++) {
277  item = this->topLevelItem(i);
278  f = _showCallers ?
279  ((CallerCoverageItem*)item)->function() :
280  ((CalleeCoverageItem*)item)->function();
281  if (f == _selectedItem) {
282  scrollToItem(item);
283  setCurrentItem(item);
284  break;
285  }
286  }
287  return;
288  }
289 
290  if (changeType == groupTypeChanged) {
291  QTreeWidgetItem *item;
292  for (int i=0; i<topLevelItemCount();i++) {
293  item = topLevelItem(i);
294  if (_showCallers)
295  ((CallerCoverageItem*)item)->setGroupType(_groupType);
296  else
297  ((CalleeCoverageItem*)item)->setGroupType(_groupType);
298  }
299  return;
300  }
301 
302  refresh();
303 }
304 
305 void CoverageView::refresh()
306 {
307  clear();
308 
309  if (!_data || !_activeItem) return;
310 
311  ProfileContext::Type t = _activeItem->type();
312  TraceFunction* f = 0;
313  if (t == ProfileContext::Function) f = (TraceFunction*) _activeItem;
314  if (t == ProfileContext::FunctionCycle) f = (TraceFunction*) _activeItem;
315  if (!f) return;
316 
317 
318 
319  _hc.clear(GlobalConfig::maxListCount());
320  SubCost realSum = f->inclusive()->subCost(_eventType);
321 
322  TraceFunctionList l;
323  if (_showCallers)
324  l = Coverage::coverage(f, Coverage::Caller, _eventType);
325  else
326  l = Coverage::coverage(f, Coverage::Called, _eventType);
327 
328  foreach(TraceFunction* f2, l) {
329  Coverage* c = (Coverage*) f2->association(Coverage::Rtti);
330  if (c && (c->inclusive()>0.0))
331  _hc.addCost(f2, SubCost(realSum * c->inclusive()));
332  }
333 
334  QList<QTreeWidgetItem*> items;
335  QTreeWidgetItem* item;
336  TraceFunction* ff;
337  for(int i=0;i<_hc.realCount();i++) {
338  ff = (TraceFunction*) _hc[i];
339  Coverage* c = (Coverage*) ff->association(Coverage::Rtti);
340  if (_showCallers)
341  item = new CallerCoverageItem(0, c, f, _eventType, _groupType);
342  else
343  item = new CalleeCoverageItem(0, c, f, _eventType, _groupType);
344  items.append(item);
345  }
346  if (_hc.hasMore()) {
347  // a placeholder for all the functions skipped ...
348  ff = (TraceFunction*) _hc[_hc.maxSize()-1];
349  Coverage* c = (Coverage*) ff->association(Coverage::Rtti);
350  if (_showCallers)
351  item = new CallerCoverageItem(0, _hc.count() - _hc.maxSize(),
352  c, f, _eventType, _groupType);
353  else
354  item = new CalleeCoverageItem(0, _hc.count() - _hc.maxSize(),
355  c, f, _eventType, _groupType);
356  items.append(item);
357  }
358 
359  // when inserting, switch off sorting for performance reason
360  setSortingEnabled(false);
361  addTopLevelItems(items);
362  setSortingEnabled(true);
363  // enabling sorting switches on the indicator, but we want it off
364  header()->setSortIndicatorShown(false);
365  // resize to content now (section size still can be interactively changed)
366  header()->resizeSections(QHeaderView::ResizeToContents);
367 }
368 
369 #include "coverageview.moc"
Coverage::inclusive
double inclusive()
Definition: coverage.h:55
QWidget::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
QHeaderView::resizeSections
void resizeSections(QHeaderView::ResizeMode mode)
TraceItemView::selectedItemChanged
Definition: traceitemview.h:86
QWidget
TraceItemView::_selectedItem
CostItem * _selectedItem
Definition: traceitemview.h:211
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
HighestCostList::maxSize
int maxSize()
Definition: subcost.h:88
globalconfig.h
CoverageView::CoverageView
CoverageView(bool showCallers, TraceItemView *parentView, QWidget *parent=0)
Definition: coverageview.cpp:41
ProfileContext::FunctionCycle
Definition: context.h:46
coverageview.h
coverageitem.h
Coverage::coverage
static TraceFunctionList coverage(TraceFunction *f, CoverageMode m, EventType *ct)
Calculate coverage of all functions based on function f.
Definition: coverage.cpp:81
QTreeWidget::currentItemChanged
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
QTreeWidget::scrollToItem
void scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint)
TraceItemView::addEventTypeMenu
void addEventTypeMenu(QMenu *, bool withCost2=true)
Definition: traceitemview.cpp:466
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
CoverageView::whatsThis
QString whatsThis() const
Definition: coverageview.cpp:91
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceItemView::_data
TraceData * _data
Definition: traceitemview.h:209
QMenu::addAction
void addAction(QAction *action)
HighestCostList::clear
void clear(int maxSize)
Definition: subcost.cpp:75
TraceItemView::addGoMenu
void addGoMenu(QMenu *)
Definition: traceitemview.cpp:471
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
QTreeWidget::items
QList< QTreeWidgetItem * > items(const QMimeData *data) const
QTreeView::setUniformRowHeights
void setUniformRowHeights(bool uniform)
CostItem
Base class for cost items.
Definition: costitem.h:37
QHeaderView::setSortIndicatorShown
void setSortIndicatorShown(bool show)
QPoint
QTreeView::sortByColumn
void sortByColumn(int column, Qt::SortOrder order)
CoverageView::selectedSlot
void selectedSlot(QTreeWidgetItem *, QTreeWidgetItem *)
Definition: coverageview.cpp:186
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
TraceItemView::_groupType
ProfileContext::Type _groupType
Definition: traceitemview.h:213
CoverageView::headerClicked
void headerClicked(int)
Definition: coverageview.cpp:213
QPoint::x
int x() const
QTreeWidget::clear
void clear()
TraceItemView
Abstract Base Class for KCachegrind Views.
Definition: traceitemview.h:70
Coverage::Caller
Definition: coverage.h:40
TraceFunction::association
TraceAssociation * association(int rtti)
Definition: tracedata.cpp:1862
CoverageView::activatedSlot
void activatedSlot(QTreeWidgetItem *, int)
Definition: coverageview.cpp:201
QTreeWidget
TraceItemView::_eventType
EventType * _eventType
Definition: traceitemview.h:212
QList::append
void append(const T &value)
Coverage
Coverage of a function.
Definition: coverage.h:36
HighestCostList::realCount
int realCount()
Definition: subcost.h:87
QTreeWidget::addTopLevelItems
void addTopLevelItems(const QList< QTreeWidgetItem * > &items)
QAbstractItemView::setIconSize
void setIconSize(const QSize &size)
coverage.h
QTreeWidget::itemAt
QTreeWidgetItem * itemAt(const QPoint &p) const
TraceFunction::prettyName
QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
Definition: tracedata.cpp:1889
Coverage::Rtti
static const int Rtti
Definition: coverage.h:46
TraceItemView::_activeItem
CostItem * _activeItem
Definition: traceitemview.h:211
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QMenu::addSeparator
QAction * addSeparator()
QTreeWidget::currentItem
QTreeWidgetItem * currentItem() const
QString
QList
GlobalConfig::shortenSymbol
static QString shortenSymbol(const QString &)
Definition: globalconfig.cpp:395
QMenu::exec
QAction * exec()
QTreeWidget::setColumnCount
void setColumnCount(int columns)
QStringList
TraceItemView::selected
virtual void selected(TraceItemView *sender, CostItem *)
Notification from child views.
Definition: traceitemview.cpp:319
QKeyEvent::key
int key() const
QMenu
QSize
TraceItemView::activated
virtual void activated(TraceItemView *sender, CostItem *)
Definition: traceitemview.cpp:347
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
HighestCostList::addCost
void addCost(ProfileCostArray *, SubCost)
Definition: subcost.cpp:83
QTreeWidget::setCurrentItem
void setCurrentItem(QTreeWidgetItem *item)
QTreeWidget::setHeaderLabels
void setHeaderLabels(const QStringList &labels)
QKeyEvent
QTreeView::setSortingEnabled
void setSortingEnabled(bool enable)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
HighestCostList::count
int count()
Definition: subcost.h:86
CoverageView::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: coverageview.cpp:227
QTreeWidgetItem
ProfileContext::Type
Type
Definition: context.h:36
HighestCostList::hasMore
bool hasMore()
Definition: subcost.h:89
SubCost
Cost event counter, simple wrapper around a 64bit entity.
Definition: subcost.h:32
QAction
TraceItemView::groupTypeChanged
Definition: traceitemview.h:83
QWidget::setMinimumHeight
void setMinimumHeight(int minh)
Coverage::Called
Definition: coverage.h:40
QTreeView::header
QHeaderView * header() const
CalleeCoverageItem
Definition: coverageitem.h:59
CoverageView::context
void context(const QPoint &)
Definition: coverageview.cpp:155
QTreeWidget::topLevelItem
QTreeWidgetItem * topLevelItem(int index) const
QTreeView::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QTreeWidget::topLevelItemCount
int topLevelItemCount() const
QAbstractItemView::clearSelection
void clearSelection()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
GlobalConfig::maxListCount
static int maxListCount()
Definition: globalconfig.cpp:402
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QTreeWidget::itemDoubleClicked
void itemDoubleClicked(QTreeWidgetItem *item, int column)
QTreeView::columnAt
int columnAt(int x) const
QWidget::height
int height() const
TraceInclusiveCost::inclusive
ProfileCostArray * inclusive()
Definition: tracedata.cpp:163
ProfileContext::Function
Definition: context.h:46
ProfileContext::InvalidType
Definition: context.h:37
CallerCoverageItem
Definition: coverageitem.h:31
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