Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExaTrkXTiming.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExaTrkXTiming.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
12 
13 #include <chrono>
14 #include <fstream>
15 #include <numeric>
16 #include <string>
17 #include <vector>
18 
19 namespace Acts {
20 
24 struct ExaTrkXTime {
25  float embedding = 0.0;
26  float building = 0.0;
27  float filtering = 0.0;
28  float gnn = 0.0;
29  float labeling = 0.0;
30  float total = 0.0;
31 
32  void summary(const Logger& logger) const {
33  ACTS_VERBOSE("1) embedding: " << embedding);
34  ACTS_VERBOSE("2) building: " << building);
35  ACTS_VERBOSE("3) filtering: " << filtering);
36  ACTS_VERBOSE("4) gnn: " << gnn);
37  ACTS_VERBOSE("5) labeling: " << labeling);
38  ACTS_VERBOSE("6) total: " << total);
39  }
40 };
41 
45 class ExaTrkXTimer {
46  public:
47  ExaTrkXTimer(bool disabled = false) : m_disabled(disabled) {}
48 
49  void start() {
50  if (not m_disabled) {
51  m_start = std::chrono::high_resolution_clock::now();
52  m_running = true;
53  }
54  }
55  void stop() {
56  if (not m_disabled) {
57  m_end = std::chrono::high_resolution_clock::now();
58  m_running = false;
59  }
60  }
62  stop();
63  return elapsedSeconds();
64  }
65  double elapsed() {
66  if (not m_disabled) {
67  std::chrono::time_point<std::chrono::high_resolution_clock> end;
68  if (m_running) {
69  end = std::chrono::high_resolution_clock::now();
70  } else {
71  end = m_end;
72  }
73  return std::chrono::duration<double, std::milli>(end - m_start).count();
74  } else {
75  return 0.0;
76  }
77  }
78  double elapsedSeconds() { return elapsed() / 1000.0; }
79 
80  private:
81  std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
82  std::chrono::time_point<std::chrono::high_resolution_clock> m_end;
83  bool m_running = false;
84  bool m_disabled;
85 };
86 
87 } // namespace Acts