From cb1efb317b25a938f3dd9d69405ed99511b6bee3 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Tue, 11 Jul 2023 23:16:15 +0200
Subject: [PATCH] cbmreco: Monitor unpack time.

---
 algo/global/Reco.cxx   | 5 +++--
 algo/unpack/Unpack.cxx | 9 +++++++--
 algo/unpack/Unpack.h   | 1 +
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx
index 7a25dcad36..3dad3a6a01 100644
--- a/algo/global/Reco.cxx
+++ b/algo/global/Reco.cxx
@@ -166,8 +166,8 @@ void Reco::QueueUnpackerMetrics(const fles::Timeslice& ts, const UnpackMonitorDa
 {
   if (!HasMonitor()) return;
 
-  auto sizeBytes = [](const auto& d) { return d.size() * sizeof(d[0]); };
-  auto expansionFactor = [](size_t x, const auto& d) {
+  auto sizeBytes       = [](const auto& d) { return d.size() * sizeof(d[0]); };
+  auto expansionFactor = [&](size_t x, const auto& d) {
     return d.size() > 0 ? static_cast<double>(sizeBytes(d)) / x : 0.0;
   };
 
@@ -186,6 +186,7 @@ void Reco::QueueUnpackerMetrics(const fles::Timeslice& ts, const UnpackMonitorDa
 
   GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}},
                            {
+                             {"unpackTimeTotal", monitor.fTimeUnpack},
                              {"unpackBytesInSts", monitor.fNumBytesInSts},
                              {"unpackBytesInMuch", monitor.fNumBytesInMuch},
                              {"unpackBytesInTof", monitor.fNumBytesInTof},
diff --git a/algo/unpack/Unpack.cxx b/algo/unpack/Unpack.cxx
index 9a44ddffd7..f1cca939e7 100644
--- a/algo/unpack/Unpack.cxx
+++ b/algo/unpack/Unpack.cxx
@@ -20,7 +20,7 @@ namespace cbm::algo
   // -----   Execution   -------------------------------------------------------
   Unpack::resultType Unpack::operator()(const fles::Timeslice* timeslice)
   {
-    xpu::scoped_timer t0("Unpack");
+    xpu::push_timer("Unpack");
 
     // --- Output data
     resultType result          = {};
@@ -94,7 +94,7 @@ namespace cbm::algo
 
     // --- Sorting of output digis. Is required by both digi trigger and event builder.
 
-    xpu::scoped_timer t2("Sort");
+    xpu::push_timer("Sort");
     auto& digiData = digiTs.fData;
     DoSort(digiData.fSts.fDigis);
     DoSort(digiData.fMuch.fDigis);
@@ -103,6 +103,11 @@ namespace cbm::algo
     DoSort(digiData.fTrd.fDigis);
     DoSort(digiData.fTrd2d.fDigis);
     DoSort(digiData.fRich.fDigis);
+    xpu::pop_timer();
+
+    xpu::timings timings = xpu::pop_timer();
+
+    monitor.fTimeUnpack = timings.wall();
 
     return result;
   }
diff --git a/algo/unpack/Unpack.h b/algo/unpack/Unpack.h
index 676af4fcb4..13329f07a3 100644
--- a/algo/unpack/Unpack.h
+++ b/algo/unpack/Unpack.h
@@ -59,6 +59,7 @@ namespace cbm::algo
     size_t fNumCompUsed = 0;
     size_t fNumErrInvalidEqId   = 0;
     size_t fNumErrInvalidSysVer = 0;
+    double fTimeUnpack          = 0;
     std::string print() const
     {
       std::stringstream ss;
-- 
GitLab