MOAB: Mesh Oriented datABase
(version 5.4.1)
|
#include <MsqTimer.hpp>
Public Types | |
typedef size_t | Key |
Public Member Functions | |
MESQUITE_EXPORT | StopWatchCollection () |
MESQUITE_EXPORT Key | add (const std::string &name, bool fail_if_exists=true) |
MESQUITE_EXPORT Key | get_key (const std::string &name) const |
MESQUITE_EXPORT std::string | get_string (const Key key) |
Gets the string associated with a key. | |
MESQUITE_EXPORT void | get_string (const Key key, std::string &new_string) |
Gets the string associated with a key. | |
MESQUITE_EXPORT void | remove (const Key key) |
MESQUITE_EXPORT void | remove (const std::string &name) |
MESQUITE_EXPORT void | start (const Key key) |
MESQUITE_EXPORT void | start (const std::string &name) |
MESQUITE_EXPORT void | stop (const Key key) |
MESQUITE_EXPORT void | stop (const std::string &name) |
MESQUITE_EXPORT void | reset (const Key key) |
MESQUITE_EXPORT void | reset (const std::string &name) |
MESQUITE_EXPORT double | total_time (const Key key) const |
MESQUITE_EXPORT double | total_time (const std::string &name) const |
MESQUITE_EXPORT int | number_of_starts (const Key key) const |
MESQUITE_EXPORT int | number_of_starts (const std::string &name) const |
MESQUITE_EXPORT int | number_of_stop_watches () |
MESQUITE_EXPORT void | get_keys_sorted_by_time (std::vector< Key > &sorted_keys) |
Private Attributes | |
std::vector< std::pair < std::string, StopWatch > > | mEntries |
Definition at line 102 of file MsqTimer.hpp.
typedef size_t MBMesquite::StopWatchCollection::Key |
Definition at line 105 of file MsqTimer.hpp.
Definition at line 108 of file MsqTimer.hpp.
{}
MBMesquite::StopWatchCollection::Key MBMesquite::StopWatchCollection::add | ( | const std::string & | name, |
bool | fail_if_exists = true |
||
) |
Definition at line 127 of file MsqTimer.cpp.
References moab::GeomUtil::first().
{ // Don't allow empty name if( name == "" ) return 0; Key key = get_key( name ); // If the named stopwatch doesn't exist... if( !key ) { // See if there is an unused existing stopwatch size_t i; for( i = 0; i < mEntries.size(); i++ ) { if( mEntries[i].first == "" ) { mEntries[i].first = name; mEntries[i].second.reset(); break; } } // If not, create a new one if( i == mEntries.size() ) { mEntries.push_back( std::pair< std::string, StopWatch >( name, StopWatch() ) ); } key = i + 1; } // If it already existed... else if( fail_if_exists ) key = 0; return key; }
MBMesquite::StopWatchCollection::Key MBMesquite::StopWatchCollection::get_key | ( | const std::string & | name | ) | const |
Definition at line 163 of file MsqTimer.cpp.
References moab::GeomUtil::first().
Referenced by number_of_starts(), remove(), reset(), start(), stop(), and total_time().
void MBMesquite::StopWatchCollection::get_keys_sorted_by_time | ( | std::vector< Key > & | sorted_keys | ) |
Fills a vector of StopWatchCollection::Key in which the Keys are ordered by the associated StopWatch's total_time. The key associated with the largest total_time StopWatch is in the first position of the vector. The key associated with the smallest total_time StopWatch is in the last position of the vector.
Definition at line 233 of file MsqTimer.cpp.
Referenced by MBMesquite::operator<<().
{ int num_watches = mEntries.size(); int* sorted_indices = new int[num_watches]; int i = 0; int counter = 0; for( i = 0; i < num_watches; ++i ) { sorted_indices[i] = 0; } double current_max; int index_to_max; // While we haven't added all of the Keys to the vector while( counter < num_watches ) { current_max = -1; index_to_max = -1; // loop over the times and find the largest remaining for( i = 0; i < num_watches; ++i ) { if( mEntries[i].second.total_time() > current_max && sorted_indices[i] == 0 ) { current_max = mEntries[i].second.total_time(); index_to_max = i; } } // Add the key associated with index_to_max and any subsequent // keys which are associated with a StopWatch that has a total // time equal to current_max; for( i = index_to_max; i < num_watches; ++i ) { if( mEntries[i].second.total_time() >= current_max && sorted_indices[i] == 0 ) { counter++; sorted_indices[i] = counter; sorted_keys.push_back( i + 1 ); } } } // clean up delete[] sorted_indices; }
MESQUITE_EXPORT std::string MBMesquite::StopWatchCollection::get_string | ( | const Key | key | ) | [inline] |
Gets the string associated with a key.
Definition at line 123 of file MsqTimer.hpp.
References mEntries.
Referenced by MBMesquite::operator<<().
{ return mEntries[key - 1].first; }
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::get_string | ( | const Key | key, |
std::string & | new_string | ||
) | [inline] |
Gets the string associated with a key.
Definition at line 128 of file MsqTimer.hpp.
References mEntries.
{ new_string = mEntries[key - 1].first; }
int MBMesquite::StopWatchCollection::number_of_starts | ( | const Key | key | ) | const |
Definition at line 221 of file MsqTimer.cpp.
Referenced by number_of_starts(), and MBMesquite::operator<<().
MESQUITE_EXPORT int MBMesquite::StopWatchCollection::number_of_starts | ( | const std::string & | name | ) | const [inline] |
Definition at line 170 of file MsqTimer.hpp.
References get_key(), and number_of_starts().
{ return number_of_starts( get_key( name ) ); }
MESQUITE_EXPORT int MBMesquite::StopWatchCollection::number_of_stop_watches | ( | ) | [inline] |
void MBMesquite::StopWatchCollection::remove | ( | const Key | key | ) |
Definition at line 179 of file MsqTimer.cpp.
{ // Get rid of anything at the end of the list if( key == mEntries.size() ) { mEntries.pop_back(); while( !mEntries.empty() && mEntries.back().first == "" ) { mEntries.pop_back(); } } else if( key > 0 && key < mEntries.size() ) { // If in the middle of the list, set its name to "" mEntries[key - 1].first = ""; } }
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::remove | ( | const std::string & | name | ) | [inline] |
void MBMesquite::StopWatchCollection::reset | ( | const Key | key | ) |
Definition at line 208 of file MsqTimer.cpp.
Referenced by reset().
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::reset | ( | const std::string & | name | ) | [inline] |
void MBMesquite::StopWatchCollection::start | ( | const Key | key | ) |
Definition at line 198 of file MsqTimer.cpp.
Referenced by start(), and MBMesquite::FunctionTimer::start().
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::start | ( | const std::string & | name | ) | [inline] |
void MBMesquite::StopWatchCollection::stop | ( | const Key | key | ) |
Definition at line 203 of file MsqTimer.cpp.
Referenced by stop(), and MBMesquite::FunctionTimer::~FunctionTimer().
MESQUITE_EXPORT void MBMesquite::StopWatchCollection::stop | ( | const std::string & | name | ) | [inline] |
double MBMesquite::StopWatchCollection::total_time | ( | const Key | key | ) | const |
Definition at line 213 of file MsqTimer.cpp.
Referenced by MBMesquite::operator<<(), and total_time().
MESQUITE_EXPORT double MBMesquite::StopWatchCollection::total_time | ( | const std::string & | name | ) | const [inline] |
Definition at line 164 of file MsqTimer.hpp.
References get_key(), and total_time().
{ return total_time( get_key( name ) ); }
std::vector< std::pair< std::string, StopWatch > > MBMesquite::StopWatchCollection::mEntries [private] |
Definition at line 184 of file MsqTimer.hpp.
Referenced by get_string(), and number_of_stop_watches().