callstack_tracker.h

Go to the documentation of this file.
00001 #ifndef CALLSTACK_TRACKER_CLASS
00002 #define CALLSTACK_TRACKER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : callstack_tracker                                                 *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "definitions.h"
00019 
00020 #ifdef ENABLE_CALLSTACK_TRACKING
00021 
00022 #include "build_configuration.h"
00023 #include "object_base.h"
00024 
00025 // forward.
00026 class callstack_records;
00027 class callstack_tracker;
00028 
00030 
00031 callstack_tracker BASIS_EXTERN &program_wide_stack_trace();
00033 
00035 
00037 
00044 class callstack_tracker
00045 {
00046 public:
00047   callstack_tracker();
00048   virtual ~callstack_tracker();
00049 
00050   IMPLEMENT_CLASS_NAME("callstack_tracker");
00051 
00052   bool push_frame(const char *class_name, const char *func, const char *file,
00053           int line);
00055 
00062   bool pop_frame();
00064 
00065   bool update_line(int line);
00067 
00070   char *full_trace() const;
00072 
00074   int full_trace_size() const;
00076 
00077   int depth() const { return _depth; }
00079 
00080   double frames_in() const { return _frames_in; }
00082 
00083   double frames_out() const { return _frames_out; }
00085 
00086   double highest() const { return _highest; }
00088 
00089 private:
00090   callstack_records *_bt;  
00091   int _depth;  
00092   double _frames_in;  
00093   double _frames_out;  
00094   double _highest;  
00095   bool _unusable;  
00096 };
00097 
00099 
00101 
00108 class frame_tracking_instance
00109 {
00110 public:
00111   // these are not encapsulated, but be careful with the contents.
00112   bool _frame_involved;  
00113   char *_class, *_func, *_file;  
00114   int _line;
00115 
00116   frame_tracking_instance(const char *class_name = "", const char *func = "",
00117       const char *file = "", int line = 0, bool add_frame = false);
00119 
00124   frame_tracking_instance(const frame_tracking_instance &to_copy);
00125 
00126   ~frame_tracking_instance();
00128 
00129   frame_tracking_instance &operator =(const frame_tracking_instance &to_copy);
00130 
00131   void assign(const char *class_name, const char *func, const char *file,
00132           int line);
00134 
00135   void clean();
00137 };
00138 
00139 void update_current_stack_frame_line_number(int line);
00141 
00142 #else // ENABLE_CALLSTACK_TRACKING
00143   // bogus replacements for most commonly used callstack tracking support.
00144   #define frame_tracking_instance
00145   #define __trail_of_function(p1, p2, p3, p4, p5) if (func) {}
00146     // the above actually trades on the name of the object we'd normally
00147     // define.  it must match the object name in the FUNCDEF macro.
00148   #define update_current_stack_frame_line_number(line)
00149 #endif // ENABLE_CALLSTACK_TRACKING
00150 
00151 #endif // outer guard.
00152 

Generated on Thu Nov 20 04:28:52 2008 for HOOPLE Libraries by  doxygen 1.5.1