|
PLearn 0.1
|
Profiling tools, to count average time elapsed and number of times traversed for pieces of code delimited by two calls to the static functions. More...
#include <Profiler.h>

Classes | |
| class | Stats |
Static Public Member Functions | |
| static void | activate () |
| Enable profiling. | |
| static void | deactivate () |
| Disable profiling. | |
| static bool | isActive () |
| Return activation status. | |
| static void | start (const string &name_of_piece_of_code, const int max_nb_going=1) |
| Start recording time for named piece of code. | |
| static void | end (const string &name_of_piece_of_code) |
| End recording time for named piece of code, and increment frequency of occurence and total duration of this piece of code. | |
| static void | pl_profile_start (const string &name_of_piece_of_code, const int max_nb_going=1) |
| call start if if PL_PROFILE is set | |
| static void | pl_profile_end (const string &name_of_piece_of_code) |
| call end() if if PL_PROFILE is set | |
| static void | pl_profile_activate () |
| call activate() if if PL_PROFILE is set | |
| static void | pl_profile_deactivate () |
| call deactivate() if if PL_PROFILE is set | |
| static void | pl_profile_report (ostream &out) |
| call report() if if PL_PROFILE is set | |
| static void | pl_profile_report (PStream out) |
| static void | pl_profile_reportwall (ostream &out) |
| call reportwall() if if PL_PROFILE is set | |
| static void | pl_profile_reportwall (PStream out) |
| static long | ticksPerSecond () |
| Return the number of clock ticks per second on this computer. | |
| static const Stats & | getStats (const string &name_of_piece_of_code) |
| Return the statistics related to a piece of code. | |
| static void | reset (const string &name_of_piece_of_code) |
| Reset the statistics associated with a piece of code. | |
| static void | report (ostream &out) |
| Output a report on the output stream, giving the statistics recorded for each of the named pieces of codes. | |
| static void | report (PStream out) |
| static void | reportwall (ostream &out) |
| Output a report on the output stream, giving the wall time statistics recorded for each of the named pieces of codes. | |
| static void | reportwall (PStream out) |
Static Protected Member Functions | |
| static string | get_omp_save_name (const string name_of_piece_of_code) |
Static Protected Attributes | |
| static map< string, Stats > | codes_statistics |
| static struct tms | t |
| static bool | active = false |
Profiling tools, to count average time elapsed and number of times traversed for pieces of code delimited by two calls to the static functions.
Profiler::start("name_of_piece_of_code"); // ... Profiler::end("name_of_piece_of_code");
A static field of Profiler is used to maintain the statistics of occurence and durations for each piece of code. Calls to start/end for the same name cannot be nested. Three different durations are measured for a piece of code:
Before the above calls, usually in the main program, the user must call
and after all the above calls, a report for all such pieces of code can then be obtained by calling
Profiler::report(cout);
on an output stream.
This code is based on statistical averaging (using the C "times" function) because the individual measurements of elapsed time with times are too coarse (e.g. 100th of a second).
Definition at line 100 of file Profiler.h.
| static void PLearn::Profiler::activate | ( | ) | [inline, static] |
Enable profiling.
Definition at line 128 of file Profiler.h.
References PLERROR.
Referenced by PLearn::TreeDBNModule::build(), PLearn::PseudolikelihoodRBM::build_(), PLearn::mNNet::build_(), PLearn::NatGradSMPNNet::build_(), PLearn::SubsamplingDBN::build_(), PLearn::DeepBeliefNet::build_(), PLearn::AddCostToLearner::build_(), and PLearn::NatGradNNet::build_().
{
#ifdef WIN32
PLERROR("In Profiler::activate - Profiling is not currently supported "
"under Windows");
#endif
active=true;
}

