From b2b23ffba2b592052d061d9df08a1448f6d1b749 Mon Sep 17 00:00:00 2001 From: Mark Woolrich <woolrich@fmrib.ox.ac.uk> Date: Fri, 9 Aug 2002 15:30:07 +0000 Subject: [PATCH] *** empty log message *** --- log.cc | 6 +++--- log.h | 46 ++++++++++++++++++++++++++-------------------- time_tracer.cc | 6 ++++-- time_tracer.h | 42 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 70 insertions(+), 30 deletions(-) diff --git a/log.cc b/log.cc index 40ce561..ec89561 100644 --- a/log.cc +++ b/log.cc @@ -10,10 +10,10 @@ namespace Utilities { - Logger* LogSingleton::logger = NULL; + Log* LogSingleton::logger = NULL; int LogSingleton::count = 0; - void Logger::makeDir(const string& pdirname, const string& plogfilename, bool pstream_to_logfile, bool pstream_to_cout) + void Log::makeDir(const string& pdirname, const string& plogfilename, bool pstream_to_logfile, bool pstream_to_cout) { if(logEstablished) { @@ -58,7 +58,7 @@ namespace Utilities { logEstablished = true; } - void Logger::setDir(const string& pdirname, const string& plogfilename, bool pstream_to_logfile, bool pstream_to_cout) + void Log::setDir(const string& pdirname, const string& plogfilename, bool pstream_to_logfile, bool pstream_to_cout) { if(logEstablished) { diff --git a/log.h b/log.h index 6661af7..015828a 100644 --- a/log.h +++ b/log.h @@ -4,6 +4,14 @@ Copyright (C) 1999-2000 University of Oxford */ +/* The Log class allows for instantiation of more than one Log +either sharing directories or not. However, Logs can not share log files. +Or you can work with the LogSIngleton class. + +A Log can open new logfiles in the same log directory or start on an +entirely new directory. You can stream directly to a Log with flags +determining streaming to the Logfile and/or cout. */ + /* CCOPYRIGHT */ #if !defined(log_h) @@ -29,9 +37,9 @@ namespace Utilities{ return string(strc); } - class Logger; + class Log; - template<class t> Logger& operator<<(Logger& log, const t& obj) + template<class t> Log& operator<<(Log& log, const t& obj) { if(log.stream_to_logfile) log.logfileout << obj; @@ -42,12 +50,12 @@ namespace Utilities{ return log; } - class Logger + class Log { public: - Logger():logEstablished(false) {} + Log():logEstablished(false) {} - Logger(const string& pdirname, const string& plogfilename = "logfile", bool pstream_to_logfile = true, bool pstream_to_cout = false, bool makedir = true):logEstablished(false) + Log(const string& pdirname, const string& plogfilename = "logfile", bool pstream_to_logfile = true, bool pstream_to_cout = false, bool makedir = true):logEstablished(false) { if(makedir) makeDir(pdirname, plogfilename, pstream_to_logfile, pstream_to_cout); @@ -55,9 +63,9 @@ namespace Utilities{ setDir(pdirname, plogfilename, pstream_to_logfile, pstream_to_cout); } - ~Logger() { logfileout.close(); } + ~Log() { logfileout.close(); } - /** Need to call makeDir or setDir before Logger can be used */ + /** Need to call makeDir or setDir before Log can be used */ /** Makes a directory to place results into: keeps adding "+" to pdirname until unique directory is made. */ @@ -82,7 +90,7 @@ namespace Utilities{ /** stream_to_cout and stream_to_logfile respectively */ /** use like a normal ostream, e.g. log.str() << "hello" << endl */ /** NOTE: can simply stream straight to Log instead, e.g. log << "hello" << endl */ - Logger& str(); + Log& str(); /** sets whether or not you stream to cout */ void set_stream_to_cout(bool in = true) { stream_to_cout = in; } @@ -101,8 +109,8 @@ namespace Utilities{ private: - const Logger& operator=(Logger&); - Logger(Logger&); + const Log& operator=(Log&); + Log(Log&); string dir; ofstream logfileout; @@ -114,14 +122,14 @@ namespace Utilities{ bool stream_to_cout; template<class t> - friend Logger& operator<<(Logger& log, const t& obj); + friend Log& operator<<(Log& log, const t& obj); }; class LogSingleton { public: - static Logger& getInstance(); + static Log& getInstance(); ~LogSingleton() { delete logger; } @@ -134,22 +142,20 @@ namespace Utilities{ const LogSingleton& operator=(LogSingleton&); LogSingleton(LogSingleton&); - static Logger* logger; + static Log* logger; static int count; }; - typedef LogSingleton Log; - - inline Logger& LogSingleton::getInstance(){ + inline Log& LogSingleton::getInstance(){ if(logger == NULL) - logger = new Logger(); + logger = new Log(); return *logger; } - inline void Logger::setLogFile(const string& plogfilename) { + inline void Log::setLogFile(const string& plogfilename) { if(!logEstablished) { @@ -172,7 +178,7 @@ namespace Utilities{ logEstablished = true; } - inline Logger& Logger::str() { + inline Log& Log::str() { if(!logEstablished) { @@ -182,7 +188,7 @@ namespace Utilities{ return *this; } - inline const string Logger::appendDir(const string& filename) const { + inline const string Log::appendDir(const string& filename) const { if(!logEstablished) { diff --git a/time_tracer.cc b/time_tracer.cc index 5502e92..31d3e4f 100644 --- a/time_tracer.cc +++ b/time_tracer.cc @@ -15,10 +15,12 @@ namespace Utilities { - bool Time_Tracer::debug = false; + bool Time_Tracer::instantstack = false; + bool Time_Tracer::runningstack = false; bool Time_Tracer::timingon = false; unsigned int Time_Tracer::pad = 0; - set<TimingFunction*, TimingFunction::comparer> Time_Tracer::timingFunctions; + set<TimingFunction*, TimingFunction::comparer_name> Time_Tracer::timingFunctions; + stack<string> Time_Tracer::stk; } diff --git a/time_tracer.h b/time_tracer.h index ddba607..698903d 100644 --- a/time_tracer.h +++ b/time_tracer.h @@ -14,6 +14,7 @@ #include <string> #include <time.h> #include <set> +#include <stack> namespace Utilities{ @@ -80,14 +81,18 @@ namespace Utilities{ public: Time_Tracer(char* str) { - if(debug) + + if(instantstack) { tmp = ""; pad++; for(unsigned int i = 0; i < pad; i++) tmp = tmp + " "; - cout << tmp << str << endl; + stk.push(string(str)); + + if(runningstack) + cout << tmp << str << endl; } if(timingon) { @@ -110,7 +115,10 @@ namespace Utilities{ virtual ~Time_Tracer() { - if(debug && pad > 0) + if(instantstack) + stk.pop(); + + if(runningstack && pad > 0) { cout << tmp << "finished" << endl; pad--; @@ -119,6 +127,7 @@ namespace Utilities{ { timingFunction->end(); } + } static void dump_times(const string& dir) @@ -134,14 +143,37 @@ namespace Utilities{ out.close(); } - static void setdebugon() {debug = true;} + static void dump_instant_stack() + { + // tmp stack to put values into for restoring stack after outputting + stack<string> tmpstk; + + while(!stk.empty()) + { + + cout << stk.top() << endl; + tmpstk.push(stk.top()); + stk.pop(); + } + + while(!tmpstk.empty()) + { + stk.push(tmpstk.top()); + tmpstk.pop(); + } + } + + static void setinstantstackon() {instantstack = true;} + static void setrunningstackon() {runningstack = true;} static void settimingon() {timingon = true;} protected: - static bool debug; + static bool instantstack; + static bool runningstack; static bool timingon; static unsigned int pad; static set<TimingFunction*, TimingFunction::comparer_name> timingFunctions; + static stack<string> stk; string tmp; TimingFunction* timingFunction; -- GitLab