Merge branch 'fast-timer' of github.com:ctiller/grpc into fast-timer

pull/1460/head
Craig Tiller 10 years ago
commit c3c9318579
  1. 17
      src/core/profiling/basic_timers.c
  2. 9
      src/core/profiling/timers.h
  3. 12
      src/core/profiling/timers_preciseclock.h

@ -45,11 +45,7 @@
#include <grpc/support/thd.h> #include <grpc/support/thd.h>
#include <stdio.h> #include <stdio.h>
typedef enum { typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type;
BEGIN = '{',
END = '}',
MARK = '.'
} marker_type;
typedef struct grpc_timer_entry { typedef struct grpc_timer_entry {
grpc_precise_clock tm; grpc_precise_clock tm;
@ -69,7 +65,9 @@ static void log_report() {
int i; int i;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
grpc_timer_entry* entry = &(log[i]); grpc_timer_entry* entry = &(log[i]);
printf("GRPC_LAT_PROF " GRPC_PRECISE_CLOCK_FORMAT " %p %c %d %p %s %d\n", GRPC_PRECISE_CLOCK_PRINTF_ARGS(&entry->tm), (void*)(gpr_intptr)gpr_thd_currentid(), entry->type, entry->tag, printf("GRPC_LAT_PROF " GRPC_PRECISE_CLOCK_FORMAT " %p %c %d %p %s %d\n",
GRPC_PRECISE_CLOCK_PRINTF_ARGS(&entry->tm),
(void*)(gpr_intptr)gpr_thd_currentid(), entry->type, entry->tag,
entry->id, entry->file, entry->line); entry->id, entry->file, entry->line);
} }
@ -116,12 +114,9 @@ void grpc_timer_end(int tag, void* id, const char *file, int line) {
} }
/* Basic profiler specific API functions. */ /* Basic profiler specific API functions. */
void grpc_timers_global_init(void) { void grpc_timers_global_init(void) {}
}
void grpc_timers_global_destroy(void) {
}
void grpc_timers_global_destroy(void) {}
#else /* !GRPC_BASIC_PROFILER */ #else /* !GRPC_BASIC_PROFILER */
void grpc_timers_global_init(void) {} void grpc_timers_global_init(void) {}

@ -74,13 +74,16 @@ enum grpc_profiling_tags {
#if !(defined(GRPC_STAP_PROFILER) + defined(GRPC_BASIC_PROFILER)) #if !(defined(GRPC_STAP_PROFILER) + defined(GRPC_BASIC_PROFILER))
/* No profiling. No-op all the things. */ /* No profiling. No-op all the things. */
#define GRPC_TIMER_MARK(tag, id) \ #define GRPC_TIMER_MARK(tag, id) \
do {} while(0) do { \
} while (0)
#define GRPC_TIMER_BEGIN(tag, id) \ #define GRPC_TIMER_BEGIN(tag, id) \
do {} while(0) do { \
} while (0)
#define GRPC_TIMER_END(tag, id) \ #define GRPC_TIMER_END(tag, id) \
do {} while(0) do { \
} while (0)
#else /* at least one profiler requested... */ #else /* at least one profiler requested... */
/* ... hopefully only one. */ /* ... hopefully only one. */

@ -61,9 +61,11 @@ static void grpc_precise_clock_init() {
time_t start = time(NULL); time_t start = time(NULL);
grpc_precise_clock start_time; grpc_precise_clock start_time;
grpc_precise_clock end_time; grpc_precise_clock end_time;
while (time(NULL) == start); while (time(NULL) == start)
;
grpc_precise_clock_now(&start_time); grpc_precise_clock_now(&start_time);
while (time(NULL) == start+1); while (time(NULL) == start + 1)
;
grpc_precise_clock_now(&end_time); grpc_precise_clock_now(&end_time);
cycles_per_second = end_time - start_time; cycles_per_second = end_time - start_time;
} }
@ -72,7 +74,8 @@ static double grpc_precise_clock_scaling_factor() {
return 1e6 / cycles_per_second; return 1e6 / cycles_per_second;
} }
#define GRPC_PRECISE_CLOCK_FORMAT "%f" #define GRPC_PRECISE_CLOCK_FORMAT "%f"
#define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) (*(clk) * grpc_precise_clock_scaling_factor()) #define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) \
(*(clk)*grpc_precise_clock_scaling_factor())
#else #else
typedef struct grpc_precise_clock grpc_precise_clock; typedef struct grpc_precise_clock grpc_precise_clock;
struct grpc_precise_clock { struct grpc_precise_clock {
@ -82,7 +85,8 @@ static void grpc_precise_clock_now(grpc_precise_clock* clk) {
clk->clock = gpr_now(); clk->clock = gpr_now();
} }
#define GRPC_PRECISE_CLOCK_FORMAT "%ld.%09d" #define GRPC_PRECISE_CLOCK_FORMAT "%ld.%09d"
#define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) (clk)->clock.tv_sec, (clk)->clock.tv_nsec #define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) \
(clk)->clock.tv_sec, (clk)->clock.tv_nsec
static void grpc_precise_clock_print(const grpc_precise_clock* clk, FILE* fp) { static void grpc_precise_clock_print(const grpc_precise_clock* clk, FILE* fp) {
fprintf(fp, "%ld.%09d", clk->clock.tv_sec, clk->clock.tv_nsec); fprintf(fp, "%ld.%09d", clk->clock.tv_sec, clk->clock.tv_nsec);
} }

Loading…
Cancel
Save