diff OrthancFramework/Sources/Toolbox.h @ 5430:b83192e7ad10

Now displaying timings when reading from/writing to disk in the verbose logs
author Alain Mazy <am@osimis.io>
date Mon, 20 Nov 2023 17:01:48 +0100
parents 1c3b0cf341f0
children 48b8dae6dc77
line wrap: on
line diff
--- a/OrthancFramework/Sources/Toolbox.h	Fri Nov 17 13:56:13 2023 +0100
+++ b/OrthancFramework/Sources/Toolbox.h	Mon Nov 20 17:01:48 2023 +0100
@@ -376,14 +376,30 @@
 
     static void RemoveSurroundingQuotes(std::string& value);
 
+    class ORTHANC_PUBLIC ElapsedTimer
+    {
+      boost::posix_time::ptime  start_;
+    public:
+      explicit ElapsedTimer();
+
+      uint64_t GetElapsedMilliseconds();
+      uint64_t GetElapsedMicroseconds();
+      uint64_t GetElapsedNanoseconds();
+      
+      std::string GetHumanElapsedDuration();
+      std::string GetHumanTransferSpeed(bool full, uint64_t sizeInBytes);
+      
+      void Restart();
+    };
+
     // 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_;
+      ElapsedTimer      timer_;
+      const std::string message_;
       bool logged_;
 
     public:
@@ -394,6 +410,12 @@
       void StopAndLog();
     };
 
+    static std::string GetHumanFileSize(uint64_t sizeInBytes);
+
+    static std::string GetHumanDuration(uint64_t durationInNanoseconds);
+
+    static std::string GetHumanTransferSpeed(bool full, uint64_t sizeInBytes, uint64_t durationInNanoseconds);
+
   };
 }