|
Sierra Toolkit
Version of the Day
|
1 #ifndef STK_UTIL_SIERRA_TRACE_HPP
2 #define STK_UTIL_SIERRA_TRACE_HPP
10 #include <stk_util/diag/Writer_fwd.hpp>
14 #define SLIB_TRACE_COVERAGE
93 typedef std::vector<const char *> TracebackStack;
116 enum {STACK_SIZE = 2048};
117 typedef const char *
Stack[STACK_SIZE] ;
166 if (s_top >= &s_stack[STACK_SIZE - 1] || s_top == 0)
168 *s_top++ = function_spec;
170 if (s_tracebackState == THROWING && !s_tracebackPreserve && !std::uncaught_exception())
171 s_tracebackState = RUNNING;
173 #ifdef SLIB_TRACE_COVERAGE
174 if (s_coverageEnabled)
175 ++s_coverage[function_spec];
186 if (!s_tracebackPreserve && std::uncaught_exception() && s_tracebackState == RUNNING) {
187 s_tracebackState = THROWING;
188 s_storedTop = s_storedStack + (s_top - s_stack);
189 std::copy(s_stack, s_top, s_storedStack);
191 if (s_top > &s_stack[0])
195 static TracebackStack snapshot();
203 --s_tracebackDisplay;
212 ++s_tracebackDisplay;
223 return s_tracebackDisplay == 0;
232 ++s_tracebackPreserve;
241 --s_tracebackPreserve;
254 s_coverageEnabled = coverage_enabled;
265 return s_coverageEnabled;
275 return s_tracebackState;
313 static std::string
printTraceback(
const TracebackStack &traceback_stack);
329 static int s_tracebackPreserve;
330 static int s_tracebackDisplay;
331 static const char ** s_top;
332 static Stack s_stack;
333 static const char ** s_storedTop;
334 static Stack s_storedStack;
335 static bool s_coverageEnabled;
368 s_traceListExists =
true;
372 s_traceListExists =
false;
401 Trace(
Writer &dout,
const char *function_name,
int print_mask = LOG_TRACE,
bool do_trace =
true);
433 char *s = std::strcpy(
new char[function_prefix.length() + 1], function_prefix.c_str());
435 s_traceList.push_back(s);
444 for (std::vector<const char *>::iterator it = s_traceList.begin(); it != s_traceList.end(); ++it)
462 double m_startCpuTime;
463 size_t m_startMemAlloc;
464 PrintMask m_lineMask;
469 static TraceList s_traceList;
470 static bool s_traceListExists;
526 #endif // STK_UTIL_SIERRA_TRACE_HPP
static ExtraFuncPtr setExtra(ExtraFuncPtr extra)
Member function setExtra sets the extra function which is called during each trace construction and d...
Writer & verbose_print(Writer &dout) const
Member function dump writes the trace to the specified Writer.
const char * getFunctionSpec() const
Member function getFunctionSpec returns the function's name.
Tracespec(const char *function_spec)
TracebackState
Enumeration TracebackState lists the traceback execution states.
static TracebackState getTracebackState()
Member function getTracebackState returns the value of the traceback state.
static void releaseStack()
Member function releaseStack decrements the traceback stack preservation counter.
static void disableTracebackDisplay()
Member function disableTracebackDisplay disables the display of the traceback.
static std::string printTraceback(const TracebackStack &traceback_stack)
Member function printTraceback writes the traceback stack function specifications to the output strea...
static bool coverageEnabled()
Member function coverageEnabled returns true if coverage has been enabled.
static PrintCoverage printCoverage()
Member function printCoverage creates a PrintCoverage type holder class which enables operator<< to p...
Class Tracespec dissects file specification strings. It contains a single char const pointer to a fun...
std::map< const char *, int > Coverage
Typedef Coverage declares the function usage coverage data type.
static void enableTracebackDisplay()
Member function enableTracebackDisplay enables the display of the traceback.
Class Traceback is a stack of char constant pointers to function specifications which have been encou...
const typedef char *const * const_stack_iterator
const iterator thru stack
const typedef char * Stack[STACK_SIZE]
Stack type.
std::string getFunctionShortName() const
Member function getFunctionName returns the function's name.
Writer & verbose_print(Writer &dout) const
Member function verbose_print dumps the function specification stack to the diagnostic writer.
std::string getFunctionNamespace() const
Member function getFunctionName returns the function's name.
Trace(Writer &dout, const char *function_name, int print_mask=LOG_TRACE, bool do_trace=true)
Creates a new Trace instance, resulting in the printing of the member function name and pushing the d...
static void enableCoverage(bool coverage_enabled=true)
Member function enableCoverage enables the collection of function call coverage data....
~Trace()
Destroys a Trace instance, resulting in the printing of the member function name and popping the diag...
std::string getFunctionName() const
Member function getFunctionName returns the function's name.
Writer &(* ExtraFuncPtr)(Writer &)
Typedef ExtraFuncPtr declares the extra function pointer signature.
const char * m_functionSpec
The member function specification.
Tracing enabled by this function.
Class PrintCoverage is a type holder class for printing the stack.
Class Writer implements a runtime selectable diagnostic output writer to aid in the development and d...
~Preserve()
Destroys a Preserve sentry which allows traceback stack.
~Traceback()
Destroys a Traceback instance, resulting in the pushing of the function specification if unwinding th...
Preserve()
Creates a new Traceback::Preserve sentry. When the sentry is in place, the traceback stack is preserv...
static void clearTraceFunctions()
Member function clearTraceFunctions removes all function prefixes from the function signature prefix ...
Class Traceback::Preserve serves as a sentry for traceback stack preservation during additional exten...
const typedef char ** stack_iterator
iterator thru stack
Traceback(const char *function_spec)
Creates a new Trace instance, resulting in the printing of the member function name and pushing the d...
static void preserveStack()
Member function preserveStack increments the traceback stack preservation counter.
Typedef TraceList declares the trace list data type.
static bool displayTraceback()
Member function displayEnabled returns true if display of the tracback stack has been enabled.
std::string getFunctionClass() const
Member function getFunctionName returns the function's name.
static void addTraceFunction(const std::string &function_prefix)
Member function addTraceFunction adds a function prefix to the list of function prefixes search to en...
Class Trace serves as a sentry for entering routines. Creating a trace object prints the specified me...
std::string getFunctionShortClass() const
Member function getFunctionName returns the function's name.