DebTime.hh 1.42 KB
Newer Older
1 2 3 4 5 6 7 8
// (C) Copyright 2015 by Autodesk, Inc.

#ifndef BASE_DEBTIME_HH_INCLUDED
#define BASE_DEBTIME_HH_INCLUDED

#include <Base/Utils/StopWatch.hh>
#include <Base/Debug/DebOut.hh>

9 10
#ifdef DEB_ON

11 12 13 14 15
namespace Debug {

class StopWatchSession
{
public:
Max Lyon's avatar
Max Lyon committed
16
  StopWatchSession(Enter& _deb, const char* _sssn_name = NULL,
17 18 19 20 21 22
    const int _deb_lvl = 2) 
    : deb(_deb), sssn_name_(_sssn_name), deb_lvl_(_deb_lvl)
  {
    sw_.start();
  }

23
  ~StopWatchSession() noexcept(false)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  {
    // TODO: implement "prettier" DEB out if seconds turn into minutes/hours/etc
    DEB_line(deb_lvl_, sssn_name_ << " took " << sw_.stop()/1000.0 << " s.");
  }

private:
  Enter& deb; // intentional variable name match with the DEB_marcos!
  const char* sssn_name_;
  const int deb_lvl_;
  Base::StopWatch sw_;

private:
  // disable copy and assignment
  StopWatchSession(const StopWatchSession&);
  StopWatchSession& operator=(const StopWatchSession&);
};

} //namespace Debug

#define DEB_time_session(SSSN, LL) \
  Debug::StopWatchSession __sw_sssn(deb, SSSN, LL);

#define DEB_time_session_def(SSSN) \
  Debug::StopWatchSession __sw_sssn(deb, SSSN, 2);

#define DEB_time_func(LL) DEB_enter_func \
  Debug::StopWatchSession __sw_func(deb, __FUNCTION__, LL);

#define DEB_time_func_def DEB_time_func(2)

54 55 56 57 58 59 60 61 62 63 64 65
#else

#define DEB_time_session(SSSN, LL)

#define DEB_time_session_def(SSSN)

#define DEB_time_func(LL)

#define DEB_time_func_def

#endif // DEB_ON

66
#endif//BASE_DEBTIME_HH_INCLUDED