SST 15.0
Structural Simulation Toolkit
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
19namespace 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
29using ProfData_t = CLOCK::time_point;
30
31inline ProfData_t
32now()
33{
34 return CLOCK::now();
35}
36
37inline double
38getElapsed(const ProfData_t& begin, const ProfData_t& end)
39{
40 std::chrono::duration<double> elapsed = (end - begin);
41 return elapsed.count();
42}
43
44inline double
45getElapsed(const ProfData_t& since)
46{
47 return getElapsed(since, now());
48}
49
50#else
51using ProfData_t = double;
52
53inline ProfData_t
54now()
55{
56 return 0.0;
57}
58
59inline double
60getElapsed(const ProfData_t& UNUSED(begin), const ProfData_t& UNUSED(end))
61{
62 return 0.0;
63}
64
65inline double
66getElapsed(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