1 #ifndef _GPXE_PROFILE_H
2 #define _GPXE_PROFILE_H
10 FILE_LICENCE ( GPL2_OR_LATER
);
15 * A data structure for storing profiling information
18 /** Timestamp (in CPU-specific "ticks") */
20 /** Registers returned by rdtsc.
22 * This part should really be architecture-specific code.
31 * Static per-object profiler, for use with simple_profile()
33 static union profiler simple_profiler
;
38 * @v profiler Profiler data structure
39 * @ret delta Elapsed ticks since last call to profile().
41 * Call profile() both before and after the code you wish to measure.
42 * The "after" call will return the measurement. For example:
46 * profile ( &profiler );
47 * ... do something here ...
48 * printf ( "It took %ld ticks to execute\n", profile ( &profiler ) );
52 static inline __attribute__ (( always_inline
)) unsigned long
53 profile ( union profiler
*profiler
) {
54 uint64_t last_timestamp
= profiler
->timestamp
;
56 __asm__
__volatile__ ( "rdtsc" :
57 "=a" ( profiler
->rdtsc
.eax
),
58 "=d" ( profiler
->rdtsc
.edx
) );
59 return ( profiler
->timestamp
- last_timestamp
);
65 * @ret delta Elapsed ticks since last call to profile().
67 * When you only need one profiler, you can avoid the hassle of
68 * creating your own @c profiler data structure by using
69 * simple_profile() instead.
71 * simple_profile() is equivalent to profile(&simple_profiler), where
72 * @c simple_profiler is a @c profiler data structure that is static
73 * to each object which includes @c profile.h.
75 static inline __attribute__ (( always_inline
)) unsigned long
76 simple_profile ( void ) {
77 return profile ( &simple_profiler
);
80 #endif /* _GPXE_PROFILE_H */