Mantid
Loading...
Searching...
No Matches
AlgoTimeRegister.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <fstream>
10#include <time.h>
11
12namespace Mantid {
13namespace Instrumentation {
14
16
18 : m_algoTimeRegister(atr), m_regStart_chrono(std::chrono::high_resolution_clock::now()), m_name(nm) {}
19
21 const time_point_ns regFinish = std::chrono::high_resolution_clock::now();
22 {
23 std::lock_guard<std::mutex> lock(m_algoTimeRegister.m_mutex);
24 m_algoTimeRegister.addTime(m_name, std::this_thread::get_id(), m_regStart_chrono, regFinish);
25 }
26}
27
28void AlgoTimeRegister::addTime(const std::string &name, const std::thread::id thread_id,
29 const Kernel::time_point_ns &begin, const Kernel::time_point_ns &end) {
30 m_info.emplace_back(name, thread_id, begin, end);
31}
32
33void AlgoTimeRegister::addTime(const std::string &name, const Kernel::time_point_ns &begin,
34 const Kernel::time_point_ns &end) {
35 this->addTime(name, std::this_thread::get_id(), begin, end);
36}
37
38AlgoTimeRegister::AlgoTimeRegister() : m_start(std::chrono::high_resolution_clock::now()) {}
39
41 std::fstream fs;
42 fs.open("./algotimeregister.out", std::ios::out);
43 // c++20 has an implementation of operator<<
44 fs << "START_POINT: " << std::chrono::duration_cast<std::chrono::nanoseconds>(m_start.time_since_epoch()).count()
45 << " MAX_THREAD: " << PARALLEL_GET_MAX_THREADS << "\n";
46 for (auto &elem : m_info) {
47 const std::chrono::nanoseconds st = elem.m_begin - m_start;
48 const std::chrono::nanoseconds fi = elem.m_end - m_start;
49 fs << "ThreadID=" << elem.m_threadId << ", AlgorithmName=" << elem.m_name << ", StartTime=" << st.count()
50 << ", EndTime=" << fi.count() << "\n";
51 }
52}
53
54} // namespace Instrumentation
55} // namespace Mantid
#define PARALLEL_GET_MAX_THREADS
Dump(AlgoTimeRegister &atr, const std::string &nm)
AlgoTimeRegister : simple class to dump information about executed algorithms.
void addTime(const std::string &name, const std::thread::id thread_id, const Kernel::time_point_ns &begin, const Kernel::time_point_ns &end)
std::chrono::time_point< std::chrono::high_resolution_clock > time_point_ns
Definition: Algorithm.h:45
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.