Skip to content
Snippets Groups Projects
Commit 410f27ab authored by Mark Woolrich's avatar Mark Woolrich
Browse files

*** empty log message ***

parent 08d3afa8
No related branches found
No related tags found
No related merge requests found
...@@ -22,11 +22,11 @@ namespace Utilities{ ...@@ -22,11 +22,11 @@ namespace Utilities{
public: public:
TimingFunction(const char * pstr): TimingFunction(const char * pstr):
str(pstr), str(pstr),
time_taken(0.0), time_taken(0),
times_called(0) times_called(0)
{} {}
class comparer class comparer_name
{ {
public: public:
bool operator()(const TimingFunction* t1, const TimingFunction* t2) const bool operator()(const TimingFunction* t1, const TimingFunction* t2) const
...@@ -35,10 +35,20 @@ namespace Utilities{ ...@@ -35,10 +35,20 @@ namespace Utilities{
} }
}; };
class comparer_time_taken
{
public:
bool operator()(const TimingFunction* t1, const TimingFunction* t2) const
{
return t1->time_taken > t2->time_taken;
}
};
void start() {start_time = clock();} void start() {start_time = clock();}
void end() {time_taken += clock()-start_time; times_called++;} void end() {time_taken += clock()-start_time; times_called++;}
friend comparer; friend comparer_name;
friend comparer_time_taken;
friend ostream& operator<<(ostream& ostr, const TimingFunction* t); friend ostream& operator<<(ostream& ostr, const TimingFunction* t);
protected: protected:
...@@ -57,9 +67,9 @@ namespace Utilities{ ...@@ -57,9 +67,9 @@ namespace Utilities{
{ {
ostr << "<tr><td>" << t->str; ostr << "<tr><td>" << t->str;
ostr.setf(0, ios::floatfield); ostr.setf(0, ios::floatfield);
ostr << "<td align=center>" << t->time_taken/CLOCKS_PER_SEC; ostr << "<td align=center>" << float(t->time_taken)/CLOCKS_PER_SEC;
ostr.setf(ios::scientific, ios::floatfield); ostr.setf(ios::scientific, ios::floatfield);
ostr << "<td align=center>" << t->times_called << "<td align=center>" << (t->time_taken/t->times_called)/CLOCKS_PER_SEC; ostr << "<td align=center>" << t->times_called << "<td align=center>" << (t->time_taken/float(t->times_called))/CLOCKS_PER_SEC;
ostr << "</tr>"; ostr << "</tr>";
return ostr; return ostr;
} }
...@@ -83,7 +93,7 @@ namespace Utilities{ ...@@ -83,7 +93,7 @@ namespace Utilities{
{ {
// see if already in list: // see if already in list:
timingFunction = new TimingFunction(str); timingFunction = new TimingFunction(str);
set<TimingFunction*, TimingFunction::comparer>::iterator it = timingFunctions.find(timingFunction); set<TimingFunction*, TimingFunction::comparer_name>::iterator it = timingFunctions.find(timingFunction);
if(it== timingFunctions.end()) if(it== timingFunctions.end())
{ {
timingFunctions.insert(timingFunction); timingFunctions.insert(timingFunction);
...@@ -112,11 +122,13 @@ namespace Utilities{ ...@@ -112,11 +122,13 @@ namespace Utilities{
static void dump_times(const string& dir) static void dump_times(const string& dir)
{ {
multiset<TimingFunction*, TimingFunction::comparer_time_taken> timingFunctionsByTimeTaken(timingFunctions.begin(), timingFunctions.end());
ofstream out; ofstream out;
out.open((dir + "/timings.html").c_str(), ios::out); out.open((dir + "/timings.html").c_str(), ios::out);
out << "<HTML><TITLE>Tracer Timings</TITLE><BODY><table border=3 cellspacing=5>" << endl; out << "<HTML><TITLE>Tracer Timings</TITLE><BODY><table border=3 cellspacing=5>" << endl;
out << "<tr><td>Function<td align=center>Total Time(secs)<td align=center>Num of calls<td align=center>Time per call(secs)</tr>" << endl; out << "<tr><td>Function<td align=center>Total Time(secs)<td align=center>Num of calls<td align=center>Time per call(secs)</tr>" << endl;
copy(timingFunctions.begin(), timingFunctions.end(), ostream_iterator<TimingFunction*>(out, "\n")); copy(timingFunctionsByTimeTaken.begin(), timingFunctionsByTimeTaken.end(), ostream_iterator<TimingFunction*>(out, "\n"));
out << "</table></BODY></HTML>" << endl; out << "</table></BODY></HTML>" << endl;
out.close(); out.close();
} }
...@@ -128,7 +140,7 @@ namespace Utilities{ ...@@ -128,7 +140,7 @@ namespace Utilities{
static bool debug; static bool debug;
static bool timingon; static bool timingon;
static unsigned int pad; static unsigned int pad;
static set<TimingFunction*, TimingFunction::comparer> timingFunctions; static set<TimingFunction*, TimingFunction::comparer_name> timingFunctions;
string tmp; string tmp;
TimingFunction* timingFunction; TimingFunction* timingFunction;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment