feisty meow concerns codebase  2.140
application::callstack_tracker Class Reference

This object can provide a backtrace at runtime of the invoking methods. More...

#include <callstack_tracker.h>

Public Member Functions

 callstack_tracker ()
 
virtual ~callstack_tracker ()
 
bool push_frame (const char *class_name, const char *func, const char *file, int line)
 adds a new stack from for the "class_name" in "function" at the "line". More...
 
bool pop_frame ()
 removes the last callstack frame off from our tracking. More...
 
bool update_line (int line)
 sets the line number within the current stack frame. More...
 
char * full_trace () const
 provides the current stack trace in a newly malloc'd string. More...
 
int full_trace_size () const
 this returns an estimated number of bytes needed for the full_trace(). More...
 
int depth () const
 the current number of frames we know of. More...
 
double frames_in () const
 reports the number of call stack frames that were added, total. More...
 
double frames_out () const
 reports the number of call stack frames that were removed, total. More...
 
double highest () const
 reports the maximum stack depth seen during the runtime so far. More...
 

Static Public Member Functions

static basis::mutex__callstack_tracker_synchronizer ()
 protects concurrent access. More...
 

Detailed Description

This object can provide a backtrace at runtime of the invoking methods.

The callstack tracking is hooked in through the FUNCDEF macros used to set function names for logging. Thus it will only be visible if those macros are used fairly carefully or if people invoke the stack frame addition method themselves.

Definition at line 48 of file callstack_tracker.h.

Constructor & Destructor Documentation

◆ callstack_tracker()

application::callstack_tracker::callstack_tracker ( )

Definition at line 97 of file callstack_tracker.cpp.

◆ ~callstack_tracker()

application::callstack_tracker::~callstack_tracker ( )
virtual

Definition at line 107 of file callstack_tracker.cpp.

References basis::WHACK().

Member Function Documentation

◆ __callstack_tracker_synchronizer()

basis::mutex & application::callstack_tracker::__callstack_tracker_synchronizer ( )
static

protects concurrent access.

Definition at line 45 of file callstack_tracker.cpp.

Referenced by full_trace(), full_trace_size(), pop_frame(), push_frame(), and update_line().

◆ depth()

int application::callstack_tracker::depth ( ) const
inline

the current number of frames we know of.

Definition at line 81 of file callstack_tracker.h.

◆ frames_in()

double application::callstack_tracker::frames_in ( ) const
inline

reports the number of call stack frames that were added, total.

Definition at line 84 of file callstack_tracker.h.

◆ frames_out()

double application::callstack_tracker::frames_out ( ) const
inline

reports the number of call stack frames that were removed, total.

Definition at line 87 of file callstack_tracker.h.

◆ full_trace()

char * application::callstack_tracker::full_trace ( ) const

provides the current stack trace in a newly malloc'd string.

the user must free() the string returned.

Definition at line 173 of file callstack_tracker.cpp.

References __callstack_tracker_synchronizer(), CHECK_SPACE_IN_BUFFER, application::emptiness_note, full_trace_size(), application::MAX_TEXT_FIELD, and filename_helper::temp.

◆ full_trace_size()

int application::callstack_tracker::full_trace_size ( ) const

this returns an estimated number of bytes needed for the full_trace().

Definition at line 237 of file callstack_tracker.cpp.

References __callstack_tracker_synchronizer(), application::emptiness_note, and application::MAX_TEXT_FIELD.

Referenced by structures::static_memory_gremlin::__hoople_globals(), and full_trace().

◆ highest()

double application::callstack_tracker::highest ( ) const
inline

reports the maximum stack depth seen during the runtime so far.

Definition at line 90 of file callstack_tracker.h.

◆ pop_frame()

bool application::callstack_tracker::pop_frame ( )

removes the last callstack frame off from our tracking.

Definition at line 134 of file callstack_tracker.cpp.

References __callstack_tracker_synchronizer().

Referenced by application::frame_tracking_instance::clean().

◆ push_frame()

bool application::callstack_tracker::push_frame ( const char *  class_name,
const char *  func,
const char *  file,
int  line 
)

adds a new stack from for the "class_name" in "function" at the "line".

this function should be invoked when entering a new stack frame. the "file" can be gotten from the FILE macro and the "line" number can come from LINE, but the "class_name" and "func" must be tracked some other way. we recommend the FUNCDEF macro. this function might return false if there is no longer any room for tracking more frames; that is a serious issue that might indicate a runaway recursion or infinite loop.

Definition at line 113 of file callstack_tracker.cpp.

References __callstack_tracker_synchronizer(), and application::MAX_STACK_DEPTH.

Referenced by application::frame_tracking_instance::frame_tracking_instance().

◆ update_line()

bool application::callstack_tracker::update_line ( int  line)

sets the line number within the current stack frame.

the current frame can reside across several line numbers, so this allows the code to be more specific about the location of an invocation.

Definition at line 153 of file callstack_tracker.cpp.

References __callstack_tracker_synchronizer().

Referenced by application::update_current_stack_frame_line_number().


The documentation for this class was generated from the following files: