# HG changeset patch # User Alain Mazy # Date 1726648722 -7200 # Node ID 89a13d8ec80b5ed1a67322543dfa58f0551c5d91 # Parent a3d283f61304df8dd53481c50155181deb2d9c17# Parent 7fadeb395359916d6133fb93cfbc5536ecefeae5 merged default -> find-refactoring diff -r a3d283f61304 -r 89a13d8ec80b NEWS --- a/NEWS Wed Sep 18 09:34:52 2024 +0200 +++ b/NEWS Wed Sep 18 10:38:42 2024 +0200 @@ -48,6 +48,9 @@ in very specific use-cases. * Fix extremely rare error when 2 threads are trying to create the same folder in the File Storage at the same time. +* Metrics: + - fix a few metrics that were not published + - added 2 metrics: orthanc_storage_cache_miss_count & orthanc_storage_cache_hit_count * Upgraded dependencies for static builds: - curl 8.9.0 * Added a new fallback when trying to decode a frame: transcode the file using the plugin diff -r a3d283f61304 -r 89a13d8ec80b OrthancFramework/Sources/FileStorage/StorageAccessor.cpp --- a/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Wed Sep 18 09:34:52 2024 +0200 +++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.cpp Wed Sep 18 10:38:42 2024 +0200 @@ -44,6 +44,8 @@ static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms"; static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes"; static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes"; +static const std::string METRICS_CACHE_HIT_COUNT = "orthanc_storage_cache_hit_count"; +static const std::string METRICS_CACHE_MISS_COUNT = "orthanc_storage_cache_miss_count"; namespace Orthanc @@ -208,10 +210,19 @@ if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType())) { + if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1); + } + ReadWholeInternal(content, info); // always store the uncompressed data in cache cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content); + } + else if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1); } } } @@ -284,10 +295,19 @@ if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType())) { + if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1); + } + ReadRawInternal(content, info); cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content); } + else if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1); + } } } @@ -353,24 +373,38 @@ StorageCache::Accessor accessorStartRange(*cache_); if (!accessorStartRange.FetchStartRange(target, info.GetUuid(), info.GetContentType(), end)) { - ReadStartRangeInternal(target, info, end); - accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target); - } - else - { + // the start range is not in cache, let's check if the whole file is StorageCache::Accessor accessorWhole(*cache_); if (!accessorWhole.Fetch(target, info.GetUuid(), info.GetContentType())) { - ReadWholeInternal(target, info); - accessorWhole.Add(info.GetUuid(), info.GetContentType(), target); - } + if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_MISS_COUNT, 1); + } - if (target.size() < end) + // if nothing is in the cache, let's read and cache only the start + ReadStartRangeInternal(target, info, end); + accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target); + } + else { - throw OrthancException(ErrorCode_CorruptedFile); + if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1); + } + + // we have read the whole file, check size and resize if needed + if (target.size() < end) + { + throw OrthancException(ErrorCode_CorruptedFile); + } + + target.resize(end); } - - target.resize(end); + } + else if (metrics_ != NULL) + { + metrics_->IncrementIntegerValue(METRICS_CACHE_HIT_COUNT, 1); } } } diff -r a3d283f61304 -r 89a13d8ec80b OrthancFramework/Sources/MetricsRegistry.cpp --- a/OrthancFramework/Sources/MetricsRegistry.cpp Wed Sep 18 09:34:52 2024 +0200 +++ b/OrthancFramework/Sources/MetricsRegistry.cpp Wed Sep 18 10:38:42 2024 +0200 @@ -139,6 +139,8 @@ void Increment(const T& delta) { + time_ = GetNow(); + if (hasValue_) { value_ += delta; @@ -146,6 +148,7 @@ else { value_ = delta; + hasValue_ = true; } }