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