forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfiler.h
92 lines (63 loc) · 2.39 KB
/
Profiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**********************************************************************
Sneedacity: A Digital Audio Editor
Profiler.h
Created by Michael Chinen (mchinen) on 8/12/08
Sneedacity(R) is copyright (c) 1999-2008 Sneedacity Team.
License: GPL v2. See License.txt.
******************************************************************//**
\class Profiler
\brief A simple profiler to measure the average time lengths that a
particular task/function takes. Currently not thread-safe and not thread-smart,
but it will probably work fine if you use it on a high level.
\class TaskProfile
\brief a simple class to keep track of one task that may be called multiple times.
*//*******************************************************************/
#ifndef __SNEEDACITY_PROFILER__
#define __SNEEDACITY_PROFILER__
#include <mutex>
#include <vector>
#include <time.h>
#include "MemoryX.h"
#define BEGIN_TASK_PROFILING(TASK_DESCRIPTION) Profiler::Instance()->Begin(__FILE__,__LINE__,TASK_DESCRIPTION)
#define END_TASK_PROFILING(TASK_DESCRIPTION) Profiler::Instance()->End(__FILE__,__LINE__,TASK_DESCRIPTION)
class TaskProfile;
class Profiler
{
public:
///write to a profile at the end of the test.
virtual ~Profiler();
///start the task timer.
void Begin(const char* fileName, int lineNum, const char* taskDescription);
///end the task timer.
void End(const char* fileName, int lineNum, const char* taskDescription);
///Gets the singleton instance
static Profiler* Instance();
protected:
///private constructor - Singleton.
Profiler(){};
///find a taskProfile for the given task, otherwise create
TaskProfile* GetOrCreateTaskProfile(const char* fileName, int lineNum);
TaskProfile* GetTaskProfileByDescription(const char* description);
//List of current Task to do.
std::vector<std::unique_ptr<TaskProfile>> mTasks;
//mutex for above variable
std::mutex mTasksMutex;
};
class TaskProfile
{
public:
TaskProfile();
virtual ~TaskProfile();
///start the task timer.
void Begin(const char* fileName, int lineNum, const char* taskDescription);
///end the task timer.
void End(const char* fileName, int lineNum, const char* taskDescription);
double ComputeAverageRunTime();
ArrayOf<char> mFileName;
int mLine;
ArrayOf<char> mDescription;
int mNumHits;
clock_t mCumTime;
clock_t mLastTime;
};
#endif