audacia/src/Profiler.h
Paul Licameli ba7ebbb032 Reviewed the ODLocks removed at cbf1bb5, restored just two of them...
... as std::mutex instead.

One is the mutex for the set of all files.

Another is in Profiler.h, which is now back into CMakeLists because the header
is included in one place.  Maybe this utility will find more use again.

Restored one other but commented out, as not necessary now, but need might be
found to put it back again.

The class ODLock was a misnamed thing not specific to the on-demand manager but
used more widely as a thread synchronization utility, functioning as a mutex
object.  It was a mistake to remove all uses of it along with the rest of the
on-demand system.
2020-07-07 16:34:25 -04:00

93 lines
2.4 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
Profiler.h
Created by Michael Chinen (mchinen) on 8/12/08
Audacity(R) is copyright (c) 1999-2008 Audacity 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 __AUDACITY_PROFILER__
#define __AUDACITY_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