2 * Sherlock Library -- Poor Man's Profiler
4 * (c) 2001 Martin Mares <mj@ucw.cz>
10 * #include "lib/profile.h"
17 * printf("%s\n", PROF_STRING(&cnt));
20 /* PROFILE_TOD: gettimeofday() profiler */
23 u32 start_sec, start_usec;
27 void prof_tod_init(struct prof_tod *);
28 void prof_tod_switch(struct prof_tod *, struct prof_tod *);
29 int prof_tod_format(char *, struct prof_tod *);
31 /* PROFILE_TSC: i386 TSC profiler */
40 void prof_tsc_init(struct prof_tsc *);
41 int prof_tsc_format(char *, struct prof_tsc *);
45 /* PROFILE_KTSC: Linux kernel TSC profiler */
50 u64 start_user, start_sys;
51 u64 ticks_user, ticks_sys;
54 void prof_ktsc_init(struct prof_ktsc *);
55 void prof_ktsc_switch(struct prof_ktsc *, struct prof_ktsc *);
56 int prof_ktsc_format(char *, struct prof_ktsc *);
60 /* Select the right profiler */
62 #if defined(PROFILE_TOD)
65 #define PROF_STR_SIZE 21
66 typedef struct prof_tod prof_t;
67 #define prof_init prof_tod_init
68 #define prof_switch prof_tod_switch
69 #define prof_format prof_tod_format
71 #elif defined(PROFILE_TSC)
74 #define PROFILER_INLINE
75 #define PROF_STR_SIZE 24
77 typedef struct prof_tsc prof_t;
78 #define prof_init prof_tsc_init
79 #define prof_format prof_tsc_format
81 #define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
83 static inline void prof_start(prof_t *c)
85 rdtscll(c->start_tsc);
88 static inline void prof_stop(prof_t *c)
96 static inline void prof_switch(prof_t *o, prof_t *n)
105 #elif defined(PROFILE_KTSC)
108 #define PROF_STR_SIZE 50
109 typedef struct prof_ktsc prof_t;
110 #define prof_init prof_ktsc_init
111 #define prof_switch prof_ktsc_switch
112 #define prof_format prof_ktsc_format
118 /* Stuff common for all profilers */
119 #ifndef PROFILER_INLINE
120 static inline void prof_start(prof_t *c) { prof_switch(NULL, c); }
121 static inline void prof_stop(prof_t *c) { prof_switch(c, NULL); }
123 #define PROF_STR(c) ({ static byte _x[PROF_STR_SIZE]; prof_format(_x, &(C)); _x })
127 /* Dummy profiler with no output */
128 typedef struct { } prof_t;
129 static inline void prof_init(prof_t *c UNUSED) { }
130 static inline void prof_start(prof_t *c UNUSED) { }
131 static inline void prof_stop(prof_t *c UNUSED) { }
132 static inline void prof_switch(prof_t *c UNUSED, prof_t *d UNUSED) { }
133 static inline void prof_format(char *b, prof_t *c UNUSED) { strcpy(b, "?"); }
134 #define PROF_STR_SIZE 2