1111
1212#include " CCDBHelpers.h"
1313#include " Framework/DeviceSpec.h"
14+ #include " Framework/DataProcessingStats.h"
1415#include " Framework/Logger.h"
1516#include " Framework/TimingInfo.h"
1617#include " Framework/ConfigParamRegistry.h"
@@ -28,14 +29,16 @@ O2_DECLARE_DYNAMIC_LOG(ccdb);
2829namespace o2 ::framework
2930{
3031
31- namespace {
32+ namespace
33+ {
3234struct CCDBFetcherHelper {
3335 struct CCDBCacheInfo {
3436 std::string etag;
3537 size_t cacheValidUntil = 0 ;
3638 size_t cachePopulatedAt = 0 ;
3739 size_t cacheMiss = 0 ;
3840 size_t cacheHit = 0 ;
41+ size_t size = 0 ;
3942 size_t minSize = -1ULL ;
4043 size_t maxSize = 0 ;
4144 int lastCheckedTF = 0 ;
@@ -50,6 +53,8 @@ struct CCDBFetcherHelper {
5053 std::string url;
5154 };
5255
56+ size_t totalFetchedBytes = 0 ;
57+ size_t totalRequestedBytes = 0 ;
5358 std::unordered_map<std::string, CCDBCacheInfo> mapURL2UUID;
5459 std::unordered_map<std::string, DataAllocator::CacheId> mapURL2DPLCache;
5560 std::string createdNotBefore = " 0" ;
@@ -80,7 +85,7 @@ struct CCDBFetcherHelper {
8085 return apis[entry == remappings.end () ? " " : entry->second ];
8186 }
8287};
83- }
88+ } // namespace
8489
8590bool isPrefix (std::string_view prefix, std::string_view full)
8691{
@@ -336,8 +341,11 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
336341 helper->mapURL2UUID [path].etag = headers[" ETag" ]; // update uuid
337342 helper->mapURL2UUID [path].cachePopulatedAt = timestampToUse;
338343 helper->mapURL2UUID [path].cacheMiss ++;
344+ helper->mapURL2UUID [path].size = v.size ();
339345 helper->mapURL2UUID [path].minSize = std::min (v.size (), helper->mapURL2UUID [path].minSize );
340346 helper->mapURL2UUID [path].maxSize = std::max (v.size (), helper->mapURL2UUID [path].maxSize );
347+ helper->totalFetchedBytes += v.size ();
348+ helper->totalRequestedBytes += v.size ();
341349 api.appendFlatHeader (v, headers);
342350 auto cacheId = allocator.adoptContainer (output, std::move (v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB );
343351 helper->mapURL2DPLCache [path] = cacheId;
@@ -350,8 +358,11 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
350358 helper->mapURL2UUID [path].cachePopulatedAt = timestampToUse;
351359 helper->mapURL2UUID [path].cacheValidUntil = headers[" Cache-Valid-Until" ].empty () ? 0 : std::stoul (headers[" Cache-Valid-Until" ]);
352360 helper->mapURL2UUID [path].cacheMiss ++;
361+ helper->mapURL2UUID [path].size = v.size ();
353362 helper->mapURL2UUID [path].minSize = std::min (v.size (), helper->mapURL2UUID [path].minSize );
354363 helper->mapURL2UUID [path].maxSize = std::max (v.size (), helper->mapURL2UUID [path].maxSize );
364+ helper->totalFetchedBytes += v.size ();
365+ helper->totalRequestedBytes += v.size ();
355366 api.appendFlatHeader (v, headers);
356367 auto cacheId = allocator.adoptContainer (output, std::move (v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB );
357368 helper->mapURL2DPLCache [path] = cacheId;
@@ -368,6 +379,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
368379 auto cacheId = helper->mapURL2DPLCache [path];
369380 O2_SIGNPOST_EVENT_EMIT (ccdb, sid, " populateCacheWith" , " Reusing %{public}s for %{public}s (DPL id %" PRIu64 " )" , path.data (), headers[" ETag" ].data (), cacheId.value );
370381 helper->mapURL2UUID [path].cacheHit ++;
382+ helper->totalRequestedBytes += helper->mapURL2UUID [path].size ;
371383 allocator.adoptFromCache (output, cacheId, header::gSerializationMethodCCDB );
372384 // the outputBuffer was not used, can we destroy it?
373385 }
@@ -382,13 +394,13 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
382394 // / Add a callback on stop which dumps the statistics for the caching per
383395 // / path
384396 callbacks.set <CallbackService::Id::Stop>([helper]() {
385- LOGP (info, " CCDB cache miss/hit ratio: " );
397+ LOGP (info, " CCDB cache miss/hit ratio ({} fetched / {} requested bytes): " , helper-> totalFetchedBytes , helper-> totalRequestedBytes );
386398 for (auto & entry : helper->mapURL2UUID ) {
387399 LOGP (info, " {}: {}/{} ({}-{} bytes)" , entry.first , entry.second .cacheMiss , entry.second .cacheHit , entry.second .minSize , entry.second .maxSize );
388400 }
389401 });
390402
391- return adaptStateless ([helper](DataTakingContext& dtc, DataAllocator& allocator, TimingInfo& timingInfo) {
403+ return adaptStateless ([helper](DataTakingContext& dtc, DataAllocator& allocator, TimingInfo& timingInfo, DataProcessingStats& stats ) {
392404 auto sid = _o2_signpost_id_t {(int64_t )timingInfo.timeslice };
393405 O2_SIGNPOST_START (ccdb, sid, " fetchFromCCDB" , " Fetching CCDB objects for timeslice %" PRIu64, (uint64_t )timingInfo.timeslice );
394406 static Long64_t orbitResetTime = -1 ;
@@ -429,8 +441,11 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
429441 if (etag.empty ()) {
430442 helper->mapURL2UUID [path].etag = headers[" ETag" ]; // update uuid
431443 helper->mapURL2UUID [path].cacheMiss ++;
444+ helper->mapURL2UUID [path].size = v.size ();
432445 helper->mapURL2UUID [path].minSize = std::min (v.size (), helper->mapURL2UUID [path].minSize );
433446 helper->mapURL2UUID [path].maxSize = std::max (v.size (), helper->mapURL2UUID [path].maxSize );
447+ helper->totalFetchedBytes += v.size ();
448+ helper->totalRequestedBytes += v.size ();
434449 newOrbitResetTime = getOrbitResetTime (v);
435450 api.appendFlatHeader (v, headers);
436451 auto cacheId = allocator.adoptContainer (output, std::move (v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone );
@@ -440,8 +455,11 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
440455 // somewhere here pruneFromCache should be called
441456 helper->mapURL2UUID [path].etag = headers[" ETag" ]; // update uuid
442457 helper->mapURL2UUID [path].cacheMiss ++;
458+ helper->mapURL2UUID [path].size = v.size ();
443459 helper->mapURL2UUID [path].minSize = std::min (v.size (), helper->mapURL2UUID [path].minSize );
444460 helper->mapURL2UUID [path].maxSize = std::max (v.size (), helper->mapURL2UUID [path].maxSize );
461+ helper->totalFetchedBytes += v.size ();
462+ helper->totalRequestedBytes += v.size ();
445463 newOrbitResetTime = getOrbitResetTime (v);
446464 api.appendFlatHeader (v, headers);
447465 auto cacheId = allocator.adoptContainer (output, std::move (v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone );
@@ -455,6 +473,7 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
455473 auto cacheId = helper->mapURL2DPLCache [path];
456474 O2_SIGNPOST_EVENT_EMIT (ccdb, sid, " fetchFromCCDB" , " Reusing %{public}s for %{public}s (DPL id %" PRIu64 " )" , path.data (), headers[" ETag" ].data (), cacheId.value );
457475 helper->mapURL2UUID [path].cacheHit ++;
476+ helper->totalRequestedBytes += helper->mapURL2UUID [path].size ;
458477 allocator.adoptFromCache (output, cacheId, header::gSerializationMethodNone );
459478
460479 if (newOrbitResetTime != orbitResetTime) {
@@ -480,6 +499,8 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
480499 dtc.runNumber .data (), orbitResetTime, timingInfo.creation , timestamp, timingInfo.firstTForbit );
481500
482501 populateCacheWith (helper, timestamp, timingInfo, dtc, allocator);
502+ stats.updateStats ({(int )ProcessingStatsId::CCDB_CACHE_FETCHED_BYTES, DataProcessingStats::Op::Set, (int64_t )helper->totalFetchedBytes });
503+ stats.updateStats ({(int )ProcessingStatsId::CCDB_CACHE_REQUESTED_BYTES, DataProcessingStats::Op::Set, (int64_t )helper->totalRequestedBytes });
483504 O2_SIGNPOST_END (ccdb, _o2_signpost_id_t {(int64_t )timingInfo.timeslice }, " fetchFromCCDB" , " Fetching CCDB objects" );
484505 }); });
485506}
0 commit comments