Mercurial > hg > orthanc
diff OrthancFramework/Sources/Toolbox.h @ 5390:1c3b0cf341f0
Toolbox: added ElapsedTimeLogger debug tool
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 26 Sep 2023 12:28:13 +0200 |
parents | b31c73bc7cb6 |
children | b83192e7ad10 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Toolbox.h Thu Sep 21 18:18:25 2023 +0200 +++ b/OrthancFramework/Sources/Toolbox.h Tue Sep 26 12:28:13 2023 +0200 @@ -67,6 +67,8 @@ # include <pugixml.hpp> #endif +#include <boost/date_time/posix_time/posix_time.hpp> + namespace Orthanc { @@ -373,6 +375,25 @@ const Json::Value& source); static void RemoveSurroundingQuotes(std::string& value); + + // This is a helper class to measure and log time spend e.g in a method. + // This should be used only during debugging and should likely not ever used in a release. + // By default, you should use it as a RAII but you may force Restart/StopAndLog manually if needed. + class ORTHANC_PUBLIC ElapsedTimeLogger + { + private: + const std::string message_; + boost::posix_time::ptime start_; + bool logged_; + + public: + explicit ElapsedTimeLogger(const std::string& message); + ~ElapsedTimeLogger(); + + void Restart(); + void StopAndLog(); + }; + }; }