FunctionTrace.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_TRACING_FUNCTIONTRACE_H_
36 #define _BLAZE_UTIL_TRACING_FUNCTIONTRACE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #if BLAZE_OPENMP_PARALLEL_MODE
44 # include <omp.h>
45 #elif BLAZE_CPP_THREADS_PARALLEL_MODE
46 # include <thread>
47 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
48 # include <boost/thread/thread.hpp>
49 #endif
50 
51 #include <iostream>
52 #include <new>
53 #include <sstream>
54 #include <string>
55 #include <blaze/system/Debugging.h>
56 #include <blaze/system/Signature.h>
57 #include <blaze/system/SMP.h>
58 
59 
60 namespace blaze {
61 
62 //=================================================================================================
63 //
64 // CLASS DEFINITION
65 //
66 //=================================================================================================
67 
68 //*************************************************************************************************
77 {
78  public:
79  //**Constructors********************************************************************************
82  inline FunctionTrace( const std::string& file, const std::string& function );
84  //**********************************************************************************************
85 
86  //**Destructor**********************************************************************************
89  inline ~FunctionTrace();
91  //**********************************************************************************************
92 
93  //**Forbidden operations************************************************************************
96  FunctionTrace( const FunctionTrace& ) = delete;
97  FunctionTrace( FunctionTrace&& ) = delete;
98 
99  FunctionTrace& operator=( const FunctionTrace& ) = delete;
100  FunctionTrace& operator=( FunctionTrace&& ) = delete;
101 
102  void* operator new ( std::size_t ) = delete;
103  void* operator new[]( std::size_t ) = delete;
104  void* operator new ( std::size_t, const std::nothrow_t& ) noexcept = delete;
105  void* operator new[]( std::size_t, const std::nothrow_t& ) noexcept = delete;
106 
107  void operator delete ( void* ) noexcept = delete;
108  void operator delete[]( void* ) noexcept = delete;
109  void operator delete ( void*, const std::nothrow_t& ) noexcept = delete;
110  void operator delete[]( void*, const std::nothrow_t& ) noexcept = delete;
112  //**********************************************************************************************
113 
114  private:
115  //**Member variables****************************************************************************
118  std::string file_;
119  std::string function_;
120 
121  //**********************************************************************************************
122 };
123 //*************************************************************************************************
124 
125 
126 
127 
128 //=================================================================================================
129 //
130 // CONSTRUCTORS
131 //
132 //=================================================================================================
133 
134 //*************************************************************************************************
140 inline FunctionTrace::FunctionTrace( const std::string& file, const std::string& function )
141  : file_ ( file ) // The file name the traced function is contained in
142  , function_( function ) // The name of the traced function
143 {
144  std::ostringstream oss;
145  oss << " + ";
146 
147 #if BLAZE_OPENMP_PARALLEL_MODE
148  oss << "[Thread " << omp_get_thread_num() << "]";
149 #elif BLAZE_CPP_THREADS_PARALLEL_MODE
150  oss << "[Thread " << std::this_thread::get_id() << "]";
151 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
152  oss << "[Thread " << boost::this_thread::get_id() << "]";
153 #endif
154 
155  oss << " Entering function '" << function_ << "' in file '" << file_ << "'\n";
156  std::cerr << oss.str();
157 }
158 //*************************************************************************************************
159 
160 
161 
162 
163 //=================================================================================================
164 //
165 // DESTRUCTOR
166 //
167 //=================================================================================================
168 
169 //*************************************************************************************************
173 {
174  std::ostringstream oss;
175  oss << " - ";
176 
177 #if BLAZE_OPENMP_PARALLEL_MODE
178  oss << "[Thread " << omp_get_thread_num() << "]";
179 #elif BLAZE_CPP_THREADS_PARALLEL_MODE
180  oss << "[Thread " << std::this_thread::get_id() << "]";
181 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
182  oss << "[Thread " << boost::this_thread::get_id() << "]";
183 #endif
184 
185  oss << " Leaving function '" << function_ << "' in file '" << file_ << "'\n";
186  std::cerr << oss.str();
187 }
188 //*************************************************************************************************
189 
190 } // namespace blaze
191 
192 #endif
Header file for a compiler independent type/function signature macro.
FunctionTrace(const std::string &file, const std::string &function)
Constructor for the FunctionTrace class.
Definition: FunctionTrace.h:140
RAII object for function tracing.The FunctionTrace class is an auxiliary helper class for the tracing...
Definition: FunctionTrace.h:76
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
System settings for the shared-memory parallelization.
std::string file_
The file name the traced function is contained in.
Definition: FunctionTrace.h:118
~FunctionTrace()
Destructor for the FunctionTrace class.
Definition: FunctionTrace.h:172
std::string function_
The name of the traced function.
Definition: FunctionTrace.h:119
System settings for the debugging policy of the Blaze library.