35 FILE* log = fopen(
"AudacityProfilerLog.txt",
"a");
39 wxFprintf(log,
"Audacity Profiler Run, Ended at ");
40 wxFprintf(log,
"%s",ctime(&now));
41 wxFprintf(log,
"****************************************\n");
43 for(
int i=0;i<(int)
mTasks.size();i++)
47 wxFprintf(log,
"Task: %s\n(begins at line %d in %s)\n\n",
mTasks[i]->mDescription.get(),
mTasks[i]->mLine,
mTasks[i]->mFileName.get());
48 wxFprintf(log,
"Number of times run: %d\n",
mTasks[i]->mNumHits);
49 wxFprintf(log,
"Total run time (seconds): %f\n", (
double)
mTasks[i]->mCumTime/CLOCKS_PER_SEC);
50 wxFprintf(log,
"Average run time (seconds): %f\n",
mTasks[i]->ComputeAverageRunTime());
52 if(i < ((
int)
mTasks.size()) -1)
53 wxFprintf(log,
"----------------------------\n");
56 wxFprintf(log,
"\n****************************************\n\n\n");
63void Profiler::Begin(
const char* fileName,
int lineNum,
const char* taskDescription)
70void Profiler::End(
const char* fileName,
int lineNum,
const char* taskDescription)
76 tp->
End(fileName,lineNum,taskDescription);
91 for(
int i=0;i<(int)
mTasks.size();i++)
93 if(strcmp(fileName,
mTasks[i]->mFileName.get())==0 && lineNum ==
mTasks[i]->mLine)
97 auto tp = std::make_unique<TaskProfile>();
98 mTasks.push_back(std::move(tp));
99 return mTasks.back().get();
104 for(
int i=0;i<(int)
mTasks.size();i++)
106 if(strcmp(description,
mTasks[i]->mDescription.get())==0)
143void TaskProfile::End(
const char* WXUNUSED(fileName),
int WXUNUSED(lineNum),
const char* WXUNUSED(taskDescription))
void reinit(Integral count, bool initialize=false)
A simple profiler to measure the average time lengths that a particular task/function takes....
virtual ~Profiler()
write to a profile at the end of the test.
TaskProfile * GetOrCreateTaskProfile(const char *fileName, int lineNum)
find a taskProfile for the given task, otherwise create
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
std::vector< std::unique_ptr< TaskProfile > > mTasks
TaskProfile * GetTaskProfileByDescription(const char *description)
static Profiler * Instance()
Gets the singleton instance.
a simple class to keep track of one task that may be called multiple times.
void End(const char *fileName, int lineNum, const char *taskDescription)
end the task timer.
void Begin(const char *fileName, int lineNum, const char *taskDescription)
start the task timer.
double ComputeAverageRunTime()
ArrayOf< char > mDescription
TaskProfile()
Task Profile.
ArrayOf< char > mFileName