| static void PLearn::Profiler::deactivate | ( | ) | [inline, static] |
| void PLearn::Profiler::end | ( | const string & | name_of_piece_of_code | ) | [static] |
End recording time for named piece of code, and increment frequency of occurence and total duration of this piece of code.
Definition at line 107 of file Profiler.cc.
References PLearn::Profiler::Stats::frequency_of_occurence, PLearn::Profiler::Stats::nb_going, PLERROR, PLWARNING, PLearn::Profiler::Stats::system_duration, PLearn::Profiler::Stats::system_last_start, PLearn::times(), PLearn::Profiler::Stats::user_duration, PLearn::Profiler::Stats::user_last_start, PLearn::Profiler::Stats::wall_duration, and PLearn::Profiler::Stats::wall_last_start.
Referenced by PLearn::TreeDBNModule::bpropAccUpdate(), PLearn::PythonProcessedLearner::computeOutput(), PLearn::TreeDBNModule::fprop(), PLearn::TreeDBNModule::full_fprop(), PLearn::SubsamplingDBN::test(), PLearn::DeepBeliefNet::test(), PLearn::AddCostToLearner::test(), PLearn::SubsamplingDBN::train(), PLearn::PseudolikelihoodRBM::train(), PLearn::NatGradSMPNNet::train(), PLearn::NatGradNNet::train(), PLearn::mNNet::train(), PLearn::DeepBeliefNet::train(), and PLearn::AddCostToLearner::train().
{
string name_of_piece_of_code=get_omp_save_name(name_of_piece_of_code_);
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
if (active)
{
clock_t end_time = times(&t);
map<string,Profiler::Stats>::iterator it =
codes_statistics.find(name_of_piece_of_code);
if (it == codes_statistics.end())
PLERROR("Profiler::end(%s) called before any call to start(%s)",
name_of_piece_of_code.c_str(),name_of_piece_of_code.c_str());
Profiler::Stats& stats = it->second;
if (stats.nb_going == 0)
PLERROR("Profiler::end(%s) called before previous start was called",
name_of_piece_of_code.c_str());
stats.nb_going--;
stats.frequency_of_occurence++;
if (stats.nb_going==0){
long wall_duration = end_time - stats.wall_last_start;
long user_duration = t.tms_utime - stats.user_last_start;
long system_duration = t.tms_stime - stats.system_last_start;
stats.wall_duration += wall_duration;
stats.user_duration += user_duration;
stats.system_duration += system_duration;
if (wall_duration < 0) {
wall_duration = user_duration = system_duration = 1;
PLWARNING("Profiler: negative duration measured with times!");
}
}
}
}


| string PLearn::Profiler::get_omp_save_name | ( | const string | name_of_piece_of_code | ) | [static, protected] |
Definition at line 59 of file Profiler.cc.
References PLearn::tostring().
{
#ifdef _OPENMP
return name_of_piece_of_code+tostring(omp_get_thread_num());
#else
return name_of_piece_of_code;
#endif
}

| const Profiler::Stats & PLearn::Profiler::getStats | ( | const string & | name_of_piece_of_code_ | ) | [static] |
Return the statistics related to a piece of code.
This is useful for aggregators that collect and report a number of statistics
Definition at line 172 of file Profiler.cc.
References PLERROR.
Referenced by PLearn::DeepBeliefNet::test(), PLearn::SubsamplingDBN::test(), PLearn::DeepBeliefNet::train(), PLearn::NatGradSMPNNet::train(), PLearn::mNNet::train(), PLearn::AddCostToLearner::train(), PLearn::PseudolikelihoodRBM::train(), PLearn::SubsamplingDBN::train(), and PLearn::NatGradNNet::train().
{
string name_of_piece_of_code=get_omp_save_name(name_of_piece_of_code_);
Stats* s;
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
{
map<string,Stats>::iterator it = codes_statistics.find(name_of_piece_of_code);
if (it == codes_statistics.end())
PLERROR("Profiler::getStats: cannot find statistics for '%s'. the active variable is at: %d",
name_of_piece_of_code.c_str(),active);
s = &(it->second);
}
return *s;
}

