PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::PTimer Class Reference

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <PTimer.h>

Inheritance diagram for PLearn::PTimer:
Inheritance graph
[legend]
Collaboration diagram for PLearn::PTimer:
Collaboration graph
[legend]

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual PTimerdeepCopy (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 PPathdeclaringFile ()

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, intname_to_idx

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

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

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 57 of file PTimer.h.


Member Typedef Documentation

typedef Object PLearn::PTimer::inherited [private]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.h.


Constructor & Destructor Documentation

PLearn::PTimer::PTimer ( )

Default constructor.

Definition at line 64 of file PTimer.cc.

    :use_time_fct(false)
{}
PLearn::PTimer::PTimer ( bool  use_time_fct_,
bool  call_build_ = true 
)

Definition at line 68 of file PTimer.cc.

References build_().

                                                  :
    inherited(call_build_),
    use_time_fct(use_time_fct_)
{
    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::PTimer::_classname_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

OptionList & PLearn::PTimer::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

RemoteMethodMap & PLearn::PTimer::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

bool PLearn::PTimer::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

Object * PLearn::PTimer::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

StaticInitializer PTimer::_static_initializer_ & PLearn::PTimer::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::PTimer::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

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);
}

Here is the call graph for this function:

static const PPath& PLearn::PTimer::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 99 of file PTimer.h.

:
    
PTimer * PLearn::PTimer::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

OptionList & PLearn::PTimer::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

OptionMap & PLearn::PTimer::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

RemoteMethodMap & PLearn::PTimer::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 59 of file PTimer.cc.

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.

Here is the call graph for this function:

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();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

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;
}

Here is the caller graph for this function:

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();
}

Here is the call graph for this function:

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);
}

Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 99 of file PTimer.h.

map<string, int> PLearn::PTimer::name_to_idx [protected]
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().

### 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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines