Go to the documentation of this file.
10 #ifndef vtk_m_cont_Logging_h
11 #define vtk_m_cont_Logging_h
191 #define VTKM_CONCAT_IMPL(s1, s2) s1##s2
192 #define VTKM_CONCAT(s1, s2) VTKM_CONCAT_IMPL(s1, s2)
195 #define VTKM_ANONYMOUS_VARIABLE VTKM_CONCAT(vtk_m_anonymous_, __COUNTER__)
197 #define VTKM_ANONYMOUS_VARIABLE VTKM_CONCAT(vtk_m_anonymous_, __LINE__)
200 #if defined(VTKM_ENABLE_LOGGING)
202 #define VTKM_LOG_IF_S(level, cond, ...) \
203 vtkm::cont::LogCondStream(level, cond, __FILE__, __LINE__) << __VA_ARGS__
205 #define VTKM_LOG_IF_F(level, cond, ...) \
206 vtkm::cont::LogCond(level, cond, __FILE__, __LINE__, __VA_ARGS__)
208 #define VTKM_LOG_S(level, ...) VTKM_LOG_IF_S(level, true, __VA_ARGS__)
209 #define VTKM_LOG_F(level, ...) VTKM_LOG_IF_F(level, true, __VA_ARGS__)
211 #define VTKM_LOG_SCOPE(level, ...) \
212 vtkm::cont::detail::LogScope VTKM_ANONYMOUS_VARIABLE { level, __FILE__, __LINE__, __VA_ARGS__ }
214 #define VTKM_LOG_SCOPE_FUNCTION(level) VTKM_LOG_SCOPE(level, __func__)
215 #define VTKM_LOG_ALWAYS_S(level, ...) VTKM_LOG_S(level, __VA_ARGS__)
221 #define VTKM_LOG_CAST_SUCC(inObj, outObj) \
222 VTKM_LOG_F(vtkm::cont::LogLevel::Cast, \
223 "Cast succeeded: %s (%p) --> %s (%p)", \
224 vtkm::cont::TypeToString(inObj).c_str(), \
226 vtkm::cont::TypeToString(outObj).c_str(), \
230 #define VTKM_LOG_CAST_FAIL(inObj, outType) \
231 VTKM_LOG_F(vtkm::cont::LogLevel::Cast, \
232 "Cast failed: %s (%p) --> %s", \
233 vtkm::cont::TypeToString(inObj).c_str(), \
235 vtkm::cont::TypeToString<outType>().c_str())
238 #define VTKM_LOG_TRYEXECUTE_FAIL(errorMessage, functorName, deviceId) \
239 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "TryExecute encountered an error: " << errorMessage); \
240 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "Failing functor: " << functorName); \
241 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "Failing device: " << deviceId.GetName())
244 #define VTKM_LOG_TRYEXECUTE_DISABLE(errorMessage, functorName, deviceId) \
245 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "TryExecute encountered an error: " << errorMessage); \
246 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "Failing functor: " << functorName); \
247 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "Failing device: " << deviceId.GetName()); \
248 VTKM_LOG_S(vtkm::cont::LogLevel::Error, "The failing device has been disabled.")
251 #define VTKM_DEFINE_USER_LOG_LEVEL(name, offset) \
252 static constexpr vtkm::cont::LogLevel name = static_cast<vtkm::cont::LogLevel>( \
253 static_cast<typename std::underlying_type<vtkm::cont::LogLevel>::type>( \
254 vtkm::cont::LogLevel::UserFirst) + \
256 static_cast<typename std::underlying_type<vtkm::cont::LogLevel>::type>( \
257 vtkm::cont::LogLevel::UserLast))
259 #else // VTKM_ENABLE_LOGGING
261 #define VTKM_LOG_S(level, ...)
262 #define VTKM_LOG_F(level, ...)
263 #define VTKM_LOG_IF_S(level, cond, ...)
264 #define VTKM_LOG_IF_F(level, cond, ...)
265 #define VTKM_LOG_SCOPE(level, ...)
266 #define VTKM_LOG_SCOPE_FUNCTION(level)
267 #define VTKM_LOG_ERROR_CONTEXT(desc, data)
268 #define VTKM_LOG_CAST_SUCC(inObj, outObj)
269 #define VTKM_LOG_CAST_FAIL(inObj, outType)
270 #define VTKM_DEFINE_USER_LOG_LEVEL(name, offset)
274 #define VTKM_LOG_ALWAYS_S(level, ...) \
275 (static_cast<int>(level) < 0 ? std::cerr : std::cout) \
276 << vtkm::cont::GetLogLevelName(level) << ": " << __VA_ARGS__ << "\n"
280 #define VTKM_LOG_TRYEXECUTE_FAIL(errorMessage, functorName, deviceId) \
281 std::cerr << "Error: TryExecute encountered an error: " << errorMessage << "\n" \
282 << "\t- Failing functor: " << functorName << "\n" \
283 << "\t- Failing device: " << deviceId.GetName() << "\n\n"
284 #define VTKM_LOG_TRYEXECUTE_DISABLE(errorMessage, functorName, deviceId) \
285 std::cerr << "Error: TryExecute encountered an error: " << errorMessage << "\n" \
286 << "\t- Failing functor: " << functorName << "\n" \
287 << "\t- Failing device: " << deviceId.GetName() << "\n" \
288 << "The failing device has been disabled.\n\n"
290 #endif // VTKM_ENABLE_LOGGING
376 const std::string& loggingFlag =
"--vtkm-log-level",
377 const std::string& loggingEnv =
"VTKM_LOG_LEVEL");
460 template <
typename T>
474 template <
typename T>
488 template <
typename T>
493 template <
typename T>
500 #ifdef VTKM_ENABLE_LOGGING
513 void LogCond(
LogLevel level,
bool cond,
const char* file,
unsigned line,
const char* format...);
527 struct InternalStruct;
528 std::unique_ptr<InternalStruct> Internals;
537 LogScope(
LogLevel level,
const char* file,
unsigned line,
const char* format...);
564 template <typename T>
585 #endif // VTKM_ENABLE_LOGGING
590 #endif // vtk_m_cont_Logging_h
Represent an infinite or semi-infinite line segment with a point and a direction.
Definition: Geometry.h:21
std::string TypeToString(const std::type_info &t)
Use RTTI information to retrieve the name of the type T.
@ UserVerboseFirst
The first in a range of logging levels reserved for code that uses VTK-m.
Groups connected points that have the same field value.
Definition: Atomic.h:19
@ Warn
Less important user errors, such as out-of-bounds parameters.
std::string GetStackTrace(vtkm::Int32 skip=0)
Returns a stacktrace on supported platforms.
@ DevicesEnabled
Information about which devices are enabled/disabled.
LogLevel Level
Definition: Logging.h:579
@ MemTransfer
Transferring of data between a host and device.
@ UserLast
The last in a range of logging levels reserved for code that uses VTK-m.
LogLevel
Log levels for use with the logging macros.
Definition: Logging.h:298
The superclass of all exceptions thrown by any VTKm function or method.
Definition: Error.h:33
bool Condition
Definition: Logging.h:580
@ UserVerboseLast
The last in a range of logging levels reserved for code that uses VTK-m.
@ Cast
Reports when a dynamic object is (or is not) resolved via a CastAndCall or other casting method.
std::string GetLogThreadName()
Specifies a humman-readable name to identify the current thread in the log output.
void LogCond(LogLevel level, bool cond, const char *file, unsigned line, const char *format...)
Conditionally logs a message with a printf-like format.
Conditionally logs a message with a stream-like interface.
Definition: Logging.h:550
std::string GetSizeString(vtkm::UInt64 bytes, int prec=2)
Returns "%1 (%2 bytes)" where %1 is the result from GetHumanReadableSize and %2 is the exact number o...
void SetLogLevelName(vtkm::cont::LogLevel level, const std::string &name)
Register a custom name to identify a log level.
@ Info
Information messages (detected hardware, etc) and temporary debugging output.
void SetStderrLogLevel(const char *verbosity)
Set the range of log levels that will be printed to stderr.
@ KernelLaunches
Details on device-side kernel launches.
std::ostringstream SStream
Definition: Logging.h:583
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
int Line
Definition: Logging.h:582
LogCondStream & operator<<(std::ostream &(*f)(std::ostream &))
Definition: Logging.h:572
#define VTKM_CONT
Definition: ExportMacros.h:57
@ MemCont
Host-side resource allocations/frees (e.g. ArrayHandle control buffers).
@ Fatal
Fatal errors that should abort execution.
std::string GetLogLevelName(vtkm::cont::LogLevel level)
Get a human readable name for the log level.
vtkm::cont::LogLevel GetStderrLogLevel()
Get the active highest log level that will be printed to stderr.
void SetLogThreadName(const std::string &name)
Specifies a humman-readable name to identify the current thread in the log output.
@ Off
A placeholder used to silence all logging.
@ MemExec
Device-side resource allocations/frees (e.g ArrayHandle device buffers).
unsigned long long UInt64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:207
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:181
std::string GetLogErrorContext()
const char * File
Definition: Logging.h:581
LogCondStream(LogLevel level, bool cond, const char *file, int line)
Definition: Logging.h:553
void InitLogging(int &argc, char *argv[], const std::string &loggingFlag="--vtkm-log-level", const std::string &loggingEnv="VTKM_LOG_LEVEL")
This shouldn't be called directly – prefer calling vtkm::cont::Initialize, which takes care of loggin...
std::string GetHumanReadableSize(vtkm::UInt64 bytes, int prec=2)
Convert a size in bytes to a human readable string (such as "64 bytes", "1.44 MiB",...
@ UserFirst
The first in a range of logging levels reserved for code that uses VTK-m.
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...