1: #ifndef included_ALE_ALE_log_hh
2: #define included_ALE_ALE_log_hh 4: #include <petscsys.h>
6: namespace ALE {
7: int getVerbosity();
8: void setVerbosity(const int& verbosity);
10: typedef PetscClassId LogCookie;
11: typedef int LogStage;
12: typedef PetscLogEvent LogEvent;
14: LogCookie LogCookieRegister(const char *name);
16: LogStage LogStageRegister(const char *name);
17: void LogStagePush(LogStage stage);
18: void LogStagePop(LogStage stage);
20: LogEvent LogEventRegister(LogCookie cookie, const char* event_name);
21: LogEvent LogEventRegister(const char* event_name);
22: void LogEventBegin(LogEvent e);
23: void LogEventEnd(LogEvent e);
27: } // namespace ALE
29: // Helper macros that push and pop log stages bracketing method invocations.
30: // These depend on the __FUNCT__ macro being declared correctly -- as the qualified method name (e.g., PreSieve::cone).
31: // Every ALE_LOG_STAGE_BEGIN must be matched by a corresponding ALE_LOG_STAGE_END.
32: // For proper logging, these macro calls must be placed outside of all code in a function, including variable declaration,
33: // except return value declaration and the actual return statement. This might require some code rearrangement.
34: // In particular, returns from inside the block bracketed by the macros will break the stage stack.
35: // ALE_LOG_STAGE_START and ALE_LOG_STAGE_FINISH mirror the corresponding BEGIN and END macros, except that they do not contain
36: // opening and closing braces and can be used more freely throughout the code
37: // ALE_LOG_EVENT_START and ALE_LOG_EVENT_FINISH can likewise be used throughout the code to start and stop logging of an event
38: // associate with the function __FUNCT__. The difference between function stages and events is implementation-dependent
39: // (currently PETSc logging).
41: #if (defined ALE_USE_LOGGING) && (defined ALE_LOGGING_USE_STAGES)
43: #define ALE_LOG_STAGE_START \ 44: { \ 45: ALE::LogStage stage = ALE::LogStageRegister(__FUNCT__); \ 46: ALE::LogStagePush(stage); \ 47: } 49: #define ALE_LOG_STAGE_FINISH \ 50: { \ 51: ALE::LogStage stage = ALE::LogStageRegister(__FUNCT__); \ 52: ALE::LogStagePop(stage); \ 53: } 55: #define ALE_LOG_STAGE_BEGIN ALE_LOG_STAGE_START { 56: #define ALE_LOG_STAGE_END } ALE_LOG_STAGE_FINISH 58: #else
60: #define ALE_LOG_STAGE_START {} 61: #define ALE_LOG_STAGE_FINISH {} 62: #define ALE_LOG_STAGE_BEGIN {} 63: #define ALE_LOG_STAGE_END {} 65: #endif
67: #if (defined ALE_USE_LOGGING) && (defined ALE_LOGGING_USE_EVENTS)
69: #define ALE_LOG_EVENT_BEGIN \ 70: { \ 71: ALE::LogEvent event = ALE::LogEventRegister(__FUNCT__); \ 72: ALE::LogEventBegin(event); \ 73: } 75: #define ALE_LOG_EVENT_END \ 76: { \ 77: ALE::LogEvent event = ALE::LogEventRegister(__FUNCT__); \ 78: ALE::LogEventEnd(event); \ 79: } 81: #else
83: #define ALE_LOG_EVENT_BEGIN {} 84: #define ALE_LOG_EVENT_END {} 86: #endif
88: #endif