QGIS API Documentation  3.6.0-Noosa (5873452)
qgsruntimeprofiler.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsruntimeprofiler.cpp
3  ---------------------
4  begin : June 2016
5  copyright : (C) 2016 by Nathan Woodrow
6  email : woodrow dot nathan at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsruntimeprofiler.h"
16 #include "qgslogger.h"
17 
18 void QgsRuntimeProfiler::beginGroup( const QString &name )
19 {
20  mGroupStack.push( name );
21  if ( !name.isEmpty() )
22  {
23  mGroupPrefix += name;
24  mGroupPrefix += QLatin1Char( '/' );
25  }
26 }
27 
29 {
30  if ( mGroupStack.isEmpty() )
31  {
32  qWarning( "QgsSettings::endGroup: No matching beginGroup()" );
33  return;
34  }
35 
36  QString group = mGroupStack.pop();
37  int len = group.size();
38  if ( len > 0 )
39  mGroupPrefix.truncate( mGroupPrefix.size() - ( len + 1 ) );
40 }
41 
42 void QgsRuntimeProfiler::start( const QString &name )
43 {
44  mProfileTime.restart();
45  mCurrentName = name;
46 }
47 
49 {
50  QString name = mCurrentName;
51  name.prepend( mGroupPrefix );
52  double timing = mProfileTime.elapsed() / 1000.0;
53  mProfileTimes.append( QPair<QString, double>( name, timing ) );
54  QgsDebugMsg( QStringLiteral( "PROFILE: %1 - %2" ).arg( name ).arg( timing ) );
55 }
56 
58 {
59  mProfileTimes.clear();
60 }
61 
63 {
64  double total = 0;
65  QList<QPair<QString, double> >::const_iterator it = mProfileTimes.constBegin();
66  for ( ; it != mProfileTimes.constEnd(); ++it )
67  {
68  total += ( *it ).second;
69  }
70  return total;
71 }
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
void endGroup()
End the current active group.
double totalTime()
The current total time collected in the profiler.
void beginGroup(const QString &name)
Begin the group for the profiler.
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.