Audacity  3.0.3
Profiler.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Profiler.h
6 
7  Created by Michael Chinen (mchinen) on 8/12/08
8  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
9  License: GPL v2. See License.txt.
10 
11 ******************************************************************//*******************************************************************/
22 
23 
24 
25 
26 
27 #ifndef __AUDACITY_PROFILER__
28 #define __AUDACITY_PROFILER__
29 #include <mutex>
30 #include <vector>
31 #include <time.h>
32 #include "MemoryX.h"
33 
34 
35 #define BEGIN_TASK_PROFILING(TASK_DESCRIPTION) Profiler::Instance()->Begin(__FILE__,__LINE__,TASK_DESCRIPTION)
36 #define END_TASK_PROFILING(TASK_DESCRIPTION) Profiler::Instance()->End(__FILE__,__LINE__,TASK_DESCRIPTION)
37 
38 class TaskProfile;
39 class Profiler
40 {
41  public:
42 
44  virtual ~Profiler();
45 
47  void Begin(const char* fileName, int lineNum, const char* taskDescription);
49  void End(const char* fileName, int lineNum, const char* taskDescription);
50 
52  static Profiler* Instance();
53 
54  protected:
56  Profiler(){};
57 
59  TaskProfile* GetOrCreateTaskProfile(const char* fileName, int lineNum);
60  TaskProfile* GetTaskProfileByDescription(const char* description);
61 
62  //List of current Task to do.
63  std::vector<std::unique_ptr<TaskProfile>> mTasks;
64  //mutex for above variable
65  std::mutex mTasksMutex;
66 
67 };
68 
70  {
71  public:
72  TaskProfile();
73  virtual ~TaskProfile();
74 
76  void Begin(const char* fileName, int lineNum, const char* taskDescription);
78  void End(const char* fileName, int lineNum, const char* taskDescription);
79 
80  double ComputeAverageRunTime();
81 
83  int mLine;
85  int mNumHits;
86  clock_t mCumTime;
87  clock_t mLastTime;
88  };
89 
90 
91 #endif
92 
TaskProfile::mCumTime
clock_t mCumTime
Definition: Profiler.h:86
Profiler
A simple profiler to measure the average time lengths that a particular task/function takes....
Definition: Profiler.h:40
TaskProfile::~TaskProfile
virtual ~TaskProfile()
Definition: Profiler.cpp:123
TaskProfile::mFileName
ArrayOf< char > mFileName
Definition: Profiler.h:82
Profiler::Begin
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
Definition: Profiler.cpp:64
TaskProfile::ComputeAverageRunTime
double ComputeAverageRunTime()
Definition: Profiler.cpp:150
Profiler::mTasksMutex
std::mutex mTasksMutex
Definition: Profiler.h:65
TaskProfile::mDescription
ArrayOf< char > mDescription
Definition: Profiler.h:84
Profiler::Profiler
Profiler()
private constructor - Singleton.
Definition: Profiler.h:56
TaskProfile::Begin
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
Definition: Profiler.cpp:128
TaskProfile::mLastTime
clock_t mLastTime
Definition: Profiler.h:87
Profiler::GetTaskProfileByDescription
TaskProfile * GetTaskProfileByDescription(const char *description)
Definition: Profiler.cpp:103
Profiler::Instance
static Profiler * Instance()
Gets the singleton instance.
Definition: Profiler.cpp:81
TaskProfile::End
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
Definition: Profiler.cpp:144
Profiler::mTasks
std::vector< std::unique_ptr< TaskProfile > > mTasks
Definition: Profiler.h:63
MemoryX.h
Profiler::End
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
Definition: Profiler.cpp:71
TaskProfile::mNumHits
int mNumHits
Definition: Profiler.h:85
Profiler::GetOrCreateTaskProfile
TaskProfile * GetOrCreateTaskProfile(const char *fileName, int lineNum)
find a taskProfile for the given task, otherwise create
Definition: Profiler.cpp:90
TaskProfile::TaskProfile
TaskProfile()
Task Profile.
Definition: Profiler.cpp:117
ArrayOf< char >
TaskProfile
a simple class to keep track of one task that may be called multiple times.
Definition: Profiler.h:70
TaskProfile::mLine
int mLine
Definition: Profiler.h:83
Profiler::~Profiler
virtual ~Profiler()
write to a profile at the end of the test.
Definition: Profiler.cpp:31