diff --git a/include/podio/BenchmarkRecorder.h b/include/podio/BenchmarkRecorder.h deleted file mode 100644 index c6e3f8a04..000000000 --- a/include/podio/BenchmarkRecorder.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef PODIO_BENCHMARKRECORDER_H -#define PODIO_BENCHMARKRECORDER_H - -#include "podio/BenchmarkUtil.h" - -#include "TFile.h" -#include "TTree.h" - -#include -#include -#include -#include -#include -#include - -namespace podio::benchmark { - -class BenchmarkRecorderTree { -public: - BenchmarkRecorderTree() = delete; - // Avoid some possible issues that could arise from copying by simply - // disallowing it - BenchmarkRecorderTree(const BenchmarkRecorderTree&) = delete; - BenchmarkRecorderTree& operator=(const BenchmarkRecorderTree&) = delete; - - BenchmarkRecorderTree(TFile* recFile, const std::string& name, const std::vector& steps) : - m_stepNames(steps), m_stepTimes(steps.size()) { - recFile->cd(); - m_recordTree = new TTree(name.c_str(), "time recording tree"); - m_recordTree->SetDirectory(recFile); - - for (size_t i = 0; i < m_stepNames.size(); ++i) { - m_recordTree->Branch(m_stepNames[i].c_str(), &m_stepTimes[i]); - } - } - - template - void recordTime(const std::string& stepName, const ClockT::duration time) { - const auto it = std::find(m_stepNames.cbegin(), m_stepNames.cend(), stepName); - const auto index = std::distance(m_stepNames.cbegin(), it); - m_stepTimes[index] = std::chrono::duration_cast(time).count(); - } - - void Fill() { - m_recordTree->Fill(); - } - - void Write() { - m_recordTree->Write(); - } - -private: - TTree* m_recordTree{nullptr}; - std::vector m_stepNames; - std::vector m_stepTimes; -}; - -class BenchmarkRecorder { -public: - BenchmarkRecorder() = delete; - BenchmarkRecorder(const std::string& recFileName = "podio_benchmark_file.root") { - m_recordFile = new TFile(recFileName.c_str(), "recreate"); - } - - BenchmarkRecorder(const BenchmarkRecorder&) = delete; - BenchmarkRecorder operator=(const BenchmarkRecorder&) = delete; - - ~BenchmarkRecorder() { - for (auto& tree : m_recordTrees) { - tree.second.Write(); - } - m_recordFile->Write("", TObject::kWriteDelete); - m_recordFile->Close(); - } - - template - void recordTime(const std::string& treeName, const std::string& stepName, const ClockT::duration time) { - auto it = std::find_if(m_recordTrees.begin(), m_recordTrees.end(), - [&treeName](const auto& recTree) { return recTree.first == treeName; }); - - it->second.template recordTime(stepName, time); - } - - void Fill(const std::string& treeName) { - auto it = std::find_if(m_recordTrees.begin(), m_recordTrees.end(), - [&treeName](const auto& recTree) { return recTree.first == treeName; }); - it->second.Fill(); - } - - BenchmarkRecorderTree& addTree(const std::string& name, const std::vector& steps) { - return m_recordTrees - .emplace_back(std::piecewise_construct, std::forward_as_tuple(name), - std::forward_as_tuple(m_recordFile, name, steps)) - .second; - } - -private: - TFile* m_recordFile{nullptr}; - // Stable references outside!! - std::deque> m_recordTrees{}; -}; - -} // namespace podio::benchmark - -#endif diff --git a/include/podio/BenchmarkUtil.h b/include/podio/BenchmarkUtil.h deleted file mode 100644 index 558bc7077..000000000 --- a/include/podio/BenchmarkUtil.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef PODIO_BENCHMARKUTIL_H -#define PODIO_BENCHMARKUTIL_H - -#include -#include -#include - -namespace podio::benchmark { -using ClockT = std::chrono::high_resolution_clock; - -/** - * Run a member function and record the duration. Return the result and the - * duration in a pair. - */ -template -inline std::pair, ClockT::duration> -run_member_timed(Obj& obj, MemberFunc func, Args&&... args) { - const auto start = ClockT::now(); - const auto retval = std::invoke(func, obj, std::forward(args)...); - const auto end = ClockT::now(); - - return std::make_pair(retval, end - start); -} - -/** - * Run a member function without return value and record the duration. Return - * the duration and only use the side-effects of the member function. Can't get - * this to work in the above version with a void return value, so that is why we - * have a dedicated function for void functions here. - */ -template -inline ClockT::duration run_void_member_timed(Obj& obj, MemberFunc func, Args&&... args) { - const auto start = ClockT::now(); - std::invoke(func, obj, std::forward(args)...); - const auto end = ClockT::now(); - - return end - start; -} - -} // namespace podio::benchmark - -#endif