• 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
  • cgview
cgview/main.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2008 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 <QCoreApplication>
20 #include <QTextStream>
21 
22 #include "tracedata.h"
23 #include "loader.h"
24 #include "config.h"
25 #include "globalconfig.h"
26 #include "logger.h"
27 
28 /*
29  * Just a simple command line tool using libcore
30  */
31 
32 void showHelp(QTextStream& out, bool fullHelp = true)
33 {
34  out << "Show profiles from callgrind files. (C) 2010 J. Weidendorfer\n";
35 
36  if (!fullHelp)
37  out << "Type 'cgview -h' for help." << endl;
38  else
39  out << "Usage: cgview [options] <file> ...\n\n"
40  "Options:\n"
41  " -h Show this help text\n"
42  " -e Sort list according to exclusive cost\n"
43  " -s <ev> Sort and show counters for event <ev>\n"
44  " -c Sort by call count\n"
45  " -b Show butterfly (callers and callees)\n"
46  " -n Do not detect recursive cycles" << endl;
47 
48  exit(1);
49 }
50 
51 
52 int main(int argc, char** argv)
53 {
54  QCoreApplication app(argc, argv);
55  QTextStream out(stdout);
56 
57  Loader::initLoaders();
58  ConfigStorage::setStorage(new ConfigStorage);
59  GlobalConfig::config()->addDefaultTypes();
60 
61  QStringList list = app.arguments();
62  list.pop_front();
63  if (list.isEmpty()) showHelp(out, false);
64 
65  bool sortByExcl = false;
66  bool sortByCount = false;
67  bool showCalls = false;
68  QString showEvent;
69  QStringList files;
70 
71  for(int arg = 0; arg<list.count(); arg++) {
72  if (list[arg] == "-h") showHelp(out);
73  else if (list[arg] == "-e") sortByExcl = true;
74  else if (list[arg] == "-n") GlobalConfig::setShowCycles(false);
75  else if (list[arg] == "-b") showCalls = true;
76  else if (list[arg] == "-c") sortByCount = true;
77  else if (list[arg] == "-s") showEvent = list[++arg];
78  else
79  files << list[arg];
80  }
81  TraceData* d = new TraceData(new Logger);
82  d->load(files);
83 
84  EventTypeSet* m = d->eventTypes();
85  if (m->realCount() == 0) {
86  out << "Error: No event types found." << endl;
87  return 1;
88  }
89 
90  out << "\nTotals for event types:\n";
91 
92  QString p;
93  EventType* et;
94  for (int i=0;i<m->realCount();i++) {
95  et = m->realType(i);
96  out.setFieldWidth(14);
97  out.setFieldAlignment(QTextStream::AlignRight);
98  out << d->subCost(et).pretty();
99  out.setFieldWidth(0);
100  out << " " << et->longName() << " (" << et->name() << ")\n";
101  }
102  for (int i=0;i<m->derivedCount();i++) {
103  et = m->derivedType(i);
104  out.setFieldWidth(14);
105  out.setFieldAlignment(QTextStream::AlignRight);
106  out << d->subCost(et).pretty();
107  out.setFieldWidth(0);
108  out << " " << et->longName() <<
109  " (" << et->name() << " = " << et->formula() << ")\n";
110  }
111  out << endl;
112 
113  if (showEvent.isEmpty())
114  et = m->realType(0);
115  else {
116  et = m->type(showEvent);
117  if (!et) {
118  out << "Error: event '" << showEvent << "' not found." << endl;
119  return 1;
120  }
121  }
122  Q_ASSERT( et!=0 );
123  out << "Sorted by: " << (sortByExcl ? "Exclusive ":"Inclusive ")
124  << et->longName() << " (" << et->name() << ")" << endl;
125 
126  QList<TraceFunction*> flist;
127  HighestCostList hc;
128  hc.clear(50);
129  TraceFunctionMap::Iterator it;
130  for ( it = d->functionMap().begin(); it != d->functionMap().end(); ++it )
131  flist.append(&(*it));
132 
133  TraceFunction *f;
134  foreach(f, d->functionCycles())
135  flist.append(f);
136 
137  foreach(f, flist) {
138  if (sortByCount)
139  hc.addCost(f, f->calledCount());
140  else if (sortByExcl)
141  hc.addCost(f, f->subCost(et));
142  else
143  hc.addCost(f, f->inclusive()->subCost(et));
144  }
145 
146 
147  out << "\n Inclusive Exclusive Called Function name (DSO)\n";
148  out << " ==================================================================\n";
149 
150  out.setFieldAlignment(QTextStream::AlignRight);
151  for(int i=0; i<hc.realCount(); i++) {
152  f = (TraceFunction*)hc[i];
153 
154  if (showCalls) {
155  if (i>0) out << endl;
156  foreach(TraceCall* c, f->callers()) {
157  out << " ";
158  out.setFieldWidth(14);
159  out << c->subCost(et).pretty();
160  out.setFieldWidth(0);
161  out << " ";
162  out.setFieldWidth(13);
163  out << c->prettyCallCount();
164  out.setFieldWidth(0);
165  out << " < " << c->caller()->prettyName() << endl;
166  }
167  }
168 
169  out.setFieldWidth(14);
170  out << f->inclusive()->subCost(et).pretty();
171  out << f->subCost(et).pretty();
172  out.setFieldWidth(13);
173  out << f->prettyCalledCount();
174  out.setFieldWidth(0);
175  out << " " << f->name() << " (" << f->object()->name() << ")" << endl;
176 
177  if (showCalls) {
178  foreach(TraceCall* c, f->callings()) {
179  out << " ";
180  out.setFieldWidth(14);
181  out << c->subCost(et).pretty();
182  out.setFieldWidth(0);
183  out << " ";
184  out.setFieldWidth(13);
185  out << c->prettyCallCount();
186  out.setFieldWidth(0);
187  out << " > " << c->called()->prettyName() << endl;
188  }
189  }
190 
191  }
192 }
193 
Logger
Definition: logger.h:32
EventTypeSet::realCount
int realCount()
Definition: eventtype.h:133
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
globalconfig.h
ConfigStorage::setStorage
static void setStorage(ConfigStorage *)
Definition: config.cpp:88
TraceFunction::callings
const TraceCallList & callings(bool skipCycle=false) const
Definition: tracedata.cpp:2302
TraceCall::caller
TraceFunction * caller(bool skipCycle=false) const
Definition: tracedata.cpp:1230
TraceFunction
A traced function.
Definition: tracedata.h:1122
Loader::initLoaders
static void initLoaders()
Definition: loader.cpp:73
HighestCostList::clear
void clear(int maxSize)
Definition: subcost.cpp:75
TraceFunction::object
TraceObject * object() const
Definition: tracedata.h:1164
config.h
GlobalConfig::config
static GlobalConfig * config()
Definition: globalconfig.cpp:145
EventTypeSet::type
EventType * type(int)
Definition: eventtype.cpp:475
TraceData::eventTypes
EventTypeSet * eventTypes()
Definition: tracedata.h:1407
TraceFunction::callers
TraceCallList callers(bool skipCycle=false) const
Definition: tracedata.cpp:2278
EventType
A cost type, e.g.
Definition: eventtype.h:43
tracedata.h
GlobalConfig::setShowCycles
static void setShowCycles(bool)
Definition: globalconfig.cpp:364
HighestCostList::realCount
int realCount()
Definition: subcost.h:86
loader.h
HighestCostList
A class to calculate the ProfileCostArray items with highest cost.
Definition: subcost.h:78
TraceData::load
int load(QStringList files)
Loads profile data files.
Definition: tracedata.cpp:3130
TraceData::functionCycles
const TraceFunctionCycleList & functionCycles()
Definition: tracedata.h:1443
EventType::formula
const QString & formula()
Definition: eventtype.h:67
TraceCallCost::prettyCallCount
QString prettyCallCount()
Definition: tracedata.cpp:114
ConfigStorage
This is an adapter class for different configuration backends.
Definition: config.h:63
TraceCostItem::name
virtual QString name() const
Returns dynamic name info (without type)
Definition: tracedata.h:986
TraceFunction::prettyName
QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
Definition: tracedata.cpp:1889
EventTypeSet::derivedCount
int derivedCount()
Definition: eventtype.h:134
showHelp
void showHelp(QTextStream &out, bool fullHelp=true)
Definition: cgview/main.cpp:32
HighestCostList::addCost
void addCost(ProfileCostArray *, SubCost)
Definition: subcost.cpp:83
EventTypeSet::realType
EventType * realType(int)
Definition: eventtype.cpp:462
logger.h
TraceFunction::calledCount
SubCost calledCount()
Definition: tracedata.cpp:2239
TraceCall::called
TraceFunction * called(bool skipCycle=false) const
Definition: tracedata.cpp:1235
EventType::longName
const QString & longName()
Definition: eventtype.h:66
GlobalConfig::addDefaultTypes
void addDefaultTypes()
Definition: globalconfig.cpp:287
SubCost::pretty
QString pretty(char sep= ' ') const
Convert SubCost value into a QString, spaced every 3 digits.
Definition: subcost.cpp:46
EventTypeSet
A class for managing a set of event types.
Definition: eventtype.h:117
TraceData::functionMap
TraceFunctionMap & functionMap()
Definition: tracedata.h:1441
TraceData
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
Definition: tracedata.h:1363
EventTypeSet::derivedType
EventType * derivedType(int)
Definition: eventtype.cpp:468
TraceCall
A call from one to another function.
Definition: tracedata.h:835
TraceFunction::prettyCalledCount
QString prettyCalledCount()
Definition: tracedata.cpp:2267
TraceInclusiveCost::inclusive
ProfileCostArray * inclusive()
Definition: tracedata.cpp:163
EventType::name
const QString & name()
Definition: eventtype.h:65
QList
main
int main(int argc, char **argv)
Definition: cgview/main.cpp:52
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