1 /*
2  * Copyright 2005, 2016. Rene Rivera
3  * Distributed under the Boost Software License, Version 1.0.
4  * (See accompanying file LICENSE_1_0.txt or copy at
5  * http://www.boost.org/LICENSE_1_0.txt)
6  */
7 
8 #ifndef BJAM_DEBUG_H
9 #define BJAM_DEBUG_H
10 
11 #include "config.h"
12 #include "constants.h"
13 #include "object.h"
14 
15 
16 typedef struct profile_info
17 {
18     /* name of rule being called */
19     OBJECT * name;
20     /* cumulative time spent in rule, in seconds */
21     double cumulative;
22     /* time spent in rule proper, in seconds */
23     double net;
24     /* number of time rule was entered */
25     unsigned long num_entries;
26     /* number of the times this function is present in stack */
27     unsigned long stack_count;
28     /* memory allocated by the call, in KiB */
29     double memory;
30 } profile_info;
31 
32 typedef struct profile_frame
33 {
34     /* permanent storage where data accumulates */
35     profile_info * info;
36     /* overhead for profiling in this call */
37     double overhead;
38     /* time of last entry to rule */
39     double entry_time;
40     /* stack frame of caller */
41     struct profile_frame * caller;
42     /* time spent in subrules */
43     double subrules;
44 } profile_frame;
45 
46 profile_frame * profile_init( OBJECT * rulename, profile_frame * );
47 void profile_enter( OBJECT * rulename, profile_frame * );
48 void profile_memory( long mem );
49 void profile_exit( profile_frame * );
50 void profile_dump();
51 double profile_clock();
52 
53 #define PROFILE_ENTER( scope ) profile_frame PROF_ ## scope, *PROF_ ## scope ## _p = profile_init( constant_ ## scope, &PROF_ ## scope )
54 #define PROFILE_EXIT( scope ) profile_exit( PROF_ ## scope ## _p )
55 
56 OBJECT * profile_make_local( char const * );
57 #define PROFILE_ENTER_LOCAL( scope ) \
58     static OBJECT * constant_LOCAL_##scope = 0; \
59     if (DEBUG_PROFILE && !constant_LOCAL_##scope) constant_LOCAL_##scope = profile_make_local( #scope ); \
60     PROFILE_ENTER( LOCAL_##scope )
61 #define PROFILE_EXIT_LOCAL( scope ) PROFILE_EXIT( LOCAL_##scope )
62 
63 #endif
64