| static bool PLearn::Profiler::isActive | ( | ) | [inline, static] |
| static void PLearn::Profiler::pl_profile_activate | ( | ) | [inline, static] |
call activate() if if PL_PROFILE is set
Definition at line 176 of file Profiler.h.
Referenced by PLearn::HyperOptimize::build_(), and PLearn::global_options().
{}

| static void PLearn::Profiler::pl_profile_deactivate | ( | ) | [inline, static] |
call deactivate() if if PL_PROFILE is set
Definition at line 183 of file Profiler.h.
Referenced by PLearn::plearn_main().
{}

| static void PLearn::Profiler::pl_profile_end | ( | const string & | name_of_piece_of_code | ) | [inline, static] |
call end() if if PL_PROFILE is set
Definition at line 169 of file Profiler.h.
Referenced by PLearn::HyperLearner::auto_save(), PLearn::Convolution2DModule::bpropAccUpdate(), PLearn::StackedAutoassociatorsNet::computeCostsFromOutputs(), PLearn::StackedAutoassociatorsNet::computeOutput(), PLearn::NatGradNNet::computeOutput(), PLearn::StackedAutoassociatorsNet::computeOutputs(), PLearn::NatGradNNet::computeOutputs(), PLearn::StackedAutoassociatorsNet::computeOutputsAndCosts(), PLearn::NatGradNNet::computeOutputsAndCosts(), PLearn::externalProductScaleAcc(), PLearn::StackedAutoassociatorsNet::fineTuningStep(), PLearn::Convolution2DModule::fprop(), PLearn::NatGradNNet::fpropNet(), PLearn::StackedAutoassociatorsNet::greedyStep(), PLearn::NatGradNNet::onlineStep(), PLearn::HyperOptimize::optimize(), PLearn::plearn_main(), PLearn::PseudolikelihoodRBM::test(), PLearn::PLearner::test(), PLearn::MultiClassAdaBoost::test(), PLearn::AdaBoost::test(), PLearn::StackedAutoassociatorsNet::train(), PLearn::RegressionTree::train(), PLearn::NatGradNNet::train(), PLearn::MultiClassAdaBoost::train(), PLearn::AdaBoost::train(), and PLearn::transposeProduct().
{ }

| static void PLearn::Profiler::pl_profile_report | ( | ostream & | out | ) | [inline, static] |
call report() if if PL_PROFILE is set
Definition at line 191 of file Profiler.h.
Referenced by PLearn::plearn_main().
{}

| static void PLearn::Profiler::pl_profile_report | ( | PStream | out | ) | [inline, static] |
Definition at line 192 of file Profiler.h.
{}
| static void PLearn::Profiler::pl_profile_reportwall | ( | ostream & | out | ) | [inline, static] |
call reportwall() if if PL_PROFILE is set
Definition at line 200 of file Profiler.h.
Referenced by PLearn::plearn_main().
{}

| static void PLearn::Profiler::pl_profile_reportwall | ( | PStream | out | ) | [inline, static] |
Definition at line 201 of file Profiler.h.
{}
| static void PLearn::Profiler::pl_profile_start | ( | const string & | name_of_piece_of_code, |
| const int | max_nb_going = 1 |
||
| ) | [inline, static] |
call start if if PL_PROFILE is set
Definition at line 162 of file Profiler.h.
Referenced by PLearn::HyperLearner::auto_save(), PLearn::Convolution2DModule::bpropAccUpdate(), PLearn::StackedAutoassociatorsNet::computeCostsFromOutputs(), PLearn::StackedAutoassociatorsNet::computeOutput(), PLearn::NatGradNNet::computeOutput(), PLearn::StackedAutoassociatorsNet::computeOutputs(), PLearn::NatGradNNet::computeOutputs(), PLearn::StackedAutoassociatorsNet::computeOutputsAndCosts(), PLearn::NatGradNNet::computeOutputsAndCosts(), PLearn::externalProductScaleAcc(), PLearn::StackedAutoassociatorsNet::fineTuningStep(), PLearn::Convolution2DModule::fprop(), PLearn::NatGradNNet::fpropNet(), PLearn::StackedAutoassociatorsNet::greedyStep(), PLearn::NatGradNNet::onlineStep(), PLearn::HyperOptimize::optimize(), PLearn::plearn_main(), PLearn::PseudolikelihoodRBM::test(), PLearn::PLearner::test(), PLearn::MultiClassAdaBoost::test(), PLearn::AdaBoost::test(), PLearn::StackedAutoassociatorsNet::train(), PLearn::RegressionTree::train(), PLearn::NatGradNNet::train(), PLearn::MultiClassAdaBoost::train(), PLearn::AdaBoost::train(), and PLearn::transposeProduct().
{}

