SST  12.0.1
StructuralSimulationToolkit
profile.h
1 // Copyright 2009-2022 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-2022, 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 {
20 namespace Core {
21 namespace Profile {
22 
23 #ifdef __SST_ENABLE_PROFILE__
24 
25 #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
26 #define CLOCK std::chrono::system_clock
27 #else
28 #define CLOCK std::chrono::steady_clock
29 #endif
30 
31 typedef CLOCK::time_point ProfData_t;
32 
33 inline ProfData_t
34 now()
35 {
36  return CLOCK::now();
37 }
38 
39 inline double
40 getElapsed(const ProfData_t& begin, const ProfData_t& end)
41 {
42  std::chrono::duration<double> elapsed = (end - begin);
43  return elapsed.count();
44 }
45 
46 inline double
47 getElapsed(const ProfData_t& since)
48 {
49  return getElapsed(since, now());
50 }
51 
52 #else
53 typedef double ProfData_t;
54 
55 inline ProfData_t
56 now()
57 {
58  return 0.0;
59 }
60 
61 inline double
62 getElapsed(const ProfData_t& UNUSED(begin), const ProfData_t& UNUSED(end))
63 {
64  return 0.0;
65 }
66 
67 inline double
68 getElapsed(const ProfData_t& UNUSED(since))
69 {
70  return 0.0;
71 }
72 
73 #endif
74 
75 } // namespace Profile
76 } // namespace Core
77 } // namespace SST
78 
79 #endif // SST_CORE_CORE_PROFILE_H