QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsruntimeprofiler.cpp
Go to the documentation of this file.
1 #include "qgsruntimeprofiler.h"
2 #include "qgslogger.h"
3 
4 
5 QgsRuntimeProfiler* QgsRuntimeProfiler::mInstance = nullptr;
6 
8 {
9  if ( !mInstance )
10  mInstance = new QgsRuntimeProfiler();
11  return mInstance;
12 }
13 
15 {
16 
17 }
18 
20 {
21  mGroupStack.push( name );
22  if ( !name.isEmpty() )
23  {
24  mGroupPrefix += name;
25  mGroupPrefix += QLatin1Char( '/' );
26  }
27 }
28 
30 {
31  if ( mGroupStack.isEmpty() )
32  {
33  qWarning( "QSettings::endGroup: No matching beginGroup()" );
34  return;
35  }
36 
37  QString group = mGroupStack.pop();
38  int len = group.size();
39  if ( len > 0 )
40  mGroupPrefix.truncate( mGroupPrefix.size() - ( len + 1 ) );
41 }
42 
44 {
45  mProfileTime.restart();
46  mCurrentName = name;
47 }
48 
50 {
51  QString name = mCurrentName;
52  name.prepend( mGroupPrefix );
53  double timing = mProfileTime.elapsed() / 1000.0;
54  mProfileTimes.append( QPair<QString, double>( name, timing ) );
55  QString message = QString( "PROFILE: %1 - %2" ).arg( name ).arg( timing );
56  QgsDebugMsg( message );
57 }
58 
60 {
61  mProfileTimes.clear();
62 }
63 
65 {
66  double total = 0;
67  QList<QPair<QString, double> >::const_iterator it = mProfileTimes.constBegin();
68  for ( ; it != mProfileTimes.constEnd(); ++it )
69  {
70  total += ( *it ).second;
71  }
72  return total;
73 }
void clear()
QgsRuntimeProfiler()
Constructor to create a new runtime profiler.
void truncate(int position)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QString & prepend(QChar ch)
void push(const T &t)
void endGroup()
End the current active group.
int size() const
double totalTime()
The current total time collected in the profiler.
void beginGroup(const QString &name)
Begin the group for the profiler.
int elapsed() const
void append(const T &value)
bool isEmpty() const
static QgsRuntimeProfiler * instance()
Instance of the run time profiler.
int restart()
void clear()
clear Clear all profile data.
void start(const QString &name)
Start a profile event with the given name.
void end()
End the current profile event.
const_iterator constEnd() const
const_iterator constBegin() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const