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 Total, S.A
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 GEOSX_COMMON_TIMINGMACROS_HPP_
26 #define GEOSX_COMMON_TIMINGMACROS_HPP_
27 
28 #include "common/GeosxConfig.hpp"
29 #include "common/GeosxMacros.hpp"
30 
31 #ifdef GEOSX_USE_CALIPER
32 #include <caliper/cali.h>
33 #include <sys/time.h>
34 #include <string>
35 #include <iostream>
36 
37 namespace timingHelpers
38 {
39  inline std::string stripPF( char const * prettyFunction )
40  {
41  std::string input(prettyFunction);
42  std::string::size_type const end = input.find_first_of( '(' );
43  std::string::size_type const beg = input.find_last_of( ' ', end)+1;
44  return input.substr( beg, end-beg );
45  }
46 }
47 
49 #define GEOSX_MARK_SCOPE(name) cali::Function __cali_ann##__LINE__(STRINGIZE_NX(name))
50 
52 #define GEOSX_MARK_FUNCTION cali::Function __cali_ann##__func__(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str())
53 
55 #define GEOSX_MARK_BEGIN(name) CALI_MARK_BEGIN(STRINGIZE(name))
56 
58 #define GEOSX_MARK_END(name) CALI_MARK_END(STRINGIZE(name))
59 
61 #define GEOSX_MARK_FUNCTION_BEGIN CALI_MARK_FUNCTION_BEGIN
62 
64 #define GEOSX_MARK_FUNCTION_END CALI_MARK_FUNCTION_END
65 
66 #else // GEOSX_USE_CALIPER
67 
69 #define GEOSX_MARK_SCOPE(name)
70 #define GEOSX_MARK_FUNCTION_SCOPED
71 #define GEOSX_MARK_FUNCTION
72 
73 #define GEOSX_MARK_BEGIN(name)
74 #define GEOSX_MARK_END(name)
75 
76 #define GEOSX_MARK_FUNCTION_BEGIN
77 #define GEOSX_MARK_FUNCTION_END
78 
80 #endif // GEOSX_USE_CALIPER
81 
83 #ifdef GEOSX_USE_TIMERS
84 #define GEOSX_GET_TIME( time ) \
85  real64 time; \
86  do \
87  { \
88  timeval tim; \
89  gettimeofday(&tim, nullptr); \
90  time = tim.tv_sec + (tim.tv_usec / 1000000.0); \
91  } while (false)
92 #else
93 #define GEOSX_GET_TIME( time )
94 #endif
95 
96 #endif // GEOSX_COMMON_TIMINGMACROS_HPP_
std::string string
String type.
Definition: DataTypes.hpp:131