Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
5429:d40ac28b9702 | 5430:b83192e7ad10 |
---|---|
374 static void WriteStyledJson(std::string& target, | 374 static void WriteStyledJson(std::string& target, |
375 const Json::Value& source); | 375 const Json::Value& source); |
376 | 376 |
377 static void RemoveSurroundingQuotes(std::string& value); | 377 static void RemoveSurroundingQuotes(std::string& value); |
378 | 378 |
379 class ORTHANC_PUBLIC ElapsedTimer | |
380 { | |
381 boost::posix_time::ptime start_; | |
382 public: | |
383 explicit ElapsedTimer(); | |
384 | |
385 uint64_t GetElapsedMilliseconds(); | |
386 uint64_t GetElapsedMicroseconds(); | |
387 uint64_t GetElapsedNanoseconds(); | |
388 | |
389 std::string GetHumanElapsedDuration(); | |
390 std::string GetHumanTransferSpeed(bool full, uint64_t sizeInBytes); | |
391 | |
392 void Restart(); | |
393 }; | |
394 | |
379 // This is a helper class to measure and log time spend e.g in a method. | 395 // This is a helper class to measure and log time spend e.g in a method. |
380 // This should be used only during debugging and should likely not ever used in a release. | 396 // This should be used only during debugging and should likely not ever used in a release. |
381 // By default, you should use it as a RAII but you may force Restart/StopAndLog manually if needed. | 397 // By default, you should use it as a RAII but you may force Restart/StopAndLog manually if needed. |
382 class ORTHANC_PUBLIC ElapsedTimeLogger | 398 class ORTHANC_PUBLIC ElapsedTimeLogger |
383 { | 399 { |
384 private: | 400 private: |
385 const std::string message_; | 401 ElapsedTimer timer_; |
386 boost::posix_time::ptime start_; | 402 const std::string message_; |
387 bool logged_; | 403 bool logged_; |
388 | 404 |
389 public: | 405 public: |
390 explicit ElapsedTimeLogger(const std::string& message); | 406 explicit ElapsedTimeLogger(const std::string& message); |
391 ~ElapsedTimeLogger(); | 407 ~ElapsedTimeLogger(); |
392 | 408 |
393 void Restart(); | 409 void Restart(); |
394 void StopAndLog(); | 410 void StopAndLog(); |
395 }; | 411 }; |
412 | |
413 static std::string GetHumanFileSize(uint64_t sizeInBytes); | |
414 | |
415 static std::string GetHumanDuration(uint64_t durationInNanoseconds); | |
416 | |
417 static std::string GetHumanTransferSpeed(bool full, uint64_t sizeInBytes, uint64_t durationInNanoseconds); | |
396 | 418 |
397 }; | 419 }; |
398 } | 420 } |
399 | 421 |
400 | 422 |