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