source: golgotha/src/i4/time/profile_stack.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: 1.8 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 I4_PROFILE_STACK_HH
10#define I4_PROFILE_STACK_HH
11
12#include "time/profile.hh"
13#include "time/time.hh"
14
15struct i4_profile_stack_item
16{
17  w64 start_clock;
18  i4_profile_class *item; 
19};
20
21enum { I4_MAX_PROFILE_STACK_DEPTH=1000 };
22
23extern int i4_profile_stack_top;
24
25struct i4_profile_stack_struct
26{
27  static i4_profile_stack_item stack[I4_MAX_PROFILE_STACK_DEPTH];
28
29  void overflow();
30  void underflow();
31
32  int top() { return i4_profile_stack_top; }
33
34  void push(i4_profile_class *item, w64 current_clock)
35  {
36    if (top()==I4_MAX_PROFILE_STACK_DEPTH)
37      overflow();
38
39    stack[top()].item=item;
40    stack[top()].start_clock=current_clock;
41    i4_profile_stack_top++;
42  }
43
44  i4_profile_stack_item *pop()
45  {
46     if (!top())
47       underflow();
48    i4_profile_stack_top--;
49    return stack+top();
50  }
51
52  i4_profile_stack_item *get_top()
53  {
54    if (top())
55      return stack+top()-1;
56    else return 0;
57  }
58
59  // this adds any time remaining on the stack into the profile classes
60  // called before reports are formed
61  void flush_stack()
62  {
63    i4_profile_stack_item *t=get_top();
64    if (t)
65    {
66      w64 current_clock=i4_get_system_clock();
67      t->item->total_time+=current_clock-t->start_clock;
68      t->start_clock=current_clock;
69    }
70     
71  }
72
73 
74 
75
76};
77
78
79#endif
Note: See TracBrowser for help on using the repository browser.