[cig-commits] r12945 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Sep 24 04:10:31 PDT 2008
Author: luis
Date: 2008-09-24 04:10:31 -0700 (Wed, 24 Sep 2008)
New Revision: 12945
Added:
cs/cigma/trunk/src/ProgressTimer.cpp
cs/cigma/trunk/src/ProgressTimer.h
Log:
Verbose timer for reporting progress & duration
Added: cs/cigma/trunk/src/ProgressTimer.cpp
===================================================================
--- cs/cigma/trunk/src/ProgressTimer.cpp (rev 0)
+++ cs/cigma/trunk/src/ProgressTimer.cpp 2008-09-24 11:10:31 UTC (rev 12945)
@@ -0,0 +1,60 @@
+#include "ProgressTimer.h"
+
+
+// ----------------------------------------------------------------------------
+
+ProgressTimer::ProgressTimer()
+{
+ t_0 = 0;
+ total = 0;
+ current = 0;
+}
+
+ProgressTimer::~ProgressTimer()
+{
+}
+
+
+// ----------------------------------------------------------------------------
+
+void ProgressTimer::printHeader(std::ostream &os, const char *firstcol)
+{
+ assert(firstcol != 0);
+ os << firstcol << " rate mins eta total progress\n";
+}
+
+void ProgressTimer::start(int total)
+{
+ time(&t_0);
+ this->total = total;
+}
+
+void ProgressTimer::update(int current)
+{
+ time(&t_n);
+ this->current = current;
+ elapsed_mins = (t_n - t_0) / 60.0;
+ mins_per_num = elapsed_mins / current;
+ num_per_sec = (1.0/60.0) / mins_per_num;
+ remaining_mins = (total - current) * mins_per_num;
+ total_mins = total * mins_per_num;
+ progress = 100 * elapsed_mins / total_mins;
+}
+
+// ----------------------------------------------------------------------------
+
+std::ostream &operator<<(std::ostream &os, const ProgressTimer &T)
+{
+ os << T.current << " "
+ << T.num_per_sec << " "
+ << T.elapsed_mins << " "
+ << T.remaining_mins << " "
+ << T.total_mins << " "
+ << T.progress << "%"
+ << " "
+ " "
+ "\r"
+ << std::flush;
+}
+
+// ----------------------------------------------------------------------------
Added: cs/cigma/trunk/src/ProgressTimer.h
===================================================================
--- cs/cigma/trunk/src/ProgressTimer.h (rev 0)
+++ cs/cigma/trunk/src/ProgressTimer.h 2008-09-24 11:10:31 UTC (rev 12945)
@@ -0,0 +1,34 @@
+#ifndef __PROGRESS_TIMER_H__
+#define __PROGRESS_TIMER_H__
+
+#include <iostream>
+#include <cassert>
+#include <ctime>
+
+class ProgressTimer
+{
+public:
+ int total;
+ int current;
+ time_t t_0, t_n;
+ double elapsed_mins;
+ double mins_per_num;
+ double num_per_sec;
+ double remaining_mins;
+ double total_mins;
+ double progress;
+
+public:
+ ProgressTimer();
+ ~ProgressTimer();
+
+ void printHeader(std::ostream &os, const char *firstcol);
+ void start(int total);
+ void update(int current);
+};
+
+
+std::ostream &operator<<(std::ostream &os, const ProgressTimer &T);
+
+
+#endif
More information about the cig-commits
mailing list