CombineHarvester
Logging.h
Go to the documentation of this file.
1 #ifndef CombineTools_Logging_h
2 #define CombineTools_Logging_h
3 #include <string>
4 #include <iostream>
5 #include <chrono>
6 
7 namespace ch {
8 
9 #define FNERROR(x) ch::FnError(x, __FILE__, __LINE__, __PRETTY_FUNCTION__)
10 
11 #define LOGLINE(x, y) LogLine(x, __func__, y)
12 
13 #define FNLOG(x) x << "[" << __func__ << "] "
14 #define FNLOGC(x, y) if (y) x << "[" << __func__ << "] "
15 
28 void LogLine(std::ostream& stream, std::string const& func,
29  std::string const& message);
30 
37 std::string FnError(std::string const& message, std::string const& file,
38  unsigned line, std::string const& fn);
39 
52 std::string GetQualififedName(std::string const& str);
53 
67 #define LAUNCH_FUNCTION_TIMER(x, y) \
68  static FnTimer x(ch::GetQualififedName(__PRETTY_FUNCTION__)); \
69  auto y = x.Inc();
70 
85 class FnTimer {
86  public:
87  class Token {
88  public:
89  explicit Token(FnTimer *src);
90  ~Token();
91  private:
92  FnTimer *src_;
93  };
94 
95  explicit FnTimer(std::string name);
96  ~FnTimer();
97  Token Inc();
98  void StartTimer();
99  void StopTimer();
100 
101  private:
102  std::string name_;
103  unsigned calls_;
104  std::chrono::time_point<std::chrono::system_clock> start_;
105  std::chrono::time_point<std::chrono::system_clock> end_;
106  double elapsed_;
107 };
108 }
109 
110 #endif
ch::FnError
std::string FnError(std::string const &message, std::string const &file, unsigned line, std::string const &fn)
Generates an error message which includes the name of the calling function and the filename and line ...
Definition: Logging.cc:32
ch::GetQualififedName
std::string GetQualififedName(std::string const &str)
Extracts the fully-qualified function name from a complete function signature.
Definition: Logging.cc:8
ch::FnTimer
Determine the total amount of time spent in a function.
Definition: Logging.h:85
ch::FnTimer::FnTimer
FnTimer(std::string name)
Definition: Logging.cc:49
ch::FnTimer::StartTimer
void StartTimer()
Definition: Logging.cc:59
ch
Definition: Algorithm.h:10
ch::LogLine
void LogLine(std::ostream &stream, std::string const &func, std::string const &message)
Writes a logging message to a given ostream.
Definition: Logging.cc:27
ch::FnTimer::Token::Token
Token(FnTimer *src)
Definition: Logging.cc:64
ch::FnTimer::StopTimer
void StopTimer()
Definition: Logging.cc:60
ch::FnTimer::Token
Definition: Logging.h:87
ch::FnTimer::Inc
Token Inc()
Definition: Logging.cc:55
ch::FnTimer::~FnTimer
~FnTimer()
Definition: Logging.cc:50
ch::FnTimer::Token::~Token
~Token()
Definition: Logging.cc:65