29 #ifdef MSQ_USE_OLD_IO_HEADERS
30 # include <iostream.h>
41 # include <sys/times.h>
46 # define CLK_TCK sysconf(_SC_CLK_TCK)
48 # include <sys/param.h>
52 # error times(3) w/out CLK_TCK. Please report this.
60 static inline double now()
64 return (
double)(t.tms_utime + t.tms_stime) / CLK_TCK;
66 #elif defined(HAVE_CLOCK)
67 # ifdef MSQ_USE_OLD_C_HEADERS
72 static inline double now()
74 return (
double)msq_stdc::clock() / CLOCKS_PER_SEC;
89 atLastCheck = atBirth;
94 double right_now = now();
95 double rv = right_now - atLastCheck;
96 atLastCheck = right_now;
102 return now() - atBirth;
110 timeAtLastStart=now();
120 totalTime += now() - timeAtLastStart;
133 double rv = totalTime;
135 rv += now() - timeAtLastStart;
140 const msq_std::string &name,
154 for (i = 0; i < mEntries.size(); i++)
156 if (mEntries[i].first ==
"")
158 mEntries[
i].first = name;
159 mEntries[
i].second.reset();
164 if (i == mEntries.size())
166 mEntries.push_back(msq_std::pair<msq_std::string, StopWatch>(name,
StopWatch()));
171 else if (fail_if_exists)
179 const msq_std::string &name)
const
183 for (
size_t i = 0;
i < mEntries.size();
i++)
185 if (mEntries[
i].first == name)
199 if (key == mEntries.size())
202 while (!mEntries.empty() && mEntries.back().first ==
"")
208 else if (key > 0 && key < mEntries.size())
211 mEntries[key-1].first =
"";
220 key <= mEntries.size() &&
221 mEntries[key-1].first !=
"")
222 mEntries[key-1].second.start();
229 key <= mEntries.size() &&
230 mEntries[key-1].first !=
"")
231 mEntries[key-1].second.stop();
238 key <= mEntries.size())
239 mEntries[key-1].second.reset();
247 key <= mEntries.size() &&
248 mEntries[key-1].first !=
"")
249 return mEntries[key-1].second.total_time();
258 key <= mEntries.size() &&
259 mEntries[key-1].first !=
"")
260 return mEntries[key-1].second.number_of_starts();
270 msq_std::vector<Key> &sorted_keys)
272 int num_watches=mEntries.size();
273 int *sorted_indices=
new int[num_watches];
276 for(i=0;i<num_watches;++
i){
282 while(counter<num_watches){
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();
295 for(i=index_to_max;i<num_watches;++
i){
296 if(mEntries[i].second.total_time()>=current_max && sorted_indices[
i]==0)
299 sorted_indices[
i]=counter;
300 sorted_keys.push_back(i+1);
305 delete[] sorted_indices;
314 msq_std::vector<Mesquite::StopWatchCollection::Key> sorted_keys;
316 int number_of_keys=sorted_keys.size();
318 str<<
"\nTIME | NUM. STARTS | TIMER NAME ("<<number_of_keys<<
" timers)\n";
319 for(i=0;i<number_of_keys;++
i){
320 str<<msq_stdio::setiosflags(msq_stdio::ios::left)
321 <<msq_stdio::setw(13)
322 <<Mesquite::GlobalStopWatches.
total_time(sorted_keys[i])
324 <<msq_stdio::setw(13)
327 <<Mesquite::GlobalStopWatches.
get_string(sorted_keys[i])
Mesquite::StopWatchCollection GlobalStopWatches
void start(const Key key)
msq_std::string get_string(const Key key)
Gets the string associated with a key.
double since_last_check()
void remove(const Key key)
Key get_key(const msq_std::string &name) const
double since_birth() const
void reset(const Key key)
Key add(const msq_std::string &name, bool fail_if_exists=true)
void get_keys_sorted_by_time(msq_std::vector< Key > &sorted_keys)
msq_stdio::ostream & operator<<(msq_stdio::ostream &s, const Matrix3D &A)
double total_time(const Key key) const
double total_time() const
int number_of_starts(const Key key) const