2 * Sherlock Library -- Poor Man's Profiler
4 * (c) 2001 Martin Mares <mj@ucw.cz>
15 * printf("%s\n", PROF_STRING(&cnt));
18 /* Profiling method to use */
19 #define CONFIG_PROFILE_TOD /* gettimeofday() */
20 #undef CONFIG_PROFILE_TSC /* i386 TSC */
21 #undef CONFIG_PROFILE_KTSC /* kernel TSC profiler */
23 #ifdef CONFIG_PROFILE_TOD
24 #define CONFIG_PROFILE
25 #define PROF_STR_SIZE 21
28 u32 start_sec, start_usec;
34 #ifdef CONFIG_PROFILE_TSC
35 #define CONFIG_PROFILE
36 #define CONFIG_PROFILE_INLINE
37 #define PROF_STR_SIZE 24
44 #define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
46 static inline void prof_start(prof_t *c)
48 rdtscll(c->start_tsc);
51 static inline void prof_stop(prof_t *c)
59 static inline void prof_switch(prof_t *o, prof_t *n)
69 #ifdef CONFIG_PROFILE_KTSC
70 #define CONFIG_PROFILE
71 #define PROF_STR_SIZE 50
74 u64 start_user, start_sys;
75 u64 ticks_user, ticks_sys;
81 /* Stuff common for all profilers */
82 #ifndef CONFIG_PROFILE_INLINE
83 void prof_switch(prof_t *, prof_t *);
84 static inline void prof_start(prof_t *c) { prof_switch(NULL, c); }
85 static inline void prof_stop(prof_t *c) { prof_switch(c, NULL); }
87 int prof_format(char *, prof_t *);
88 void prof_init(prof_t *);
92 /* Dummy profiler with no output */
93 typedef struct { } prof_t;
94 static inline void prof_init(prof_t *c UNUSED) { }
95 static inline void prof_start(prof_t *c UNUSED) { }
96 static inline void prof_stop(prof_t *c UNUSED) { }
97 static inline void prof_switch(prof_t *c UNUSED, prof_t *d UNUSED) { }
98 static inline void prof_format(char *b, prof_t *c UNUSED) { strcpy(b, "?"); }
99 #define PROF_STR_SIZE 2