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