edbee - Qt Editor Library
simpleprofiler.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 //#include "config.h"
9 
10 #include <QString>
11 #include <QStack>
12 #include <QMap>
13 
14 
15 namespace edbee {
16 
17 #ifdef CONFIG_PROFILE
18 
19 #define PROF_BEGIN \
20  SimpleProfiler::instance()->begin( __FILE__, __LINE__, __func__, 0 );
21 
22 #define PROF_END \
23  SimpleProfiler::instance()->end();
24 
25 #define PROF_BEGIN_NAMED(name) \
26  SimpleProfiler::instance()->begin( __FILE__, __LINE__, __func__, name );
27 
28 #else
29 #define PROF_BEGIN
30 #define PROF_END
31 #define PROF_BEGIN_NAMED(name)
32 #endif
33 
34 
36 
41 {
42 
43 public:
44 
45  static SimpleProfiler* instance();
46 
47 
49  class ProfilerItem {
50  public:
51  ProfilerItem( const char* filename, int line, const char* function, const char* name );
52  const char* filename() const { return filename_; }
53  int line() const { return line_; }
54  const char* function() const { return function_; }
55  const char* name() const { return name_; }
56  int callCount() const { return callCount_; }
57  qint64 duration() const { return duration_; }
58  qint64 childDuration() const { return childDuration_; }
59  qint64 durationWithoutChilds() const { return duration_ - childDuration_; }
60 
61  void incCallCount() { ++callCount_; }
62  void addDuration( qint64 duration ) { duration_ += duration; }
64 
65  protected:
66  const char* filename_;
67  int line_;
68  const char* function_;
69  const char* name_;
70 
71  int callCount_;
72  qint64 duration_;
73  qint64 childDuration_;
74  };
75 
79  qint64 startTime;
80  };
81 
82 
83 
85  virtual ~SimpleProfiler();
86 
87 
88  void begin( const char* file, int line, const char* function, const char* name );
89  void end();
90 
91  void dumpResults();
92 
93 
94 protected:
95 
96  QMap<QString,ProfilerItem*> statsMap_;
97  QStack<ProfileStackItem> stack_;
98 };
99 
100 
101 
102 } // edbee
const char * function_
The function/method name.
Definition: simpleprofiler.h:68
qint64 durationWithoutChilds() const
Definition: simpleprofiler.h:59
virtual ~SimpleProfiler()
destroy the stuff
Definition: simpleprofiler.cpp:39
qint64 duration_
The total duration.
Definition: simpleprofiler.h:72
SimpleProfiler()
Definition: simpleprofiler.cpp:33
const char * name_
The custom name.
Definition: simpleprofiler.h:69
QMap< QString, ProfilerItem * > statsMap_
The statistics.
Definition: simpleprofiler.h:96
static SimpleProfiler * instance()
This method returns the profile instance.
Definition: simpleprofiler.cpp:13
void incCallCount()
Definition: simpleprofiler.h:61
QStack< ProfileStackItem > stack_
The current items being processed.
Definition: simpleprofiler.h:97
const char * filename() const
Definition: simpleprofiler.h:52
int line_
The line.
Definition: simpleprofiler.h:67
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
const char * name() const
Definition: simpleprofiler.h:55
FILE / LINE / FUNCTION (or func )
Definition: simpleprofiler.h:40
const char * filename_
The filename.
Definition: simpleprofiler.h:66
void addChildDuration(qint64 duration)
Definition: simpleprofiler.h:63
void end()
ends profiling
Definition: simpleprofiler.cpp:65
qint64 duration() const
Definition: simpleprofiler.h:57
ProfilerItem * item
Definition: simpleprofiler.h:78
int callCount_
The total number of calls.
Definition: simpleprofiler.h:71
qint64 startTime
Definition: simpleprofiler.h:79
int line() const
Definition: simpleprofiler.h:53
qint64 childDuration() const
Definition: simpleprofiler.h:58
int callCount() const
Definition: simpleprofiler.h:56
void addDuration(qint64 duration)
Definition: simpleprofiler.h:62
The current stats items.
Definition: simpleprofiler.h:77
the class to &#39;record a singlel item
Definition: simpleprofiler.h:49
qint64 childDuration_
Duration of child-items (items called by this item)
Definition: simpleprofiler.h:73
void begin(const char *file, int line, const char *function, const char *name)
begin the profiling
Definition: simpleprofiler.cpp:48
void dumpResults()
This method dumps the results to the output.
Definition: simpleprofiler.cpp:85
ProfilerItem(const char *filename, int line, const char *function, const char *name)
the constructor for a profile stat issue
Definition: simpleprofiler.cpp:21