GEOS
TimingMacros.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 
17 
18 /* UNCRUSTIFY-OFF */
19 
26 #ifndef GEOS_COMMON_TIMINGMACROS_HPP_
27 #define GEOS_COMMON_TIMINGMACROS_HPP_
28 
29 #include "common/GeosxConfig.hpp"
30 #include "GeosxMacros.hpp"
31 
32 namespace timingHelpers
33 {
34  inline std::string stripPF( char const * prettyFunction )
35  {
36  std::string input(prettyFunction);
37  std::string::size_type const end = input.find_first_of( '(' );
38  std::string::size_type const beg = input.find_last_of( ' ', end)+1;
39  return input.substr( beg, end-beg );
40  }
41 }
42 
43 
44 #if defined( GEOS_USE_CUDA ) && defined( GEOS_USE_CUDA_NVTOOLSEXT )
45 
46 #include "nvToolsExt.h"
47 
48 namespace timingHelpers
49 {
50  enum NVTXColors {
51  GREEN = 0xff00ff00,
52  BLUE = 0xff0000ff,
53  YELLOW = 0xffffff00,
54  PURPLE = 0xffff00ff,
55  AQUA = 0xff00ffff,
56  RED = 0xffff0000,
57  WHITE = 0xffffffff
58  };
59 
60  class NVTXScopeTracer {
61  public:
62  NVTXScopeTracer( const char* name, NVTXColors color ) {
63  nvtxEventAttributes_t eventAttrib = { 0 };
64  eventAttrib.version = NVTX_VERSION;
65  eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
66  eventAttrib.colorType = NVTX_COLOR_ARGB;
67  eventAttrib.color = color;
68  eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
69  eventAttrib.message.ascii = name;
70  nvtxRangePushEx(&eventAttrib);
71  }
72  ~NVTXScopeTracer() {
73  nvtxRangePop();
74  }
75  };
76 
77 }
79 # define GEOS_NVTX_MARK_SCOPE_COLORED(name, color) timingHelpers::NVTXScopeTracer __FILE__ ## _ ## __LINE__ ## _ ## scopeTracer = timingHelpers::NVTXScopeTracer(name, color)
81 # define GEOS_NVTX_MARK_SCOPE(name) GEOS_NVTX_MARK_SCOPE_COLORED(STRINGIZE_NX(name), timingHelpers::PURPLE)
83 # define GEOS_NVTX_MARK_FUNCTION GEOS_NVTX_MARK_SCOPE_COLORED(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str(), timingHelpers::BLUE)
84 #else
86 # define GEOS_NVTX_MARK_SCOPE(name)
87 # define GEOS_NVTX_MARK_FUNCTION
89 #endif /* USE_CUDA */
90 
91 
92 #ifdef GEOS_USE_CALIPER
93 #include <caliper/cali.h>
94 #include <sys/time.h>
95 #include <string>
96 #include <iostream>
97 
99 #define GEOS_CALIPER_MARK_SCOPE(name) cali::Function __cali_ann##__LINE__(STRINGIZE_NX(name))
100 
102 #define GEOS_CALIPER_MARK_FUNCTION cali::Function __cali_ann##__func__(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str())
103 
105 #define GEOS_CALIPER_MARK_BEGIN(name) CALI_MARK_BEGIN(STRINGIZE(name))
106 
108 #define GEOS_CALIPER_MARK_END(name) CALI_MARK_END(STRINGIZE(name))
109 
111 #define GEOS_CALIPER_MARK_FUNCTION_BEGIN CALI_MARK_FUNCTION_BEGIN
112 
114 #define GEOS_CALIPER_MARK_FUNCTION_END CALI_MARK_FUNCTION_END
115 
116 #else // GEOS_USE_CALIPER
117 
119 #define GEOS_CALIPER_MARK_SCOPE(name)
120 #define GEOS_CALIPER_MARK_FUNCTION
121 
122 #define GEOS_CALIPER_MARK_BEGIN(name)
123 #define GEOS_CALIPER_MARK_END(name)
124 
125 #define GEOS_CALIPER_MARK_FUNCTION_BEGIN
126 #define GEOS_CALIPER_MARK_FUNCTION_END
128 
129 #endif // GEOS_USE_CALIPER
130 
132 #define GEOS_MARK_SCOPE(name) GEOS_CALIPER_MARK_SCOPE(name); GEOS_NVTX_MARK_SCOPE(name)
134 #define GEOS_MARK_FUNCTION GEOS_CALIPER_MARK_FUNCTION; GEOS_NVTX_MARK_FUNCTION
136 #define GEOS_MARK_FUNCTION_BEGIN(name) GEOS_CALIPER_MARK_FUNCTION_BEGIN(name)
138 #define GEOS_MARK_FUNCTION_END(name) GEOS_CALIPER_MARK_FUNCTION_END(name)
140 #define GEOS_MARK_BEGIN(name) GEOS_CALIPER_MARK_BEGIN(name)
142 #define GEOS_MARK_END(name) GEOS_CALIPER_MARK_END(name)
143 
145 #ifdef GEOS_USE_TIMERS
146 #define GEOS_GET_TIME( time ) \
147  real64 time; \
148  do \
149  { \
150  timeval tim; \
151  gettimeofday(&tim, nullptr); \
152  time = tim.tv_sec + (tim.tv_usec / 1000000.0); \
153  } while (false)
154 #else
155 #define GEOS_GET_TIME( time )
156 #endif
157 
158 #endif // GEOS_COMMON_TIMINGMACROS_HPP_
std::string string
String type.
Definition: DataTypes.hpp:91