Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StopWatchCollection Class Reference

#include <MsqTimer.hpp>

Public Types

typedef size_t Key
 
typedef size_t Key
 

Public Member Functions

 StopWatchCollection ()
 
Key add (const msq_std::string &name, bool fail_if_exists=true)
 
Key get_key (const msq_std::string &name) const
 
msq_std::string get_string (const Key key)
 Gets the string associated with a key. More...
 
void get_string (const Key key, msq_std::string &new_string)
 Gets the string associated with a key. More...
 
void remove (const Key key)
 
void remove (const msq_std::string &name)
 
void start (const Key key)
 
void start (const msq_std::string &name)
 
void stop (const Key key)
 
void stop (const msq_std::string &name)
 
void reset (const Key key)
 
void reset (const msq_std::string &name)
 
double total_time (const Key key) const
 
double total_time (const msq_std::string &name) const
 
int number_of_starts (const Key key) const
 
int number_of_starts (const msq_std::string &name) const
 
int number_of_stop_watches ()
 
void get_keys_sorted_by_time (msq_std::vector< Key > &sorted_keys)
 
 StopWatchCollection ()
 
Key add (const msq_std::string &name, bool fail_if_exists=true)
 
Key get_key (const msq_std::string &name) const
 
msq_std::string get_string (const Key key)
 Gets the string associated with a key. More...
 
void get_string (const Key key, msq_std::string &new_string)
 Gets the string associated with a key. More...
 
void remove (const Key key)
 
void remove (const msq_std::string &name)
 
void start (const Key key)
 
void start (const msq_std::string &name)
 
void stop (const Key key)
 
void stop (const msq_std::string &name)
 
void reset (const Key key)
 
void reset (const msq_std::string &name)
 
double total_time (const Key key) const
 
double total_time (const msq_std::string &name) const
 
int number_of_starts (const Key key) const
 
int number_of_starts (const msq_std::string &name) const
 
int number_of_stop_watches ()
 
void get_keys_sorted_by_time (msq_std::vector< Key > &sorted_keys)
 

Private Attributes

msq_std::vector< msq_std::pair
< msq_std::string, StopWatch > > 
mEntries
 

Detailed Description

Definition at line 115 of file includeLinks/MsqTimer.hpp.

Member Typedef Documentation

typedef size_t Key

Definition at line 118 of file includeLinks/MsqTimer.hpp.

typedef size_t Key

Definition at line 118 of file src/Misc/MsqTimer.hpp.

Constructor & Destructor Documentation

StopWatchCollection ( )
inline

Definition at line 121 of file includeLinks/MsqTimer.hpp.

122  {}
StopWatchCollection ( )
inline

Definition at line 121 of file src/Misc/MsqTimer.hpp.

122  {}

Member Function Documentation

Mesquite::StopWatchCollection::Key add ( const msq_std::string &  name,
bool  fail_if_exists = true 
)

Definition at line 139 of file Misc/MsqTimer.cpp.

References i, and key.

142 {
143  // Don't allow empty name
144  if (name == "")
145  return 0;
146 
147  Key key = get_key(name);
148 
149  // If the named stopwatch doesn't exist...
150  if (!key)
151  {
152  // See if there is an unused existing stopwatch
153  size_t i;
154  for (i = 0; i < mEntries.size(); i++)
155  {
156  if (mEntries[i].first == "")
157  {
158  mEntries[i].first = name;
159  mEntries[i].second.reset();
160  break;
161  }
162  }
163  // If not, create a new one
164  if (i == mEntries.size())
165  {
166  mEntries.push_back(msq_std::pair<msq_std::string, StopWatch>(name, StopWatch()));
167  }
168  key = i+1;
169  }
170  // If it already existed...
171  else if (fail_if_exists)
172  key = 0;
173 
174  return key;
175 }
Key get_key(const msq_std::string &name) const
blockLoc i
Definition: read.cpp:79
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76
Key add ( const msq_std::string &  name,
bool  fail_if_exists = true 
)
Mesquite::StopWatchCollection::Key get_key ( const msq_std::string &  name) const

