feisty meow concerns codebase  2.140
callstack_tracker.h
Go to the documentation of this file.
1 #ifndef CALLSTACK_TRACKER_CLASS
2 #define CALLSTACK_TRACKER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : callstack_tracker *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include "definitions.h"
19 
20 #ifdef ENABLE_CALLSTACK_TRACKING
21 
22 #include "build_configuration.h"
23 #include "root_object.h"
24 
25 namespace application {
26 
27 // forward.
28 class callstack_records;
29 class callstack_tracker;
30 
32 
33 callstack_tracker BASIS_EXTERN &program_wide_stack_trace();
35 
37 
39 
46 class callstack_tracker
47 {
48 public:
49  callstack_tracker();
50  virtual ~callstack_tracker();
51 
52  DEFINE_CLASS_NAME("callstack_tracker");
53 
54  bool push_frame(const char *class_name, const char *func, const char *file,
55  int line);
57 
64  bool pop_frame();
66 
67  bool update_line(int line);
69 
72  char *full_trace() const;
74 
76  int full_trace_size() const;
78 
79  int depth() const { return _depth; }
81 
82  double frames_in() const { return _frames_in; }
84 
85  double frames_out() const { return _frames_out; }
87 
88  double highest() const { return _highest; }
90 
91 private:
92  callstack_records *_bt;
93  int _depth;
94  double _frames_in;
95  double _frames_out;
96  double _highest;
97  bool _unusable;
98 };
99 
101 
103 
111 {
112 public:
113  // these are not encapsulated, but be careful with the contents.
114  bool _frame_involved;
115  char *_class, *_func, *_file;
116  int _line;
117 
118  frame_tracking_instance(const char *class_name = "", const char *func = "",
119  const char *file = "", int line = 0, bool add_frame = false);
121 
127 
130 
131  frame_tracking_instance &operator =(const frame_tracking_instance &to_copy);
132 
133  void assign(const char *class_name, const char *func, const char *file,
134  int line);
136 
137  void clean();
139 };
140 
143 
144 #else // ENABLE_CALLSTACK_TRACKING
145  // bogus replacements for most commonly used callstack tracking support.
146  #define frame_tracking_instance
147  #define __trail_of_function(p1, p2, p3, p4, p5) if (func) {}
148  // the above actually trades on the name of the object we'd normally
149  // define. it must match the object name in the FUNCDEF macro.
150  #define update_current_stack_frame_line_number(line)
151 #endif // ENABLE_CALLSTACK_TRACKING
152 
153 } //namespace.
154 
155 #endif // outer guard.
156 
Contains definitions that control how libraries and programs are built.
#define update_current_stack_frame_line_number(line)
#define frame_tracking_instance
Constants and objects used throughout HOOPLE.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
Implements an application lock to ensure only one is running at once.