Audacity 3.2.0
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 or later. 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
38class TaskProfile;
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:
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:
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;
86 clock_t mCumTime;
87 clock_t mLastTime;
88 };
89
90
91#endif
92
A simple profiler to measure the average time lengths that a particular task/function takes....
Definition: Profiler.h:40
virtual ~Profiler()
write to a profile at the end of the test.
Definition: Profiler.cpp:30
TaskProfile * GetOrCreateTaskProfile(const char *fileName, int lineNum)
find a taskProfile for the given task, otherwise create
Definition: Profiler.cpp:89
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
Definition: Profiler.cpp:63
Profiler()
private constructor - Singleton.
Definition: Profiler.h:56
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
Definition: Profiler.cpp:70
std::mutex mTasksMutex
Definition: Profiler.h:65
std::vector< std::unique_ptr< TaskProfile > > mTasks
Definition: Profiler.h:63
TaskProfile * GetTaskProfileByDescription(const char *description)
Definition: Profiler.cpp:102
static Profiler * Instance()
Gets the singleton instance.
Definition: Profiler.cpp:80
a simple class to keep track of one task that may be called multiple times.
Definition: Profiler.h:70
clock_t mLastTime
Definition: Profiler.h:87
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
Definition: Profiler.cpp:143
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
Definition: Profiler.cpp:127
double ComputeAverageRunTime()
Definition: Profiler.cpp:149
int mNumHits
Definition: Profiler.h:85
ArrayOf< char > mDescription
Definition: Profiler.h:84
TaskProfile()
Task Profile.
Definition: Profiler.cpp:116
ArrayOf< char > mFileName
Definition: Profiler.h:82
int mLine
Definition: Profiler.h:83
virtual ~TaskProfile()
Definition: Profiler.cpp:122
clock_t mCumTime
Definition: Profiler.h:86