Go to the documentation of this file.
18 #ifndef viskores_cont_Logging_h
19 #define viskores_cont_Logging_h
199 #define VISKORES_CONCAT_IMPL(s1, s2) s1##s2
200 #define VISKORES_CONCAT(s1, s2) VISKORES_CONCAT_IMPL(s1, s2)
203 #define VISKORES_ANONYMOUS_VARIABLE VISKORES_CONCAT(viskores_anonymous_, __COUNTER__)
205 #define VISKORES_ANONYMOUS_VARIABLE VISKORES_CONCAT(viskores_anonymous_, __LINE__)
208 #if defined(VISKORES_ENABLE_LOGGING)
210 #define VISKORES_LOG_IF_S(level, cond, ...) \
211 viskores::cont::LogCondStream(level, cond, __FILE__, __LINE__) << __VA_ARGS__
213 #define VISKORES_LOG_IF_F(level, cond, ...) \
214 viskores::cont::LogCond(level, cond, __FILE__, __LINE__, __VA_ARGS__)
216 #define VISKORES_LOG_S(level, ...) VISKORES_LOG_IF_S(level, true, __VA_ARGS__)
217 #define VISKORES_LOG_F(level, ...) VISKORES_LOG_IF_F(level, true, __VA_ARGS__)
219 #define VISKORES_LOG_SCOPE(level, ...) \
220 viskores::cont::detail::LogScope VISKORES_ANONYMOUS_VARIABLE \
222 level, __FILE__, __LINE__, __VA_ARGS__ \
225 #define VISKORES_LOG_SCOPE_FUNCTION(level) VISKORES_LOG_SCOPE(level, __func__)
226 #define VISKORES_LOG_ALWAYS_S(level, ...) VISKORES_LOG_S(level, __VA_ARGS__)
232 #define VISKORES_LOG_CAST_SUCC(inObj, outObj) \
233 VISKORES_LOG_F(viskores::cont::LogLevel::Cast, \
234 "Cast succeeded: %s (%p) --> %s (%p)", \
235 viskores::cont::TypeToString(inObj).c_str(), \
237 viskores::cont::TypeToString(outObj).c_str(), \
241 #define VISKORES_LOG_CAST_FAIL(inObj, outType) \
242 VISKORES_LOG_F(viskores::cont::LogLevel::Cast, \
243 "Cast failed: %s (%p) --> %s", \
244 viskores::cont::TypeToString(inObj).c_str(), \
246 viskores::cont::TypeToString<outType>().c_str())
249 #define VISKORES_LOG_TRYEXECUTE_FAIL(errorMessage, functorName, deviceId) \
250 VISKORES_LOG_S(viskores::cont::LogLevel::Error, \
251 "TryExecute encountered an error: " << errorMessage); \
252 VISKORES_LOG_S(viskores::cont::LogLevel::Error, "Failing functor: " << functorName); \
253 VISKORES_LOG_S(viskores::cont::LogLevel::Error, "Failing device: " << deviceId.GetName())
256 #define VISKORES_LOG_TRYEXECUTE_DISABLE(errorMessage, functorName, deviceId) \
257 VISKORES_LOG_S(viskores::cont::LogLevel::Error, \
258 "TryExecute encountered an error: " << errorMessage); \
259 VISKORES_LOG_S(viskores::cont::LogLevel::Error, "Failing functor: " << functorName); \
260 VISKORES_LOG_S(viskores::cont::LogLevel::Error, "Failing device: " << deviceId.GetName()); \
261 VISKORES_LOG_S(viskores::cont::LogLevel::Error, "The failing device has been disabled.")
264 #define VISKORES_DEFINE_USER_LOG_LEVEL(name, offset) \
265 static constexpr viskores::cont::LogLevel name = static_cast<viskores::cont::LogLevel>( \
266 static_cast<typename std::underlying_type<viskores::cont::LogLevel>::type>( \
267 viskores::cont::LogLevel::UserFirst) + \
269 static_cast<typename std::underlying_type<viskores::cont::LogLevel>::type>( \
270 viskores::cont::LogLevel::UserLast))
272 #else // VISKORES_ENABLE_LOGGING
274 #define VISKORES_LOG_S(level, ...)
275 #define VISKORES_LOG_F(level, ...)
276 #define VISKORES_LOG_IF_S(level, cond, ...)
277 #define VISKORES_LOG_IF_F(level, cond, ...)
278 #define VISKORES_LOG_SCOPE(level, ...)
279 #define VISKORES_LOG_SCOPE_FUNCTION(level)
280 #define VISKORES_LOG_ERROR_CONTEXT(desc, data)
281 #define VISKORES_LOG_CAST_SUCC(inObj, outObj)
282 #define VISKORES_LOG_CAST_FAIL(inObj, outType)
283 #define VISKORES_DEFINE_USER_LOG_LEVEL(name, offset)
287 #define VISKORES_LOG_ALWAYS_S(level, ...) \
288 (static_cast<int>(level) < 0 ? std::cerr : std::cout) \
289 << viskores::cont::GetLogLevelName(level) << ": " << __VA_ARGS__ << "\n"
293 #define VISKORES_LOG_TRYEXECUTE_FAIL(errorMessage, functorName, deviceId) \
294 std::cerr << "Error: TryExecute encountered an error: " << errorMessage << "\n" \
295 << "\t- Failing functor: " << functorName << "\n" \
296 << "\t- Failing device: " << deviceId.GetName() << "\n\n"
297 #define VISKORES_LOG_TRYEXECUTE_DISABLE(errorMessage, functorName, deviceId) \
298 std::cerr << "Error: TryExecute encountered an error: " << errorMessage << "\n" \
299 << "\t- Failing functor: " << functorName << "\n" \
300 << "\t- Failing device: " << deviceId.GetName() << "\n" \
301 << "The failing device has been disabled.\n\n"
303 #endif // VISKORES_ENABLE_LOGGING
389 const std::string& loggingFlag =
"--viskores-log-level",
390 const std::string& loggingEnv =
"VISKORES_LOG_LEVEL");
473 template <
typename T>
487 template <
typename T>
501 template <
typename T>
506 template <
typename T>
513 #ifdef VISKORES_ENABLE_LOGGING
526 void LogCond(
LogLevel level,
bool cond,
const char* file,
unsigned line,
const char* format...);
538 class VISKORES_CONT_EXPORT LogScope
540 struct InternalStruct;
541 std::unique_ptr<InternalStruct> Internals;
550 LogScope(
LogLevel level,
const char* file,
unsigned line,
const char* format...);
577 template <typename T>
598 #endif // VISKORES_ENABLE_LOGGING
603 #endif // viskores_cont_Logging_h
@ UserVerboseFirst
The first in a range of logging levels reserved for code that uses Viskores.
std::ostringstream SStream
Definition: Logging.h:596
void LogCond(LogLevel level, bool cond, const char *file, unsigned line, const char *format...)
Conditionally logs a message with a printf-like format.
@ Warn
Less important user errors, such as out-of-bounds parameters.
std::string GetHumanReadableSize(viskores::UInt64 bytes, int prec=2)
Convert a size in bytes to a human readable string (such as "64 bytes", "1.44 MiB",...
viskores::cont::LogLevel GetStderrLogLevel()
Get the active highest log level that will be printed to stderr.
void SetStderrLogLevel(const char *verbosity)
Set the range of log levels that will be printed to stderr.
@ Info
Information messages (detected hardware, etc) and temporary debugging output.
LogCondStream & operator<<(std::ostream &(*f)(std::ostream &))
Definition: Logging.h:585
@ UserLast
The last in a range of logging levels reserved for code that uses Viskores.
@ Fatal
Fatal errors that should abort execution.
@ Cast
Reports when a dynamic object is (or is not) resolved via a CastAndCall or other casting method.
std::string GetLogErrorContext()
std::string GetLogThreadName()
Specifies a humman-readable name to identify the current thread in the log output.
LogLevel Level
Definition: Logging.h:592
#define VISKORES_CONT
Definition: ExportMacros.h:65
Groups connected points that have the same field value.
Definition: Atomic.h:27
LogLevel
Log levels for use with the logging macros.
Definition: Logging.h:311
@ UserFirst
The first in a range of logging levels reserved for code that uses Viskores.
Conditionally logs a message with a stream-like interface.
Definition: Logging.h:563
LogCondStream(LogLevel level, bool cond, const char *file, int line)
Definition: Logging.h:566
@ KernelLaunches
Details on device-side kernel launches.
@ MemExec
Device-side resource allocations/frees (e.g ArrayHandle device buffers).
std::string GetStackTrace(viskores::Int32 skip=0)
Returns a stacktrace on supported platforms.
bool Condition
Definition: Logging.h:593
Represent an infinite or semi-infinite line segment with a point and a direction.
Definition: Geometry.h:29
@ Off
A placeholder used to silence all logging.
@ DevicesEnabled
Information about which devices are enabled/disabled.
@ MemCont
Host-side resource allocations/frees (e.g. ArrayHandle control buffers).
unsigned long long UInt64
Base type to use for 64-bit signed integer numbers.
Definition: Types.h:215
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:189
const char * File
Definition: Logging.h:594
void InitLogging(int &argc, char *argv[], const std::string &loggingFlag="--viskores-log-level", const std::string &loggingEnv="VISKORES_LOG_LEVEL")
This shouldn't be called directly – prefer calling viskores::cont::Initialize, which takes care of lo...
@ MemTransfer
Transferring of data between a host and device.
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
@ UserVerboseLast
The last in a range of logging levels reserved for code that uses Viskores.
The superclass of all exceptions thrown by any Viskores function or method.
Definition: Error.h:41
void SetLogLevelName(viskores::cont::LogLevel level, const std::string &name)
Register a custom name to identify a log level.
std::string GetSizeString(viskores::UInt64 bytes, int prec=2)
Returns "%1 (%2 bytes)" where %1 is the result from GetHumanReadableSize and %2 is the exact number o...
std::string TypeToString(const std::type_info &t)
Use RTTI information to retrieve the name of the type T.
void SetLogThreadName(const std::string &name)
Specifies a humman-readable name to identify the current thread in the log output.
std::string GetLogLevelName(viskores::cont::LogLevel level)
Get a human readable name for the log level.
int Line
Definition: Logging.h:595