diff --git a/reco/steer/CbmRecoUnpack.cxx b/reco/steer/CbmRecoUnpack.cxx index a3518735e80bca898a397fd9d3e53adac82d55ce..93c399e8dd2be1deeecfead37a601fc690243843 100644 --- a/reco/steer/CbmRecoUnpack.cxx +++ b/reco/steer/CbmRecoUnpack.cxx @@ -19,6 +19,7 @@ #include <RtypesCore.h> #include <TH1.h> +#include <TStopwatch.h> #include <cstddef> #include <cstdint> @@ -161,6 +162,23 @@ Bool_t CbmRecoUnpack::Init() initPerformanceMaps(fkFlesBmon, "Bmon"); } + if (fDoPerfProfPerTs) { + /// Timer for complete processing and histograming perTS + fTimerTs = new TStopwatch(); + + fhCpuTimePerTs = new TH1D("hCpuTimePerTs", "CPU Processing time of TS vs TS; Ts; CPU time [ms]", 6000, 0, 6000); + fhRealTimePerTs = new TH1D("hRealTimePerTs", "Real Processing time of TS vs TS; Ts; Real time [ms]", 6000, 0, 6000); + + fhCpuTimePerTsHist = + new TH1D("hCpuTimePerTsHist", "CPU Histo filling time of TS vs TS; Ts; CPU time [ms]", 6000, 0, 6000); + fhRealTimePerTsHist = + new TH1D("hRealTimePerTsHist", "Real Histo filling time of TS vs TS; Ts; Real time [ms]", 6000, 0, 6000); + + fhUnpackingRatioPerTs = + new TH1D("hUnpackingRatioPerTs", "ratio of tot. unp. digi size to tot. input raw size vs TS; TS; Size Ratio []", + 6000, 0, 6000); + } + return kTRUE; } // ---------------------------------------------------------------------------- @@ -174,6 +192,27 @@ void CbmRecoUnpack::initPerformanceMaps(std::uint16_t subsysid, std::string name fTimeMap.emplace(std::make_pair(subsysid, std::make_pair(0, 0))); fDataSizeMap.emplace(std::make_pair(subsysid, std::make_pair(0, 0))); } + if (fDoPerfProfPerTs) { + fNameMapPerTs.emplace(std::make_pair(subsysid, std::make_pair(name, 0))); + fTimeMapPerTs.emplace(std::make_pair(subsysid, std::make_pair(0, 0))); + fDataSizeMapPerTs.emplace(std::make_pair(subsysid, std::make_pair(0, 0))); + + fvhInpRatioPerTs.emplace(std::make_pair( + subsysid, + new TH1D(Form("hInpRatioPerTs%s", name.c_str()), + Form("ratio of input data size in total input data size vs TS for %s; TS; Size Ratio []", name.c_str()), + 6000, 0, 6000))); + fvhOutRatioPerTs.emplace(std::make_pair( + subsysid, + new TH1D(Form("hOutRatioPerTs%s", name.c_str()), + Form("ratio of unpacked digi size in total output size vs TS for %s; TS; Size Ratio []", name.c_str()), + 6000, 0, 6000))); + fvhUnpRatioPerTs.emplace(std::make_pair( + subsysid, + new TH1D(Form("hUnpRatioPerTs%s", name.c_str()), + Form("ratio of unpacked digi size to raw data size vs TS for %s; TS; O/I Size Ratio []", name.c_str()), + 6000, 0, 6000))); + } } // ---------------------------------------------------------------------------- @@ -250,6 +289,19 @@ void CbmRecoUnpack::performanceProfiling() hSpeedPerf->Write(); hDataPerf->Write(); + if (fDoPerfProfPerTs) { + fhCpuTimePerTs->Write(); + fhRealTimePerTs->Write(); + fhCpuTimePerTsHist->Write(); + fhRealTimePerTsHist->Write(); + for (auto detHist : fvhInpRatioPerTs) { + fvhInpRatioPerTs[detHist.first]->Write(); + fvhOutRatioPerTs[detHist.first]->Write(); + fvhUnpRatioPerTs[detHist.first]->Write(); + } + fhUnpackingRatioPerTs->Write(); + } + /// Restore old global file and folder pointer to avoid messing with FairRoot gFile = oldFile; gDirectory = oldDir; @@ -257,6 +309,52 @@ void CbmRecoUnpack::performanceProfiling() // histofile->Close(); histofile.Close(); } +void CbmRecoUnpack::performanceProfilingPerTs() +{ + /// Speed performance + double dTotalCpuTime = fTimerTs->CpuTime() * 1000.; + double dTotalRealTime = fTimerTs->RealTime() * 1000.; + fTimerTs->Start(); + + /* + for (auto timeit : fTimeMapPerTs) { + // Speed performance + dTotalCpuTime += timeit->second.first + dTotalRealTime += timeit->second.second + } + */ + + double dTotalDataSizeIn = 0.0; + double dTotalDataSizeOut = 0.0; + + /// Data performance + for (auto datait : fDataSizeMapPerTs) { + dTotalDataSizeIn += datait.second.first; + dTotalDataSizeOut += datait.second.second; + } + for (auto datait : fDataSizeMapPerTs) { + fvhInpRatioPerTs[datait.first]->Fill(fCbmTsEventHeader->GetTsIndex(), datait.second.first / dTotalDataSizeIn); + fvhOutRatioPerTs[datait.first]->Fill(fCbmTsEventHeader->GetTsIndex(), datait.second.second / dTotalDataSizeOut); + fvhUnpRatioPerTs[datait.first]->Fill(fCbmTsEventHeader->GetTsIndex(), datait.second.second / datait.second.first); + } + fhUnpackingRatioPerTs->Fill(fCbmTsEventHeader->GetTsIndex(), dTotalDataSizeOut / dTotalDataSizeIn); + fhCpuTimePerTs->Fill(fCbmTsEventHeader->GetTsIndex(), dTotalCpuTime); + fhRealTimePerTs->Fill(fCbmTsEventHeader->GetTsIndex(), dTotalRealTime); + + for (auto timeit = fTimeMapPerTs.begin(); timeit != fTimeMapPerTs.end(); ++timeit) { + // Speed performance + timeit->second.first = 0.0; + timeit->second.second = 0.0; + } + for (auto datait = fDataSizeMapPerTs.begin(); datait != fDataSizeMapPerTs.end(); ++datait) { + datait->second.first = 0.0; + datait->second.second = 0.0; + } + + fTimerTs->Stop(); + fhCpuTimePerTsHist->Fill(fCbmTsEventHeader->GetTsIndex(), fTimerTs->CpuTime() * 1000.); + fhRealTimePerTsHist->Fill(fCbmTsEventHeader->GetTsIndex(), fTimerTs->RealTime() * 1000.); +} // ---------------------------------------------------------------------------- // ----- Reset ------------------------------------------------------------ @@ -290,6 +388,11 @@ void CbmRecoUnpack::Reset() // ----- Unpacking -------------------------------------------------------- void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts) { + if (fDoPerfProfPerTs) { + /// Start time for complete processing perTS + fTimerTs->Start(); + } + // Prepare timeslice const fles::Timeslice& timeslice = *ts; @@ -394,6 +497,11 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts) if (fTrd2DConfig && fTrd2DConfig->GetOptOutAVec()) { timesort(fTrd2DConfig->GetOptOutAVec()); } if (fBmonConfig && fBmonConfig->GetOptOutAVec()) { timesort(fBmonConfig->GetOptOutAVec()); } } + + if (fDoPerfProfPerTs) { + fTimerTs->Stop(); + performanceProfilingPerTs(); + } } // ---------------------------------------------------------------------------- diff --git a/reco/steer/CbmRecoUnpack.h b/reco/steer/CbmRecoUnpack.h index e99c295939ceaf8c61dd40bd6123f820673d1507..d0af724581561d7c34f3de03c2c165529b35b9cd 100644 --- a/reco/steer/CbmRecoUnpack.h +++ b/reco/steer/CbmRecoUnpack.h @@ -41,6 +41,8 @@ #include <utility> #include <vector> +class TH1; +class TStopwatch; /** @class CbmRecoUnpack ** @brief Main steering class for unpacking in cbmroot @@ -90,6 +92,17 @@ public: */ void SetDoPerfProfiling(bool value = true) { fDoPerfProf = value; } + /** + * @brief (De)Activate the performance profiling based on histograms for each TS + * + * @param value + */ + void SetDoPerfProfilingPerTs(bool value = true) + { + if (value) fDoPerfProf = value; + fDoPerfProfPerTs = value; + } + /** * @brief Set the performance profiling Output Filename * @@ -158,6 +171,9 @@ private: /** @brief Flag if performance profiling should be activated or not.*/ bool fDoPerfProf = false; //! + /** @brief Flag if performance profiling per TS should be activated or not.*/ + bool fDoPerfProfPerTs = false; //! + /** @brief Map to store a name for the unpackers and the processed amount of digis, key = fkFlesId*/ std::map<std::uint16_t, std::pair<std::string, size_t>> fNameMap = {}; //! @@ -167,9 +183,31 @@ private: /** @brief Map to store the in and out data amount, key = fkFlesId*/ std::map<std::uint16_t, std::pair<double, double>> fDataSizeMap = {}; //! + /** @brief Map to store a name for the unpackers and the processed amount of digis for a single TS, key = fkFlesId*/ + std::map<std::uint16_t, std::pair<std::string, size_t>> fNameMapPerTs = {}; //! + + /** @brief Map to store the cpu and wall time for a single TS, key = fkFlesId*/ + std::map<std::uint16_t, std::pair<double, double>> fTimeMapPerTs = {}; //! + + /** @brief Map to store the in and out data amount for a single TS, key = fkFlesId*/ + std::map<std::uint16_t, std::pair<double, double>> fDataSizeMapPerTs = {}; //! + + TStopwatch* fTimerTs = nullptr; + TH1* fhCpuTimePerTs = nullptr; /// Processing time per TS + TH1* fhRealTimePerTs = nullptr; /// Processing time per TS + TH1* fhCpuTimePerTsHist = nullptr; /// Plotting time per TS + TH1* fhRealTimePerTsHist = nullptr; /// Plotting time per TS + std::map<std::uint16_t, TH1*> fvhInpRatioPerTs = {}; /// ratio of system data in total input size vs TS in run + std::map<std::uint16_t, TH1*> fvhOutRatioPerTs = {}; /// ratio of system digi size in total output size vs TS in run + std::map<std::uint16_t, TH1*> fvhUnpRatioPerTs = {}; /// ratio of selected digi vs TS in run + TH1* fhUnpackingRatioPerTs = nullptr; /// ratio of total unpacked size to input size vs TS in run + /** @brief Run the performance profiling based on the fTimeMap and fDataSizeMap members. */ void performanceProfiling(); + /** @brief Run the performance profiling for a single TS based on the fTimeMapPerTs and fDataSizeMapPerTs members. */ + void performanceProfilingPerTs(); + /** * @brief Init the performance profiling maps for a given unpacker * @@ -349,6 +387,18 @@ private: fNameMap.find(subsysid)->second.second += nDigis; } + if (fDoPerfProfPerTs) { + auto timeit = fTimeMapPerTs.find(subsysid); + timeit->second.first += cputime; + timeit->second.second += walltime; + + auto datait = fDataSizeMapPerTs.find(subsysid); + datait->second.first += ts->size_component(icomp) / 1.0e6; + datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6; + + fNameMapPerTs.find(subsysid)->second.second += nDigis; + } + return nDigis; } // ----------------------------------------------------------------------------