|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|