| void PLearn::Profiler::report | ( | PStream | out | ) | [static] |
Definition at line 210 of file Profiler.cc.
References PLearn::endl(), PLearn::Profiler::Stats::frequency_of_occurence, PLearn::Profiler::Stats::system_duration, PLearn::Profiler::Stats::user_duration, and PLearn::Profiler::Stats::wall_duration.
{
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
{
map<string,Profiler::Stats>::iterator it =
codes_statistics.begin(), end = codes_statistics.end();
out << "*** PLearn::Profiler Report ***" << endl;
out << "Ticks per second : " << ticksPerSecond() <<endl;
for ( ; it!=end ; ++it)
{
out << endl << "For " << it->first << " :" << endl;
Profiler::Stats& stats = it->second;
out << "Frequency of occurence = " << stats.frequency_of_occurence << endl;
out << "Wall duration (ticks) = " << stats.wall_duration << endl
<< "User duration (ticks) = " << stats.user_duration << endl
<< "System duration (ticks) = " << stats.system_duration << endl;
double avg_wall = (double)stats.wall_duration/stats.frequency_of_occurence;
double avg_user = (double)stats.user_duration/stats.frequency_of_occurence;
double avg_sys = (double)stats.system_duration/stats.frequency_of_occurence;
out << "Average wall duration = " << avg_wall << endl
<< "Average user duration = " << avg_user << endl
<< "Average system duration = " << avg_sys << endl;
}
}
}

| void PLearn::Profiler::report | ( | ostream & | out | ) | [static] |
Output a report on the output stream, giving the statistics recorded for each of the named pieces of codes.
Definition at line 206 of file Profiler.cc.
Referenced by PLearn::Learner::stop_if_wanted(), PLearn::DeepBeliefNet::train(), PLearn::mNNet::train(), PLearn::SubsamplingDBN::train(), and PLearn::NatGradNNet::train().
{
report(PStream(&out));
}

| void PLearn::Profiler::reportwall | ( | PStream | out | ) | [static] |
Definition at line 246 of file Profiler.cc.
References PLearn::endl(), PLearn::Profiler::Stats::frequency_of_occurence, and PLearn::Profiler::Stats::wall_duration.
{
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
{
map<string,Profiler::Stats>::iterator it =
codes_statistics.begin(), end = codes_statistics.end();
out << "*** PLearn::Profiler Wall Report ***" << endl;
out << "Ticks per second : " << ticksPerSecond() <<endl;
for ( ; it!=end ; ++it)
{
out << endl << "For " << it->first << " :" << endl;
Profiler::Stats& stats = it->second;
out << "Frequency of occurence = " << stats.frequency_of_occurence << endl;
out << "Wall duration (ticks) = " << stats.wall_duration << endl;
double avg_wall = (double)stats.wall_duration/stats.frequency_of_occurence;
out << "Average wall duration = " << avg_wall << endl;
}
}
}

