Go to the documentation of this file.
10 #ifndef vtk_m_cont_Logging_h
11 #define vtk_m_cont_Logging_h
13 #include <vtkm/internal/Configure.h>
18 #include <vtkm/cont/vtkm_cont_export.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
369 void InitLogging(
int& argc,
char* argv[],
const std::string& loggingFlag =
"--vtkm-log-level");
452 template <
typename T>
466 template <
typename T>
469 return GetSizeString(
static_cast<vtkm::UInt64
>(std::forward<T>(bytes)), prec);
480 template <
typename T>
485 template <
typename T>
492 #ifdef VTKM_ENABLE_LOGGING
503 void LogCond(
LogLevel level,
bool cond,
const char* file,
unsigned line,
const char* format...);
515 class VTKM_CONT_EXPORT LogScope
517 struct InternalStruct;
518 std::unique_ptr<InternalStruct> Internals;
527 LogScope(
LogLevel level,
const char* file,
unsigned line,
const char* format...);
540 struct VTKM_CONT_EXPORT LogCondStream
543 LogCondStream(
LogLevel level,
bool cond,
const char* file,
int line)
552 ~LogCondStream() noexcept(false);
554 template <typename T>
555 VTKM_CONT LogCondStream& operator<<(const T& in)
562 LogCondStream&
operator<<(std::ostream& (*f)(std::ostream&))
573 std::ostringstream SStream;
575 #endif // VTKM_ENABLE_LOGGING
580 #endif // vtk_m_cont_Logging_h
VTKM_CONT_EXPORT VTKM_CONT void InitLogging(int &argc, char *argv[], const std::string &loggingFlag="--vtkm-log-level")
This shouldn't be called directly – prefer calling vtkm::cont::Initialize, which takes care of loggin...
@ UserVerboseFirst
1024-2047 are reserved for application usage.
VTKM_CONT_EXPORT VTKM_CONT std::string GetLogThreadName()
The name to identify the current thread in the log output.
VTKM_CONT_EXPORT VTKM_CONT std::string GetSizeString(vtkm::UInt64 bytes, int prec=2)
Returns "%1 (%2 bytes)" where %1 is the result from GetHumanReadableSize and two is the exact number ...
Groups connected points that have the same field value.
Definition: Atomic.h:19
@ Warn
Less important user errors, such as out-of-bounds parameters.
VTKM_CONT_EXPORT VTKM_CONT void SetStderrLogLevel(const char *verbosity)
Set the range of log levels that will be printed to stderr.
@ DevicesEnabled
Information about which devices are enabled/disabled.
@ MemTransfer
Host->device / device->host data copies.
VTKM_CONT_EXPORT VTKM_CONT std::string GetStackTrace(vtkm::Int32 skip=0)
Returns a stacktrace on supported platforms.
@ UserLast
The range 1-255 are reserved to application use.
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
@ UserVerboseLast
1024-2047 are reserved for application usage.
@ Cast
When a dynamic object is (or isn't) resolved via CastAndCall, etc.
VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::LogLevel GetStderrLogLevel()
Get the active highest log level that will be printed to stderr.
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:330
VTKM_CONT_EXPORT VTKM_CONT void SetLogThreadName(const std::string &name)
The name to identify the current thread in the log output.
@ Info
Information messages (detected hardware, etc) and temporary debugging output.
VTKM_CONT_EXPORT VTKM_CONT void SetLogLevelName(vtkm::cont::LogLevel level, const std::string &name)
Register a custom name to identify a log level.
@ KernelLaunches
Details on Device-side Kernel Launches.
VTKM_CONT_EXPORT VTKM_CONT std::string GetHumanReadableSize(vtkm::UInt64 bytes, int prec=2)
Convert a size in bytes to a human readable string (e.g.
VTKM_CONT std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:237
#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.
@ Off
Used with SetStderrLogLevel to silence the log.
@ MemExec
Device-side resource allocations/frees (e.g ArrayHandle device buffers)
int32_t Int32
Definition: Types.h:160
VTKM_CONT_EXPORT VTKM_CONT std::string GetLogLevelName(vtkm::cont::LogLevel level)
Get a human readable name for the log level.
VTKM_CONT_EXPORT VTKM_CONT std::string GetLogErrorContext()
VTKM_CONT_EXPORT VTKM_CONT std::string TypeToString(const std::type_info &t)
Use RTTI information to retrieve the name of the type T.
@ UserFirst
The range 1-255 are reserved to application use.
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...