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 "nvtx3/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_SCOPE_STR(name) GEOS_NVTX_MARK_SCOPE_COLORED(name, timingHelpers::PURPLE)
85 # define GEOS_NVTX_MARK_FUNCTION GEOS_NVTX_MARK_SCOPE_COLORED(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str(), timingHelpers::BLUE)
86 #else
88 # define GEOS_NVTX_MARK_SCOPE(name)
89 # define GEOS_NVTX_MARK_SCOPE_STR(name)
90 # define GEOS_NVTX_MARK_FUNCTION
92 #endif /* USE_CUDA */
93 
94 
95 #ifdef GEOS_USE_CALIPER
96 #include <caliper/cali.h>
97 #include <sys/time.h>
98 #include <string>
99 #include <iostream>
100 
102 #define GEOS_CALIPER_MARK_SCOPE(name) cali::Function GEOS_CONCAT(_cali_ann, __LINE__)(STRINGIZE_NX(name))
103 
105 #define GEOS_CALIPER_MARK_SCOPE_STR(name) cali::Function GEOS_CONCAT(_cali_ann, __LINE__)(name)
106 
108 #define GEOS_CALIPER_MARK_FUNCTION cali::Function _cali_ann_func(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str())
109 
111 #define GEOS_CALIPER_MARK_BEGIN(name) CALI_MARK_BEGIN(STRINGIZE(name))
112 
114 #define GEOS_CALIPER_MARK_END(name) CALI_MARK_END(STRINGIZE(name))
115 
117 #define GEOS_CALIPER_MARK_FUNCTION_BEGIN CALI_MARK_FUNCTION_BEGIN
118 
120 #define GEOS_CALIPER_MARK_FUNCTION_END CALI_MARK_FUNCTION_END
121 
122 #else // GEOS_USE_CALIPER
123 
125 #define GEOS_CALIPER_MARK_SCOPE(name)
126 #define GEOS_CALIPER_MARK_SCOPE_STR(name)
127 #define GEOS_CALIPER_MARK_FUNCTION
128 
129 #define GEOS_CALIPER_MARK_BEGIN(name)
130 #define GEOS_CALIPER_MARK_END(name)
131 
132 #define GEOS_CALIPER_MARK_FUNCTION_BEGIN
133 #define GEOS_CALIPER_MARK_FUNCTION_END
135 
136 #endif // GEOS_USE_CALIPER
137 
139 #define GEOS_MARK_SCOPE(name) GEOS_CALIPER_MARK_SCOPE(name); GEOS_NVTX_MARK_SCOPE(name)
141 #define GEOS_MARK_SCOPE_STR(name) GEOS_CALIPER_MARK_SCOPE_STR(name); GEOS_NVTX_MARK_SCOPE_STR(name)
143 #define GEOS_MARK_FUNCTION GEOS_CALIPER_MARK_FUNCTION; GEOS_NVTX_MARK_FUNCTION
145 #define GEOS_MARK_FUNCTION_BEGIN(name) GEOS_CALIPER_MARK_FUNCTION_BEGIN(name)
147 #define GEOS_MARK_FUNCTION_END(name) GEOS_CALIPER_MARK_FUNCTION_END(name)
149 #define GEOS_MARK_BEGIN(name) GEOS_CALIPER_MARK_BEGIN(name)
151 #define GEOS_MARK_END(name) GEOS_CALIPER_MARK_END(name)
152 
154 #ifdef GEOS_USE_TIMERS
155 #define GEOS_GET_TIME( time ) \
156  real64 time; \
157  do \
158  { \
159  timeval tim; \
160  gettimeofday(&tim, nullptr); \
161  time = tim.tv_sec + (tim.tv_usec / 1000000.0); \
162  } while (false)
163 #else
164 #define GEOS_GET_TIME( time )
165 #endif
166 
167 #endif // GEOS_COMMON_TIMINGMACROS_HPP_
std::string string
String type.
Definition: DataTypes.hpp:90