| void PLearn::Profiler::reportwall | ( | ostream & | out | ) | [static] |
Output a report on the output stream, giving the wall time statistics recorded for each of the named pieces of codes.
Definition at line 242 of file Profiler.cc.
{
reportwall(PStream(&out));
}
| void PLearn::Profiler::reset | ( | const string & | name_of_piece_of_code_ | ) | [static] |
Reset the statistics associated with a piece of code.
The piece of code may not yet exist, this is fine.
Definition at line 192 of file Profiler.cc.
Referenced by PLearn::AddCostToLearner::build_(), PLearn::DeepBeliefNet::test(), PLearn::SubsamplingDBN::test(), PLearn::DeepBeliefNet::train(), PLearn::NatGradSMPNNet::train(), PLearn::mNNet::train(), PLearn::PseudolikelihoodRBM::train(), PLearn::SubsamplingDBN::train(), and PLearn::NatGradNNet::train().
{
string name_of_piece_of_code=get_omp_save_name(name_of_piece_of_code_);
Stats empty;
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
codes_statistics[name_of_piece_of_code] = empty;
}

| void PLearn::Profiler::start | ( | const string & | name_of_piece_of_code, |
| const int | max_nb_going = 1 |
||
| ) | [static] |
Start recording time for named piece of code.
Definition at line 69 of file Profiler.cc.
References PLearn::Profiler::Stats::nb_going, PLERROR, PLearn::Profiler::Stats::system_last_start, PLearn::times(), PLearn::Profiler::Stats::user_last_start, and PLearn::Profiler::Stats::wall_last_start.
Referenced by PLearn::TreeDBNModule::bpropAccUpdate(), PLearn::PythonProcessedLearner::computeOutput(), PLearn::TreeDBNModule::fprop(), PLearn::TreeDBNModule::full_fprop(), PLearn::SubsamplingDBN::test(), PLearn::DeepBeliefNet::test(), PLearn::AddCostToLearner::test(), PLearn::SubsamplingDBN::train(), PLearn::PseudolikelihoodRBM::train(), PLearn::NatGradSMPNNet::train(), PLearn::NatGradNNet::train(), PLearn::mNNet::train(), PLearn::DeepBeliefNet::train(), and PLearn::AddCostToLearner::train().
{
string name_of_piece_of_code=get_omp_save_name(name_of_piece_of_code_);
#ifdef _OPENMP
#pragma omp critical (codes_statistics)
#endif
if (active)
{
map<string,Profiler::Stats>::iterator it =
codes_statistics.find(name_of_piece_of_code);
if (it == codes_statistics.end())
{
Stats stats;
stats.nb_going = 1;
stats.wall_last_start = times(&t);
stats.user_last_start = t.tms_utime;
stats.system_last_start = t.tms_stime;
codes_statistics[name_of_piece_of_code] = stats;
}
else
{
Profiler::Stats& stats = it->second;
if (stats.nb_going >= max_nb_going)
PLERROR("Profiler::start(%s) called while previous %d starts had not ended and we allowed only %d starts",
name_of_piece_of_code.c_str(),stats.nb_going, max_nb_going);
if (stats.nb_going==0){
stats.wall_last_start = times(&t);
stats.user_last_start = t.tms_utime;
stats.system_last_start = t.tms_stime;
}
stats.nb_going++;
}
}
}


| static long PLearn::Profiler::ticksPerSecond | ( | ) | [inline, static] |
Return the number of clock ticks per second on this computer.
Definition at line 206 of file Profiler.h.
Referenced by PLearn::DeepBeliefNet::test(), PLearn::SubsamplingDBN::test(), PLearn::DeepBeliefNet::train(), PLearn::NatGradSMPNNet::train(), PLearn::mNNet::train(), PLearn::AddCostToLearner::train(), PLearn::PseudolikelihoodRBM::train(), PLearn::SubsamplingDBN::train(), and PLearn::NatGradNNet::train().
{ return sysconf(_SC_CLK_TCK); }

bool PLearn::Profiler::active = false [static, read, protected] |
Definition at line 233 of file Profiler.h.
map< string, Profiler::Stats > PLearn::Profiler::codes_statistics [static, protected] |
Definition at line 231 of file Profiler.h.
struct tms PLearn::Profiler::t [static, protected] |
Definition at line 232 of file Profiler.h.
1.7.4