SST  15.1.0
StructuralSimulationToolkit
profile.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_CORE_PROFILE_H
13 #define SST_CORE_CORE_PROFILE_H
14 
15 #include "sst/core/warnmacros.h"
16 
17 #include <chrono>
18 
19 namespace SST::Core::Profile {
20 
21 #ifdef __SST_ENABLE_PROFILE__
22 
23 #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
24 #define CLOCK std::chrono::system_clock
25 #else
26 #define CLOCK std::chrono::steady_clock
27 #endif
28 
29 using ProfData_t = CLOCK::time_point;
30 
31 inline ProfData_t
32 now()
33 {
34  return CLOCK::now();
35 }
36 
37 inline double
38 getElapsed(const ProfData_t& begin, const ProfData_t& end)
39 {
40  std::chrono::duration<double> elapsed = (end - begin);
41  return elapsed.count();
42 }
43 
44 inline double
45 getElapsed(const ProfData_t& since)
46 {
47  return getElapsed(since, now());
48 }
49 
50 #else
51 using ProfData_t = double;
52 
53 inline ProfData_t
54 now()
55 {
56  return 0.0;
57 }
58 
59 inline double
60 getElapsed(const ProfData_t& UNUSED(begin), const ProfData_t& UNUSED(end))
61 {
62  return 0.0;
63 }
64 
65 inline double
66 getElapsed(const ProfData_t& UNUSED(since))
67 {
68  return 0.0;
69 }
70 
71 #endif
72 
73 } // namespace SST::Core::Profile
74 
75 #endif // SST_CORE_CORE_PROFILE_H
Definition: profile.h:19