AlgoTimeRegister.h 1.37 KB
Newer Older
1
2
3
4
5
6
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <mutex>
#include <thread>
#include <vector>

#include "MantidAPI/DllConfig.h"

class timespec;

namespace Mantid {
namespace Instrumentation {

/** AlgoTimeRegister : simple class to dump information about executed
 * algorithms
 */
class AlgoTimeRegister {
public:
  static AlgoTimeRegister globalAlgoTimeRegister;
  static timespec diff(timespec start, timespec end);
  struct Info {
    std::string m_name;
    std::thread::id m_threadId;
    timespec m_begin;
    timespec m_end;

    Info(const std::string &nm, const std::thread::id &id, const timespec &be,
         const timespec &en)
        : m_name(nm), m_threadId(id), m_begin(be), m_end(en) {}
  };

  class Dump {
    AlgoTimeRegister &m_algoTimeRegister;
    timespec m_regStart;
    const std::string m_name;

  public:
    Dump(AlgoTimeRegister &atr, const std::string &nm);
    ~Dump();
  };

  AlgoTimeRegister();
  ~AlgoTimeRegister();

private:
  std::mutex m_mutex;
  std::vector<Info> m_info;
  timespec m_hstart;
  std::chrono::high_resolution_clock::time_point m_start;
};

} // namespace Instrumentation
} // namespace Mantid