changeset 716:66c421fc2fbf

EnablePerformanceLogs
author Alain Mazy <am@orthanc.team>
date Tue, 22 Jul 2025 11:14:44 +0200
parents d8114860cba4
children a90d16a5a27d
files NEWS Plugin/Configuration.cpp Plugin/Configuration.h Plugin/WadoRs.cpp
diffstat 4 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Jun 13 15:30:50 2025 +0200
+++ b/NEWS	Tue Jul 22 11:14:44 2025 +0200
@@ -5,6 +5,9 @@
   files from the storage when answering to a WADO-RS query.  A value > 1 is meaningful 
   only if the storage is a distributed network storage (e.g object storage plugin).
   A value of 0 means reading and writing are performed in sequence (default behaviour).
+* New configuration "EnablePerformanceLogs" to display performance logs.  Currently
+  only showing the time required to execute a WADO-RS query.  For example:
+  WADO-RS: elapsed: 26106623 us, rate: 14.86 files/s, 155.23Mbps
 
 
 Version 1.20 (2025-05-12)
--- a/Plugin/Configuration.cpp	Fri Jun 13 15:30:50 2025 +0200
+++ b/Plugin/Configuration.cpp	Tue Jul 22 11:14:44 2025 +0200
@@ -696,6 +696,11 @@
       return GetUnsignedIntegerValue("WadoRsLoaderThreadsCount", 0);
     }
 
+    bool IsPerformanceLogsEnabled()
+    {
+      return GetBooleanValue("EnablePerformanceLogs", false);
+    }
+
     MetadataMode GetMetadataMode(Orthanc::ResourceType level)
     {
       static const std::string FULL = "Full";
--- a/Plugin/Configuration.h	Fri Jun 13 15:30:50 2025 +0200
+++ b/Plugin/Configuration.h	Tue Jul 22 11:14:44 2025 +0200
@@ -146,5 +146,7 @@
     bool IsMetadataCacheEnabled();
 
     bool IsReadOnly();
+
+    bool IsPerformanceLogsEnabled();
   }
 }
--- a/Plugin/WadoRs.cpp	Fri Jun 13 15:30:50 2025 +0200
+++ b/Plugin/WadoRs.cpp	Tue Jul 22 11:14:44 2025 +0200
@@ -595,6 +595,10 @@
                                        bool transcode,
                                        Orthanc::DicomTransferSyntax targetSyntax /* only if transcoding */)
 {
+  Orthanc::Toolbox::ElapsedTimer perfTimer;
+  size_t perfTotalSizeInBytes = 0;
+  size_t perfTotalFilesCount = 0;
+
   if (level != Orthanc::ResourceType_Study &&
       level != Orthanc::ResourceType_Series &&
       level != Orthanc::ResourceType_Instance)
@@ -723,6 +727,8 @@
     loader->PrepareDicom(instances[i]["ID"].asString(), transcodeThisInstance);
   }
 
+  perfTotalFilesCount = instances.size();
+
   for (Json::Value::ArrayIndex i = 0; i < instances.size(); i++)
   {
     std::unique_ptr<OrthancPlugins::DicomInstance> dicom(loader->GetNextDicom());
@@ -735,12 +741,20 @@
       {
         throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
       }
+      perfTotalSizeInBytes += dicom->GetSize();
     }
     else
     {
       LOG(WARNING) << "Failed to load an instance";
     }
   }
+
+  if (OrthancPlugins::Configuration::IsPerformanceLogsEnabled())
+  {
+    uint64_t elapsedMicrosends = perfTimer.GetElapsedMicroseconds();
+    float filesPerSeconds = float(perfTotalFilesCount) / (float(elapsedMicrosends) / 1000000.0f);
+    LOG(INFO) << "WADO-RS: elapsed: " << perfTimer.GetElapsedMicroseconds() << " us, rate: " << std::fixed << std::setprecision(2) << filesPerSeconds << " files/s, " << Orthanc::Toolbox::GetHumanTransferSpeed(false, perfTotalSizeInBytes, elapsedMicrosends * 1000);
+  }
 }