From 6f7543c7dc2964e89439ab7f70c336046f06ac23 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 11 Jun 2021 10:08:06 +0200 Subject: [PATCH] Timer - convenience constructors to disable tracing and/or timing Examples: Timer t0("name"); Timer t1("name", NoTracing); Timer t2("name", NoTiming); Timer t3("name", NoTracing, NoTiming); Timer t4("name", NoTiming, NoTracing); --- libsrc/core/profiler.hpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/libsrc/core/profiler.hpp b/libsrc/core/profiler.hpp index e6795f69..b8bd09e8 100644 --- a/libsrc/core/profiler.hpp +++ b/libsrc/core/profiler.hpp @@ -148,16 +148,42 @@ namespace ngcore }; + namespace detail { + struct NoTracing_t{}; + struct NoTiming_t{}; + } + + static detail::NoTracing_t NoTracing; + static detail::NoTiming_t NoTiming; template class Timer { int timernr; - public: - Timer (const std::string & name) + int Init( const std::string & name ) { - timernr = NgProfiler::CreateTimer (name); + return NgProfiler::CreateTimer (name); } + public: + Timer (const std::string & name) : timernr(Init(name)) + { } + + template> + Timer( const std::string & name, detail::NoTracing_t ) : timernr(Init(name)) + { } + + template> + Timer( const std::string & name, detail::NoTiming_t ) : timernr(Init(name)) + { } + + template> + Timer( const std::string & name, detail::NoTracing_t, detail::NoTiming_t ) : timernr(Init(name)) + { } + + template> + Timer( const std::string & name, detail::NoTiming_t, detail::NoTracing_t ) : timernr(Init(name)) + { } + void SetName (const std::string & name) { NgProfiler::SetName (timernr, name);