PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <PTimer.h>
Public Member Functions | |
PTimer () | |
Default constructor. | |
PTimer (bool use_time_fct_, bool call_build_=true) | |
real | getTimer (const string &timer_name) |
Return the value of a timer. | |
void | newTimer (const string &timer_name, bool can_exit=false) |
Add a new timer. | |
void | resetAllTimers () |
Reset all timers. | |
void | resetTimer (const string &timer_name) |
Reset a specific timer. | |
void | startTimer (const string &timer_name) |
Start a timer. If the timer does not already exist, it is created. | |
void | stopTimer (const string &timer_name) |
Stop a timer. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual PTimer * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
bool | use_time_fct |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
TVec< clock_t > | start_clock_t |
List of starting times (measured in clock_t units). | |
TVec< long > | start_long |
List of starting times (measured in long units). | |
Vec | total_times |
map< string, int > | name_to_idx |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
typedef Object PLearn::PTimer::inherited [private] |
Reimplemented from PLearn::Object.
PLearn::PTimer::PTimer | ( | ) |
string PLearn::PTimer::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
OptionList & PLearn::PTimer::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
RemoteMethodMap & PLearn::PTimer::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Reimplemented from PLearn::Object.
Object * PLearn::PTimer::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
StaticInitializer PTimer::_static_initializer_ & PLearn::PTimer::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
void PLearn::PTimer::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Object.
Definition at line 79 of file PTimer.cc.
References PLearn::Object::build(), and build_().
Referenced by newTimer().
{ inherited::build(); build_(); }
void PLearn::PTimer::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 127 of file PTimer.cc.
References PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), start_clock_t, start_long, and total_times.
Referenced by build(), and PTimer().
{ // ### This method should do the real building of the object, // ### according to set 'options', in *any* situation. // ### Typical situations include: // ### - Initial building of an object from a few user-specified options // ### - Building of a "reloaded" object: i.e. from the complete set of all serialised options. // ### - Updating or "re-building" of an object after a few "tuning" options have been modified. // ### You should assume that the parent class' build_() has already been called. int n_timers = total_times.length(); start_long.resize(n_timers); start_clock_t.resize(n_timers); }
string PLearn::PTimer::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
void PLearn::PTimer::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::Object.
Definition at line 99 of file PTimer.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), PLearn::OptionBase::learntoption, name_to_idx, total_times, and use_time_fct.
{ // ### Declare all of this object's options here // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. Another possible flag to be combined with // ### is OptionBase::nosave declareOption(ol, "name_to_idx", &PTimer::name_to_idx, OptionBase::learntoption, "Map a timer's name to its internal integer index."); declareOption(ol, "total_times", &PTimer::total_times, OptionBase::learntoption, "Contains the current total times of all timers."); declareOption(ol, "use_time_fct", &PTimer::use_time_fct, OptionBase::buildoption, "If true, we will use the time(0) function. So we will report the\n" "wall time. Useful in multithread case."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::PTimer::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
OptionList & PLearn::PTimer::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
OptionMap & PLearn::PTimer::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
RemoteMethodMap & PLearn::PTimer::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
real PLearn::PTimer::getTimer | ( | const string & | timer_name | ) |
Return the value of a timer.
Definition at line 144 of file PTimer.cc.
References name_to_idx, PLASSERT, and total_times.
{ PLASSERT( name_to_idx.find(timer_name) != name_to_idx.end() ); int timer_id = name_to_idx[timer_name]; return total_times[timer_id]; }
void PLearn::PTimer::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Object.
Definition at line 88 of file PTimer.cc.
References PLearn::deepCopyField(), PLearn::Object::makeDeepCopyFromShallowCopy(), start_clock_t, start_long, and total_times.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(start_clock_t, copies); deepCopyField(start_long, copies); deepCopyField(total_times, copies); }
void PLearn::PTimer::newTimer | ( | const string & | timer_name, |
bool | can_exit = false |
||
) |
Add a new timer.
Definition at line 154 of file PTimer.cc.
References PLearn::TVec< T >::append(), build(), PLearn::TVec< T >::length(), name_to_idx, PLASSERT, and total_times.
Referenced by startTimer().
{ if(!can_exist) PLASSERT( name_to_idx.find(timer_name) == name_to_idx.end() ); int n_timers = total_times.length(); name_to_idx[timer_name] = n_timers; total_times.append(0); build(); }
void PLearn::PTimer::resetAllTimers | ( | ) |
Reset all timers.
Definition at line 167 of file PTimer.cc.
References name_to_idx, and resetTimer().
{ map<string, int>::const_iterator it; for (it = name_to_idx.begin(); it != name_to_idx.end(); it++) resetTimer(it->first); }
void PLearn::PTimer::resetTimer | ( | const string & | timer_name | ) |
Reset a specific timer.
Definition at line 177 of file PTimer.cc.
References name_to_idx, PLASSERT, and total_times.
Referenced by resetAllTimers().
{ PLASSERT( name_to_idx.find(timer_name) != name_to_idx.end() ); int timer_id = name_to_idx[timer_name]; total_times[timer_id] = 0; }
void PLearn::PTimer::startTimer | ( | const string & | timer_name | ) |
Start a timer. If the timer does not already exist, it is created.
Definition at line 187 of file PTimer.cc.
References name_to_idx, newTimer(), start_clock_t, and start_long.
{ map<string, int>::const_iterator it = name_to_idx.find(timer_name); if (it == name_to_idx.end()) { // The timer does not already exist. this->newTimer(timer_name); it = name_to_idx.find(timer_name); } int timer_id = it->second; start_long[timer_id] = long(time(0)); start_clock_t[timer_id] = clock(); }
void PLearn::PTimer::stopTimer | ( | const string & | timer_name | ) |
Stop a timer.
Definition at line 203 of file PTimer.cc.
References name_to_idx, PLASSERT, start_clock_t, start_long, total_times, and use_time_fct.
{ PLASSERT( name_to_idx.find(timer_name) != name_to_idx.end() ); int timer_id = name_to_idx[timer_name]; clock_t time_clock_t = clock() - start_clock_t[timer_id]; long time_long = long(time(0)) - start_long[timer_id]; if (time_long > 1800 || use_time_fct) // More than 30 mins: we use the approximate length. total_times[timer_id] += time_long; else // Less than 30 mins: we use the more precise length. total_times[timer_id] += time_clock_t / real(CLOCKS_PER_SEC); }
Reimplemented from PLearn::Object.
map<string, int> PLearn::PTimer::name_to_idx [protected] |
Definition at line 119 of file PTimer.h.
Referenced by declareOptions(), getTimer(), newTimer(), resetAllTimers(), resetTimer(), startTimer(), and stopTimer().
TVec<clock_t> PLearn::PTimer::start_clock_t [protected] |
List of starting times (measured in clock_t units).
Definition at line 111 of file PTimer.h.
Referenced by build_(), makeDeepCopyFromShallowCopy(), startTimer(), and stopTimer().
TVec<long> PLearn::PTimer::start_long [protected] |
List of starting times (measured in long units).
Definition at line 114 of file PTimer.h.
Referenced by build_(), makeDeepCopyFromShallowCopy(), startTimer(), and stopTimer().
Vec PLearn::PTimer::total_times [protected] |
Definition at line 118 of file PTimer.h.
Referenced by build_(), declareOptions(), getTimer(), makeDeepCopyFromShallowCopy(), newTimer(), resetTimer(), and stopTimer().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Definition at line 66 of file PTimer.h.
Referenced by declareOptions(), and stopTimer().