1 #ifndef _IPXE_PROFILE_H
2 #define _IPXE_PROFILE_H
10 FILE_LICENCE ( GPL2_OR_LATER );
12 #include <bits/profile.h>
13 #include <ipxe/tables.h>
22 * A data structure for storing profiling information
27 /** Start timestamp */
28 unsigned long started;
30 unsigned long stopped;
31 /** Number of samples */
33 /** Mean sample value (scaled) */
35 /** Mean sample value MSB
37 * This is the highest bit set in the raw (unscaled) value
38 * (i.e. one less than would be returned by flsl(raw_mean)).
40 unsigned int mean_msb;
41 /** Accumulated variance (scaled) */
42 unsigned long long accvar;
43 /** Accumulated variance MSB
45 * This is the highest bit set in the raw (unscaled) value
46 * (i.e. one less than would be returned by flsll(raw_accvar)).
48 unsigned int accvar_msb;
52 #define PROFILERS __table ( struct profiler, "profilers" )
54 /** Declare a profiler */
56 #define __profiler __table_entry ( PROFILERS, 01 )
61 extern unsigned long profile_excluded;
63 extern void profile_update ( struct profiler *profiler, unsigned long sample );
64 extern unsigned long profile_mean ( struct profiler *profiler );
65 extern unsigned long profile_variance ( struct profiler *profiler );
66 extern unsigned long profile_stddev ( struct profiler *profiler );
71 * @v profiler Profiler
72 * @ret started Start time
74 static inline __attribute__ (( always_inline )) unsigned long
75 profile_started ( struct profiler *profiler ) {
77 /* If profiling is active then return start time */
79 return ( profiler->started + profile_excluded );
88 * @v profiler Profiler
89 * @ret stopped Stop time
91 static inline __attribute__ (( always_inline )) unsigned long
92 profile_stopped ( struct profiler *profiler ) {
94 /* If profiling is active then return start time */
96 return ( profiler->stopped + profile_excluded );
105 * @v profiler Profiler
106 * @ret elapsed Elapsed time
108 static inline __attribute__ (( always_inline )) unsigned long
109 profile_elapsed ( struct profiler *profiler ) {
111 /* If profiling is active then return elapsed time */
113 return ( profile_stopped ( profiler ) -
114 profile_started ( profiler ) );
123 * @v profiler Profiler
124 * @v started Start timestamp
126 static inline __attribute__ (( always_inline )) void
127 profile_start_at ( struct profiler *profiler, unsigned long started ) {
129 /* If profiling is active then record start timestamp */
131 profiler->started = ( started - profile_excluded );
137 * @v profiler Profiler
138 * @v stopped Stop timestamp
140 static inline __attribute__ (( always_inline )) void
141 profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
143 /* If profiling is active then record end timestamp and update stats */
145 profiler->stopped = ( stopped - profile_excluded );
146 profile_update ( profiler, profile_elapsed ( profiler ) );
153 * @v profiler Profiler
155 static inline __attribute__ (( always_inline )) void
156 profile_start ( struct profiler *profiler ) {
158 /* If profiling is active then record start timestamp */
160 profile_start_at ( profiler, profile_timestamp() );
166 * @v profiler Profiler
168 static inline __attribute__ (( always_inline )) void
169 profile_stop ( struct profiler *profiler ) {
171 /* If profiling is active then record end timestamp and update stats */
173 profile_stop_at ( profiler, profile_timestamp() );
177 * Exclude time from other ongoing profiling results
179 * @v profiler Profiler
181 static inline __attribute__ (( always_inline )) void
182 profile_exclude ( struct profiler *profiler ) {
184 /* If profiling is active then update accumulated excluded time */
186 profile_excluded += profile_elapsed ( profiler );
189 #endif /* _IPXE_PROFILE_H */