Add next_value and start_time

pull/17457/head
Muxi Yan 6 years ago
parent 5ebbba543c
commit ef7d45d2ab
  1. 8
      src/core/lib/gpr/sync_posix.cc
  2. 13
      src/core/lib/iomgr/exec_ctx.cc
  3. 6
      src/core/lib/iomgr/timer_manager.cc

@ -39,7 +39,8 @@ void (*g_grpc_debug_timer_manager_stats)(
int64_t abs_deadline_nsec_value, int64_t now1_sec_value, int64_t abs_deadline_nsec_value, int64_t now1_sec_value,
int64_t now1_nsec_value, int64_t now2_sec_value, int64_t now2_nsec_value, int64_t now1_nsec_value, int64_t now2_sec_value, int64_t now2_nsec_value,
int64_t add_result_sec_value, int64_t add_result_nsec_value, int64_t add_result_sec_value, int64_t add_result_nsec_value,
int64_t sub_result_sec_value, int64_t sub_result_nsec_value) = nullptr; int64_t sub_result_sec_value, int64_t sub_result_nsec_value,
int64_t next_value, int64_t start_time_sec, int64_t start_time_nsec) = nullptr;
int64_t g_timer_manager_init_count = 0; int64_t g_timer_manager_init_count = 0;
int64_t g_timer_manager_shutdown_count = 0; int64_t g_timer_manager_shutdown_count = 0;
int64_t g_fork_count = 0; int64_t g_fork_count = 0;
@ -58,6 +59,9 @@ int64_t g_add_result_sec_value = -1;
int64_t g_add_result_nsec_value = -1; int64_t g_add_result_nsec_value = -1;
int64_t g_sub_result_sec_value = -1; int64_t g_sub_result_sec_value = -1;
int64_t g_sub_result_nsec_value = -1; int64_t g_sub_result_nsec_value = -1;
int64_t g_next_value = -1;
int64_t g_start_time_sec = -1;
int64_t g_start_time_nsec = -1;
#endif // GRPC_DEBUG_TIMER_MANAGER #endif // GRPC_DEBUG_TIMER_MANAGER
#ifdef GPR_LOW_LEVEL_COUNTERS #ifdef GPR_LOW_LEVEL_COUNTERS
@ -212,7 +216,7 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
g_abs_deadline_nsec_value, g_now1_sec_value, g_now1_nsec_value, g_abs_deadline_nsec_value, g_now1_sec_value, g_now1_nsec_value,
g_now2_sec_value, g_now2_nsec_value, g_add_result_sec_value, g_now2_sec_value, g_now2_nsec_value, g_add_result_sec_value,
g_add_result_nsec_value, g_sub_result_sec_value, g_add_result_nsec_value, g_sub_result_sec_value,
g_sub_result_nsec_value); g_sub_result_nsec_value, g_next_value, g_start_time_sec, g_start_time_nsec);
} }
} }
#endif #endif

@ -53,6 +53,13 @@ static void exec_ctx_sched(grpc_closure* closure, grpc_error* error) {
static gpr_timespec g_start_time; static gpr_timespec g_start_time;
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
#ifdef GRPC_DEBUG_TIMER_MANAGER
extern int64_t g_start_time_sec;
extern int64_t g_start_time_nsec;
#endif // GRPC_DEBUG_TIMER_MANAGER
static grpc_millis timespec_to_millis_round_down(gpr_timespec ts) { static grpc_millis timespec_to_millis_round_down(gpr_timespec ts) {
ts = gpr_time_sub(ts, g_start_time); ts = gpr_time_sub(ts, g_start_time);
double x = GPR_MS_PER_SEC * static_cast<double>(ts.tv_sec) + double x = GPR_MS_PER_SEC * static_cast<double>(ts.tv_sec) +
@ -117,6 +124,12 @@ void ExecCtx::TestOnlyGlobalInit(gpr_timespec new_val) {
void ExecCtx::GlobalInit(void) { void ExecCtx::GlobalInit(void) {
g_start_time = gpr_now(GPR_CLOCK_MONOTONIC); g_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
#ifdef GRPC_DEBUG_TIMER_MANAGER
g_start_time_sec = g_start_time.tv_sec;
g_start_time_nsec = g_start_time.tv_nsec;
#endif
gpr_tls_init(&exec_ctx_); gpr_tls_init(&exec_ctx_);
} }

@ -67,6 +67,7 @@ static void timer_thread(void* completed_thread_ptr);
extern int64_t g_timer_manager_init_count; extern int64_t g_timer_manager_init_count;
extern int64_t g_timer_manager_shutdown_count; extern int64_t g_timer_manager_shutdown_count;
extern int64_t g_fork_count; extern int64_t g_fork_count;
extern int64_t g_next_value;
#endif // GRPC_DEBUG_TIMER_MANAGER #endif // GRPC_DEBUG_TIMER_MANAGER
static void gc_completed_threads(void) { static void gc_completed_threads(void) {
@ -193,6 +194,11 @@ static bool wait_until(grpc_millis next) {
gpr_log(GPR_INFO, "sleep until kicked"); gpr_log(GPR_INFO, "sleep until kicked");
} }
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
#ifdef GRPC_DEBUG_TIMER_MANAGER
g_next_value = next;
#endif
gpr_cv_wait(&g_cv_wait, &g_mu, gpr_cv_wait(&g_cv_wait, &g_mu,
grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC)); grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));

Loading…
Cancel
Save