Added counters to Cycle, added timestamp to Counter output
authorDmitriy Morozov <morozov@cs.duke.edu>
Fri, 14 Sep 2007 06:34:43 -0400
changeset 31 7a1bcccad811
parent 30 6d4e450015e4
child 32 075da5d7d6c3
Added counters to Cycle, added timestamp to Counter output
examples/alphashapes/alphashapes3d.cpp
include/topology/cycle.hpp
include/utilities/counter.h
include/utilities/counter.hpp
--- a/examples/alphashapes/alphashapes3d.cpp	Fri Sep 14 05:51:51 2007 -0400
+++ b/examples/alphashapes/alphashapes3d.cpp	Fri Sep 14 06:34:43 2007 -0400
@@ -19,6 +19,7 @@
 #endif
 
 	SetFrequency(GetCounter("filtration/pair"), 10000);
+	SetTrigger(GetCounter("filtration/pair"), GetCounter(""));
 
 	// Read in the point set and compute its Delaunay triangulation
 	std::istream& in = std::cin;
--- a/include/topology/cycle.hpp	Fri Sep 14 05:51:51 2007 -0400
+++ b/include/topology/cycle.hpp	Fri Sep 14 06:34:43 2007 -0400
@@ -7,6 +7,7 @@
 #include <boost/utility.hpp>
 
 #include "utilities/log.h"
+#include "utilities/counter.h"
 
 using boost::serialization::make_nvp;
 using boost::serialization::make_binary_object;
@@ -15,6 +16,11 @@
 static rlog::RLogChannel* rlCycle = 				DEF_CHANNEL( "topology/cycle", rlog::Log_Debug);
 #endif // LOGGING
 
+#ifdef COUNTERS
+static Counter*  cCycleAddBasic =		 			GetCounter("cycle/add/basic");
+static Counter*  cCycleAddComparison =		 		GetCounter("cycle/add/comparison");
+#endif // COUNTERS
+
 template<class I, class OrderCmp, class ConsistencyCmp>
 Cycle<I,OrderCmp,ConsistencyCmp>::
 Cycle(): sz(0)
@@ -189,13 +195,17 @@
 		if (cur1 == end())
 		{
 			while (cur2 != c.end())
+			{
 				push_back(*cur2++);
+				Count(cCycleAddBasic);
+			}
 			rLog(rlCycle, "After addition: %s", tostring(*this).c_str());
 			return *this;
 		}
 
 		// mod 2
 		int res = cmp.compare(*cur1, *cur2);
+		Count(cCycleAddComparison);
 		rLog(rlCycle, "Comparison result: %i", res);
 		if (res == 0)		// *cur1 == *cur2
 		{
@@ -214,6 +224,7 @@
 			++cur2;
 			++sz;
 		}
+		Count(cCycleAddBasic);
 	}
 
 	rLog(rlCycle, "After addition: %s", tostring(*this).c_str());
--- a/include/utilities/counter.h	Fri Sep 14 05:51:51 2007 -0400
+++ b/include/utilities/counter.h	Fri Sep 14 06:34:43 2007 -0400
@@ -53,7 +53,6 @@
 	private:	
 		SubCounterMap			subcounters_;
 		std::string				full_name_;
-
 };
 
 static		Counter				rootCounter;
--- a/include/utilities/counter.hpp	Fri Sep 14 05:51:51 2007 -0400
+++ b/include/utilities/counter.hpp	Fri Sep 14 06:34:43 2007 -0400
@@ -1,3 +1,6 @@
+#include <ctime>
+#include <cstdio>
+
 Counter*
 Counter::
 get_child(const std::string& path, std::string::size_type pos)
@@ -33,10 +36,18 @@
 Counter::
 print()
 {
-	// FIXME: add (colored) timestamp
+	time_t rawtime; time(&rawtime);
+	struct tm* timeinfo = localtime(&rawtime);
+
+	printf("%s(%02i:%02i:%02i)%s ",
+		   "\033[32m",			// green color
+			timeinfo->tm_hour,
+			timeinfo->tm_min,
+			timeinfo->tm_sec,
+			"\033[0m");			// normal color
 	std::cout << "Counter [" << full_name_ << "]: " << count << std::endl;
 	for (SubCountMap::const_iterator cur = subcount.begin(); cur != subcount.end(); ++cur)
-		std::cout << "  " << cur->first << ": " << cur->second << std::endl;
+		std::cout << "    " << cur->first << ": " << cur->second << std::endl;
 	for (SubCounterMap::iterator cur = subcounters_.begin(); cur != subcounters_.end(); ++cur)
 		cur->second->print();
 }