source: golgotha/src/i4/time/profile.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef PROFILE_HH
10#define PROFILE_HH
11
12#include "error/error.hh"
13
14// This class is used for code profiling, it properly hanldes recursion.
15
16// Example Ussage :
17//
18// i4_profiler_class ph_file_open("File open");
19// i4_profiler_class ph_file_close("File close");
20//
21// void some_function()
22// {
23//   ph_file_open.start();
24//   open();
25//   ph_file_open.stop();
26//
27//   ph_file_close.start();
28//   close();
29//   ph_file_close.stop();
30// }
31//
32// void main_function()
33// {
34//   some_function();
35//   //other stuff
36//   some_function();
37//   i4_profile_report()
38// }
39
40#include "arch.hh"
41
42#define I4_PROFILING 1
43
44#ifdef I4_PROFILING
45
46
47
48extern int i4_profile_on, i4_profile_stack_top;
49
50
51class i4_profile_class
52{
53public:
54  static i4_profile_class *list; 
55  i4_profile_class *next;           
56
57  int active;
58  char *name;
59  w64 total_time;
60
61  i4_profile_class(char *debug_name);
62
63  void called_start();     // not inlined to save program space
64  void called_stop();
65
66  void start()
67  {
68    // this is inlined so when profiling is off, there is no call overhead
69    if (active && i4_profile_on)
70      called_start();
71 }
72
73  void stop()
74  {
75    if (active && i4_profile_stack_top)
76      called_stop();
77  }
78
79  ~i4_profile_class();
80};
81
82
83
84// clear out any profile timing information we have so far
85void i4_profile_clear();               
86
87void i4_profile_report_start();  // marks the start of a profile
88
89// print a report to about timing since the last clear or program start
90void i4_profile_report(char *filename);
91
92#else
93
94void i4_profile_clear() { ; }
95void i4_profile_report_start() { ; }
96void i4_profile_report(char *filename) { ; }
97
98class i4_profile_class
99{
100public:
101  i4_profile_class(char *debug_name) {}  // make these inline so they go away
102  void start()                       {}
103  void stop()                        {}
104};
105#endif
106
107
108
109#endif
110
111
Note: See TracBrowser for help on using the repository browser.