iPXE
profile.h
Go to the documentation of this file.
1 #ifndef _IPXE_PROFILE_H
2 #define _IPXE_PROFILE_H
3 
4 /** @file
5  *
6  * Profiling
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <bits/profile.h>
13 #include <ipxe/tables.h>
14 
15 #ifndef PROFILING
16 #ifdef NDEBUG
17 #define PROFILING 0
18 #else
19 #define PROFILING 1
20 #endif
21 #endif
22 
23 /**
24  * A data structure for storing profiling information
25  */
26 struct profiler {
27  /** Name */
28  const char *name;
29  /** Start timestamp */
30  unsigned long started;
31  /** Stop timestamp */
32  unsigned long stopped;
33  /** Number of samples */
34  unsigned int count;
35  /** Mean sample value (scaled) */
36  unsigned long mean;
37  /** Mean sample value MSB
38  *
39  * This is the highest bit set in the raw (unscaled) value
40  * (i.e. one less than would be returned by flsl(raw_mean)).
41  */
42  unsigned int mean_msb;
43  /** Accumulated variance (scaled) */
44  unsigned long long accvar;
45  /** Accumulated variance MSB
46  *
47  * This is the highest bit set in the raw (unscaled) value
48  * (i.e. one less than would be returned by flsll(raw_accvar)).
49  */
50  unsigned int accvar_msb;
51 };
52 
53 /** Profiler table */
54 #define PROFILERS __table ( struct profiler, "profilers" )
55 
56 /** Declare a profiler */
57 #if PROFILING
58 #define __profiler __table_entry ( PROFILERS, 01 )
59 #else
60 #define __profiler
61 #endif
62 
63 unsigned long profile_timestamp ( void );
64 
65 extern unsigned long profile_excluded;
66 
67 extern void profile_update ( struct profiler *profiler, unsigned long sample );
68 extern unsigned long profile_mean ( struct profiler *profiler );
69 extern unsigned long profile_variance ( struct profiler *profiler );
70 extern unsigned long profile_stddev ( struct profiler *profiler );
71 
72 /**
73  * Get start time
74  *
75  * @v profiler Profiler
76  * @ret started Start time
77  */
78 static inline __attribute__ (( always_inline )) unsigned long
80 
81  /* If profiling is active then return start time */
82  if ( PROFILING ) {
83  return ( profiler->started + profile_excluded );
84  } else {
85  return 0;
86  }
87 }
88 
89 /**
90  * Get stop time
91  *
92  * @v profiler Profiler
93  * @ret stopped Stop time
94  */
95 static inline __attribute__ (( always_inline )) unsigned long
97 
98  /* If profiling is active then return start time */
99  if ( PROFILING ) {
100  return ( profiler->stopped + profile_excluded );
101  } else {
102  return 0;
103  }
104 }
105 
106 /**
107  * Get elapsed time
108  *
109  * @v profiler Profiler
110  * @ret elapsed Elapsed time
111  */
112 static inline __attribute__ (( always_inline )) unsigned long
114 
115  /* If profiling is active then return elapsed time */
116  if ( PROFILING ) {
117  return ( profile_stopped ( profiler ) -
119  } else {
120  return 0;
121  }
122 }
123 
124 /**
125  * Start profiling
126  *
127  * @v profiler Profiler
128  * @v started Start timestamp
129  */
130 static inline __attribute__ (( always_inline )) void
131 profile_start_at ( struct profiler *profiler, unsigned long started ) {
132 
133  /* If profiling is active then record start timestamp */
134  if ( PROFILING )
136 }
137 
138 /**
139  * Stop profiling
140  *
141  * @v profiler Profiler
142  * @v stopped Stop timestamp
143  */
144 static inline __attribute__ (( always_inline )) void
145 profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
146 
147  /* If profiling is active then record end timestamp and update stats */
148  if ( PROFILING ) {
149  profiler->stopped = ( stopped - profile_excluded );
151  }
152 }
153 
154 /**
155  * Start profiling
156  *
157  * @v profiler Profiler
158  */
159 static inline __attribute__ (( always_inline )) void
161 
162  /* If profiling is active then record start timestamp */
163  if ( PROFILING )
165 }
166 
167 /**
168  * Stop profiling
169  *
170  * @v profiler Profiler
171  */
172 static inline __attribute__ (( always_inline )) void
174 
175  /* If profiling is active then record end timestamp and update stats */
176  if ( PROFILING )
178 }
179 
180 /**
181  * Exclude time from other ongoing profiling results
182  *
183  * @v profiler Profiler
184  */
185 static inline __attribute__ (( always_inline )) void
187 
188  /* If profiling is active then update accumulated excluded time */
189  if ( PROFILING )
191 }
192 
193 /**
194  * Record profiling sample in custom units
195  *
196  * @v profiler Profiler
197  * @v sample Profiling sample
198  */
199 static inline __attribute__ (( always_inline )) void
200 profile_custom ( struct profiler *profiler, unsigned long sample ) {
201 
202  /* If profiling is active then update stats */
203  if ( PROFILING )
204  profile_update ( profiler, sample );
205 }
206 
207 #endif /* _IPXE_PROFILE_H */
unsigned long profile_variance(struct profiler *profiler)
Get sample variance.
Definition: profile.c:255
unsigned long long accvar
Accumulated variance (scaled)
Definition: profile.h:44
static unsigned long profile_started(struct profiler *profiler)
Get start time.
Definition: profile.h:79
static void profile_custom(struct profiler *profiler, unsigned long sample)
Record profiling sample in custom units.
Definition: profile.h:200
Profiling.
A data structure for storing profiling information.
Definition: profile.h:26
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
static __attribute__((always_inline)) unsigned long profile_timestamp(void)
Get profiling timestamp.
Definition: profile.h:19
static void profile_stop_at(struct profiler *profiler, unsigned long stopped)
Stop profiling.
Definition: profile.h:145
static int started
"startup() has been called" flag
Definition: init.c:37
const char * name
Name.
Definition: profile.h:28
unsigned int mean_msb
Mean sample value MSB.
Definition: profile.h:42
unsigned int count
Number of samples.
Definition: profile.h:34
#define PROFILING
Definition: profile.h:19
static unsigned long profile_elapsed(struct profiler *profiler)
Get elapsed time.
Definition: profile.h:113
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
unsigned long profile_excluded
Accumulated time excluded from profiling.
Definition: profile.c:49
static void profile_start_at(struct profiler *profiler, unsigned long started)
Start profiling.
Definition: profile.h:131
static unsigned long profile_stopped(struct profiler *profiler)
Get stop time.
Definition: profile.h:96
unsigned long profile_timestamp(void)
Linker tables.
unsigned int accvar_msb
Accumulated variance MSB.
Definition: profile.h:50
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:186
unsigned long mean
Mean sample value (scaled)
Definition: profile.h:36
unsigned long profile_stddev(struct profiler *profiler)
Get sample standard deviation.
Definition: profile.c:275
unsigned long profile_mean(struct profiler *profiler)
Get mean sample value.
Definition: profile.c:241
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned long started
Start timestamp.
Definition: profile.h:30
void profile_update(struct profiler *profiler, unsigned long sample)
Update profiler with a new sample.
Definition: profile.c:110
unsigned long stopped
Stop timestamp.
Definition: profile.h:32