Definition at line 178 of file Misc/MsqTimer.cpp.

References i, and key.

Referenced by StopWatchCollection::number_of_starts(), StopWatchCollection::remove(), StopWatchCollection::reset(), StopWatchCollection::start(), StopWatchCollection::stop(), and StopWatchCollection::total_time().

180 {
181  Key key = 0;
182 
183  for (size_t i = 0; i < mEntries.size(); i++)
184  {
185  if (mEntries[i].first == name)
186  {
187  key = i + 1;
188  break;
189  }
190  }
191 
192  return key;
193 }
blockLoc i
Definition: read.cpp:79
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

Key get_key ( const msq_std::string &  name) const
void get_keys_sorted_by_time ( msq_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 269 of file Misc/MsqTimer.cpp.

References i.

Referenced by Mesquite::operator<<().

271 {
272  int num_watches=mEntries.size();
273  int *sorted_indices=new int[num_watches];
274  int i=0;
275  int counter=0;
276  for(i=0;i<num_watches;++i){
277  sorted_indices[i]=0;
278  }
279  double current_max;
280  int index_to_max;
281  //While we haven't added all of the Keys to the vector
282  while(counter<num_watches){
283  current_max=-1;
284  index_to_max=-1;
285  //loop over the times and find the largest remaining
286  for(i=0;i<num_watches;++i){
287  if(mEntries[i].second.total_time()>current_max && sorted_indices[i]==0){
288  current_max=mEntries[i].second.total_time();
289  index_to_max=i;
290  }
291  }
292  //Add the key associated with index_to_max and any subsequent
293  //keys which are associated with a StopWatch that has a total
294  //time equal to current_max;
295  for(i=index_to_max;i<num_watches;++i){
296  if(mEntries[i].second.total_time()>=current_max && sorted_indices[i]==0)
297  {
298  counter++;
299  sorted_indices[i]=counter;
300  sorted_keys.push_back(i+1);
301  }
302  }
303  }
304  //clean up
305  delete[] sorted_indices;
306 }
blockLoc i
Definition: read.cpp:79
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries

Here is the caller graph for this function:

void get_keys_sorted_by_time ( msq_std::vector< Key > &  sorted_keys)
msq_std::string get_string ( const Key  key)
inline

Gets the string associated with a key.

Definition at line 137 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::mEntries.

137  {
138  return mEntries[key-1].first;}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76
msq_std::string get_string ( const Key  key)
inline

Gets the string associated with a key.

Definition at line 137 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::mEntries.

Referenced by Mesquite::operator<<().

137  {
138  return mEntries[key-1].first;}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

void get_string ( const Key  key,
msq_std::string &  new_string 
)
inline

Gets the string associated with a key.

Definition at line 140 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::mEntries.

140  {
141  new_string=mEntries[key-1].first;}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76
void get_string ( const Key  key,
msq_std::string &  new_string 
)
inline

Gets the string associated with a key.

Definition at line 140 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::mEntries.

140  {
141  new_string=mEntries[key-1].first;}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76
int number_of_starts ( const Key  key) const
int number_of_starts ( const Key  key) const

Definition at line 254 of file Misc/MsqTimer.cpp.

Referenced by StopWatchCollection::number_of_starts(), and Mesquite::operator<<().

256 {
257  if (key > 0 &&
258  key <= mEntries.size() &&
259  mEntries[key-1].first != "")
260  return mEntries[key-1].second.number_of_starts();
261  else
262  return 0;
263 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

int number_of_starts ( const msq_std::string &  name) const
inline

Definition at line 170 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::number_of_starts().

171  { return number_of_starts(get_key(name));}
Key get_key(const msq_std::string &name) const
int number_of_starts(const Key key) const

Here is the call graph for this function:

int number_of_starts ( const msq_std::string &  name) const
inline

Definition at line 170 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::number_of_starts().

171  { return number_of_starts(get_key(name));}
Key get_key(const msq_std::string &name) const
int number_of_starts(const Key key) const

Here is the call graph for this function:

int number_of_stop_watches ( )
inline

Definition at line 174 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::mEntries.

174  {
175  return mEntries.size();}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
int number_of_stop_watches ( )
inline

Definition at line 174 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::mEntries.

174  {
175  return mEntries.size();}
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
void remove ( const Key  key)

Definition at line 195 of file Misc/MsqTimer.cpp.

197 {
198  // Get rid of anything at the end of the list
199  if (key == mEntries.size())
200  {
201  mEntries.pop_back();
202  while (!mEntries.empty() && mEntries.back().first == "")
203  {
204  mEntries.pop_back();
205  }
206  }
207 
208  else if (key > 0 && key < mEntries.size())
209  {
210  // If in the middle of the list, set its name to ""
211  mEntries[key-1].first = "";
212  }
213 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76
void remove ( const Key  key)
void remove ( const msq_std::string &  name)
inline

Definition at line 145 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key().

146  { remove(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void remove ( const msq_std::string &  name)
inline

Definition at line 145 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key().

146  { remove(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void reset ( const Key  key)

Definition at line 234 of file Misc/MsqTimer.cpp.

Referenced by StopWatchCollection::reset().

236 {
237  if (key > 0 &&
238  key <= mEntries.size())
239  mEntries[key-1].second.reset();
240 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

void reset ( const Key  key)
void reset ( const msq_std::string &  name)
inline

Definition at line 160 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::reset().

161  { reset(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void reset ( const msq_std::string &  name)
inline

Definition at line 160 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::reset().

161  { reset(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void start ( const Key  key)
void start ( const Key  key)

Definition at line 216 of file Misc/MsqTimer.cpp.

Referenced by StopWatchCollection::start(), and FunctionTimer::start().

218 {
219  if (key > 0 &&
220  key <= mEntries.size() &&
221  mEntries[key-1].first != "")
222  mEntries[key-1].second.start();
223 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

void start ( const msq_std::string &  name)
inline

Definition at line 150 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::start().

151  { start(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void start ( const msq_std::string &  name)
inline

Definition at line 150 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::start().

151  { start(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void stop ( const Key  key)
void stop ( const Key  key)

Definition at line 225 of file Misc/MsqTimer.cpp.

Referenced by StopWatchCollection::stop(), and FunctionTimer::~FunctionTimer().

227 {
228  if (key > 0 &&
229  key <= mEntries.size() &&
230  mEntries[key-1].first != "")
231  mEntries[key-1].second.stop();
232 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

void stop ( const msq_std::string &  name)
inline

Definition at line 155 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::stop().

156  { stop(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

void stop ( const msq_std::string &  name)
inline

Definition at line 155 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::stop().

156  { stop(get_key(name)); }
Key get_key(const msq_std::string &name) const

Here is the call graph for this function:

double total_time ( const Key  key) const
double total_time ( const Key  key) const

Definition at line 243 of file Misc/MsqTimer.cpp.

Referenced by Mesquite::operator<<(), and StopWatchCollection::total_time().

245 {
246  if (key > 0 &&
247  key <= mEntries.size() &&
248  mEntries[key-1].first != "")
249  return mEntries[key-1].second.total_time();
250  else
251  return 0.0;
252 }
msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
static T_Key key
Definition: vinci_lass.c:76

Here is the caller graph for this function:

double total_time ( const msq_std::string &  name) const
inline

Definition at line 166 of file includeLinks/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::total_time().

167  { return total_time(get_key(name)); }
Key get_key(const msq_std::string &name) const
double total_time(const Key key) const

Here is the call graph for this function:

double total_time ( const msq_std::string &  name) const
inline

Definition at line 166 of file src/Misc/MsqTimer.hpp.

References StopWatchCollection::get_key(), and StopWatchCollection::total_time().

167  { return total_time(get_key(name)); }
Key get_key(const msq_std::string &name) const
double total_time(const Key key) const

Here is the call graph for this function:

Member Data Documentation

msq_std::vector< msq_std::pair< msq_std::string, StopWatch > > mEntries
private

The documentation for this class was generated from the following files: