Introduce multiple clocks to GPR

pull/2289/head
Craig Tiller 10 years ago
parent ef558b321f
commit f3756c1e0d
  1. 16
      include/grpc/support/time.h
  2. 6
      src/core/channel/census_filter.c
  3. 6
      src/core/channel/client_setup.c
  4. 12
      src/core/iomgr/iomgr.c
  5. 2
      src/core/iomgr/pollset_posix.c
  6. 2
      src/core/iomgr/pollset_windows.c
  7. 2
      src/core/iomgr/tcp_client_posix.c
  8. 2
      src/core/iomgr/tcp_client_windows.c
  9. 2
      src/core/profiling/timers_preciseclock.h
  10. 10
      src/core/security/credentials.c
  11. 2
      src/core/security/google_default_credentials.c
  12. 2
      src/core/security/json_token.c
  13. 4
      src/core/statistics/census_rpc_stats.c
  14. 6
      src/core/statistics/census_tracing.c
  15. 4
      src/core/statistics/window_stats.h
  16. 2
      src/core/support/cancellable.c
  17. 2
      src/core/support/log_linux.c
  18. 2
      src/core/support/log_posix.c
  19. 2
      src/core/support/log_win32.c
  20. 2
      src/core/support/sync_win32.c
  21. 47
      src/core/support/time_posix.c
  22. 2
      src/core/support/time_win32.c
  23. 2
      src/core/surface/call.c
  24. 2
      src/core/surface/completion_queue.c
  25. 2
      src/core/surface/init.c
  26. 2
      src/core/transport/chttp2/parsing.c
  27. 2
      src/core/transport/chttp2/stream_encoder.c
  28. 2
      src/core/transport/metadata.c
  29. 2
      src/csharp/ext/grpc_csharp_ext.c
  30. 2
      src/php/ext/grpc/timeval.c
  31. 2
      src/ruby/ext/grpc/rb_completion_queue.c
  32. 2
      test/core/end2end/cq_verifier.c
  33. 2
      test/core/fling/client.c
  34. 2
      test/core/fling/server.c
  35. 2
      test/core/httpcli/httpcli_test.c
  36. 2
      test/core/iomgr/alarm_list_test.c
  37. 4
      test/core/iomgr/alarm_test.c
  38. 6
      test/core/iomgr/endpoint_tests.c
  39. 6
      test/core/iomgr/tcp_client_posix_test.c
  40. 2
      test/core/iomgr/tcp_server_posix_test.c
  41. 2
      test/core/network_benchmarks/low_level_ping_pong.c
  42. 4
      test/core/statistics/census_log_tests.c
  43. 2
      test/core/statistics/multiple_writers_circular_buffer_test.c
  44. 2
      test/core/statistics/multiple_writers_test.c
  45. 2
      test/core/statistics/performance_test.c
  46. 2
      test/core/statistics/quick_test.c
  47. 2
      test/core/statistics/small_log_test.c
  48. 6
      test/core/statistics/window_stats_test.c
  49. 26
      test/core/support/cancellable_test.c
  50. 12
      test/core/support/sync_test.c
  51. 2
      test/core/surface/completion_queue_test.c
  52. 4
      test/core/util/test_config.h

@ -62,8 +62,20 @@ extern const gpr_timespec gpr_inf_past; /* The far past. */
#define GPR_NS_PER_US 1000
#define GPR_US_PER_MS 1000
/* Return the current time measured from the system's default epoch. */
gpr_timespec gpr_now(void);
/* The clocks we support. */
typedef enum {
/* Monotonic clock. Epoch undefined. Always moves forwards. */
GPR_CLOCK_MONOTONIC = 0,
/* Realtime clock. May jump forwards or backwards. Settable by
the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */
GPR_CLOCK_REALTIME
} gpr_clock_type;
/* initialize time subsystem */
void gpr_time_init(void);
/* Return the current time measured from the given clocks epoch. */
gpr_timespec gpr_now(gpr_clock_type clock);
/* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
respectively. */

@ -149,7 +149,7 @@ static void client_init_call_elem(grpc_call_element* elem,
call_data* d = elem->call_data;
GPR_ASSERT(d != NULL);
init_rpc_stats(&d->stats);
d->start_ts = gpr_now();
d->start_ts = gpr_now(GPR_CLOCK_REALTIME);
d->op_id = census_tracing_start_op();
if (initial_op) client_mutate_op(elem, initial_op);
}
@ -167,7 +167,7 @@ static void server_init_call_elem(grpc_call_element* elem,
call_data* d = elem->call_data;
GPR_ASSERT(d != NULL);
init_rpc_stats(&d->stats);
d->start_ts = gpr_now();
d->start_ts = gpr_now(GPR_CLOCK_REALTIME);
d->op_id = census_tracing_start_op();
if (initial_op) server_mutate_op(elem, initial_op);
}
@ -176,7 +176,7 @@ static void server_destroy_call_elem(grpc_call_element* elem) {
call_data* d = elem->call_data;
GPR_ASSERT(d != NULL);
d->stats.elapsed_time_ms =
gpr_timespec_to_micros(gpr_time_sub(gpr_now(), d->start_ts));
gpr_timespec_to_micros(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), d->start_ts));
census_record_rpc_server_stats(d->op_id, &d->stats);
census_tracing_end_op(d->op_id);
}

@ -94,7 +94,7 @@ static void setup_initiate(grpc_transport_setup *sp) {
int in_alarm = 0;
r->setup = s;
r->deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(60));
r->deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(60));
gpr_mu_lock(&s->mu);
GPR_ASSERT(s->refs > 0);
@ -221,7 +221,7 @@ void grpc_client_setup_create_and_attach(
int grpc_client_setup_request_should_continue(grpc_client_setup_request *r,
const char *reason) {
int result;
if (gpr_time_cmp(gpr_now(), r->deadline) > 0) {
if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), r->deadline) > 0) {
result = 0;
} else {
gpr_mu_lock(&r->setup->mu);
@ -275,7 +275,7 @@ void grpc_client_setup_request_finish(grpc_client_setup_request *r,
/* TODO(klempner): Replace these values with further consideration. 2x is
probably too aggressive of a backoff. */
gpr_timespec max_backoff = gpr_time_from_minutes(2);
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec deadline = gpr_time_add(s->current_backoff_interval, now);
GPR_ASSERT(!s->in_alarm);
s->in_alarm = 1;

@ -59,7 +59,7 @@ static void background_callback_executor(void *ignored) {
while (!g_shutdown) {
gpr_timespec deadline = gpr_inf_future;
gpr_timespec short_deadline =
gpr_time_add(gpr_now(), gpr_time_from_millis(100));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100));
if (g_cbs_head) {
grpc_iomgr_closure *closure = g_cbs_head;
g_cbs_head = closure->next;
@ -67,7 +67,7 @@ static void background_callback_executor(void *ignored) {
gpr_mu_unlock(&g_mu);
closure->cb(closure->cb_arg, closure->success);
gpr_mu_lock(&g_mu);
} else if (grpc_alarm_check(&g_mu, gpr_now(), &deadline)) {
} else if (grpc_alarm_check(&g_mu, gpr_now(GPR_CLOCK_REALTIME), &deadline)) {
} else {
gpr_mu_unlock(&g_mu);
gpr_sleep_until(gpr_time_min(short_deadline, deadline));
@ -89,7 +89,7 @@ void grpc_iomgr_init(void) {
gpr_thd_id id;
gpr_mu_init(&g_mu);
gpr_cv_init(&g_rcv);
grpc_alarm_list_init(gpr_now());
grpc_alarm_list_init(gpr_now(GPR_CLOCK_REALTIME));
g_root_object.next = g_root_object.prev = &g_root_object;
g_root_object.name = "root";
grpc_iomgr_platform_init();
@ -110,7 +110,7 @@ void grpc_iomgr_shutdown(void) {
grpc_iomgr_object *obj;
grpc_iomgr_closure *closure;
gpr_timespec shutdown_deadline =
gpr_time_add(gpr_now(), gpr_time_from_seconds(10));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10));
gpr_mu_lock(&g_mu);
g_shutdown = 1;
@ -145,9 +145,9 @@ void grpc_iomgr_shutdown(void) {
if (g_root_object.next != &g_root_object) {
int timeout = 0;
gpr_timespec short_deadline =
gpr_time_add(gpr_now(), gpr_time_from_millis(100));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100));
while (gpr_cv_wait(&g_rcv, &g_mu, short_deadline) && g_cbs_head == NULL) {
if (gpr_time_cmp(gpr_now(), shutdown_deadline) > 0) {
if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) {
timeout = 1;
break;
}

@ -122,7 +122,7 @@ static void finish_shutdown(grpc_pollset *pollset) {
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
/* pollset->mu already held */
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
if (gpr_time_cmp(now, deadline) > 0) {
return 0;
}

@ -70,7 +70,7 @@ void grpc_pollset_destroy(grpc_pollset *pollset) {
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
gpr_timespec now;
now = gpr_now();
now = gpr_now(GPR_CLOCK_REALTIME);
if (gpr_time_cmp(now, deadline) > 0) {
return 0 /* GPR_FALSE */;
}

@ -246,7 +246,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep),
ac->write_closure.cb_arg = ac;
gpr_mu_lock(&ac->mu);
grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now());
grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now(GPR_CLOCK_REALTIME));
grpc_fd_notify_on_write(ac->fd, &ac->write_closure);
gpr_mu_unlock(&ac->mu);

@ -215,7 +215,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *tcp),
ac->refs = 2;
ac->aborted = 0;
grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now());
grpc_alarm_init(&ac->alarm, deadline, on_alarm, ac, gpr_now(GPR_CLOCK_REALTIME));
socket->write_info.outstanding = 1;
grpc_socket_notify_on_write(socket, on_connect, ac);
return;

@ -82,7 +82,7 @@ struct grpc_precise_clock {
gpr_timespec clock;
};
static void grpc_precise_clock_now(grpc_precise_clock* clk) {
clk->clock = gpr_now();
clk->clock = gpr_now(GPR_CLOCK_REALTIME);
}
#define GRPC_PRECISE_CLOCK_FORMAT "%ld.%09d"
#define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) \

@ -384,7 +384,7 @@ static void jwt_get_request_metadata(grpc_credentials *creds,
if (c->cached.service_url != NULL &&
strcmp(c->cached.service_url, service_url) == 0 &&
c->cached.jwt_md != NULL &&
(gpr_time_cmp(gpr_time_sub(c->cached.jwt_expiration, gpr_now()),
(gpr_time_cmp(gpr_time_sub(c->cached.jwt_expiration, gpr_now(GPR_CLOCK_REALTIME)),
refresh_threshold) > 0)) {
jwt_md = grpc_credentials_md_store_ref(c->cached.jwt_md);
}
@ -401,7 +401,7 @@ static void jwt_get_request_metadata(grpc_credentials *creds,
char *md_value;
gpr_asprintf(&md_value, "Bearer %s", jwt);
gpr_free(jwt);
c->cached.jwt_expiration = gpr_time_add(gpr_now(), c->jwt_lifetime);
c->cached.jwt_expiration = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c->jwt_lifetime);
c->cached.service_url = gpr_strdup(service_url);
c->cached.jwt_md = grpc_credentials_md_store_create(1);
grpc_credentials_md_store_add_cstrings(
@ -586,7 +586,7 @@ static void on_oauth2_token_fetcher_http_response(
status = grpc_oauth2_token_fetcher_credentials_parse_server_response(
response, &c->access_token_md, &token_lifetime);
if (status == GRPC_CREDENTIALS_OK) {
c->token_expiration = gpr_time_add(gpr_now(), token_lifetime);
c->token_expiration = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), token_lifetime);
r->cb(r->user_data, c->access_token_md->entries,
c->access_token_md->num_entries, status);
} else {
@ -608,7 +608,7 @@ static void oauth2_token_fetcher_get_request_metadata(
{
gpr_mu_lock(&c->mu);
if (c->access_token_md != NULL &&
(gpr_time_cmp(gpr_time_sub(c->token_expiration, gpr_now()),
(gpr_time_cmp(gpr_time_sub(c->token_expiration, gpr_now(GPR_CLOCK_REALTIME)),
refresh_threshold) > 0)) {
cached_access_token_md =
grpc_credentials_md_store_ref(c->access_token_md);
@ -623,7 +623,7 @@ static void oauth2_token_fetcher_get_request_metadata(
c->fetch_func(
grpc_credentials_metadata_request_create(creds, cb, user_data),
&c->httpcli_context, pollset, on_oauth2_token_fetcher_http_response,
gpr_time_add(gpr_now(), refresh_threshold));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), refresh_threshold));
}
}

@ -105,7 +105,7 @@ static int is_stack_running_on_compute_engine(void) {
grpc_httpcli_context_init(&context);
grpc_httpcli_get(&context, &detector.pollset, &request,
gpr_time_add(gpr_now(), max_detection_delay),
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay),
on_compute_engine_detection_http_response, &detector);
/* Block until we get the response. This is not ideal but this should only be

@ -207,7 +207,7 @@ static char *encoded_jwt_claim(const grpc_auth_json_key *json_key,
grpc_json *child = NULL;
char *json_str = NULL;
char *result = NULL;
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec expiration = gpr_time_add(now, token_lifetime);
char now_str[GPR_LTOA_MIN_BUFSIZE];
char expiration_str[GPR_LTOA_MIN_BUFSIZE];

@ -157,7 +157,7 @@ static void record_stats(census_ht* store, census_op_id op_id,
key.ptr = gpr_strdup(key.ptr);
census_ht_insert(store, key, (void*)window_stats);
}
census_window_stats_add(window_stats, gpr_now(), stats);
census_window_stats_add(window_stats, gpr_now(GPR_CLOCK_REALTIME), stats);
} else {
census_internal_unlock_trace_store();
}
@ -185,7 +185,7 @@ static void get_stats(census_ht* store, census_aggregated_rpc_stats* data) {
if (store != NULL) {
size_t n;
unsigned i, j;
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
census_ht_kv* kv = census_ht_get_all_elements(store, &n);
if (kv != NULL) {
data->num_entries = n;

@ -94,7 +94,7 @@ census_op_id census_tracing_start_op(void) {
g_id++;
memcpy(&ret->id, &g_id, sizeof(census_op_id));
ret->rpc_stats.cnt = 1;
ret->ts = gpr_now();
ret->ts = gpr_now(GPR_CLOCK_REALTIME);
census_ht_insert(g_trace_store, op_id_as_key(&ret->id), (void*)ret);
gpr_log(GPR_DEBUG, "Start tracing for id %lu", g_id);
gpr_mu_unlock(&g_mu);
@ -122,7 +122,7 @@ void census_tracing_print(census_op_id op_id, const char* anno_txt) {
trace = census_ht_find(g_trace_store, op_id_as_key(&op_id));
if (trace != NULL) {
census_trace_annotation* anno = gpr_malloc(sizeof(census_trace_annotation));
anno->ts = gpr_now();
anno->ts = gpr_now(GPR_CLOCK_REALTIME);
{
char* d = anno->txt;
const char* s = anno_txt;
@ -144,7 +144,7 @@ void census_tracing_end_op(census_op_id op_id) {
trace = census_ht_find(g_trace_store, op_id_as_key(&op_id));
if (trace != NULL) {
trace->rpc_stats.elapsed_time_ms =
gpr_timespec_to_micros(gpr_time_sub(gpr_now(), trace->ts));
gpr_timespec_to_micros(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), trace->ts));
gpr_log(GPR_DEBUG, "End tracing for id %lu, method %s, latency %f us",
op_id_2_uint64(&op_id), trace->method,
trace->rpc_stats.elapsed_time_ms);

@ -90,11 +90,11 @@
// Record a new event, taking 15.3ms, transferring 1784 bytes.
stat.latency = 0.153;
stat.bytes = 1784;
census_window_stats_add(stats, gpr_now(), &stat);
census_window_stats_add(stats, gpr_now(GPR_CLOCK_REALTIME), &stat);
// Get sums and print them out
result[kMinInterval].statistic = &sums[kMinInterval];
result[kHourInterval].statistic = &sums[kHourInterval];
census_window_stats_get_sums(stats, gpr_now(), result);
census_window_stats_get_sums(stats, gpr_now(GPR_CLOCK_REALTIME), result);
printf("%d events/min, average time %gs, average bytes %g\n",
result[kMinInterval].count,
(my_stat*)result[kMinInterval].statistic->latency /

@ -122,7 +122,7 @@ void gpr_cancellable_cancel(gpr_cancellable *c) {
gpr_event ev;
gpr_event_init(&ev);
gpr_event_wait(&ev,
gpr_time_add(gpr_now(), gpr_time_from_micros(1000)));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)));
}
}
} while (failures != 0);

@ -73,7 +73,7 @@ void gpr_default_log(gpr_log_func_args *args) {
char *final_slash;
const char *display_file;
char time_buffer[64];
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
final_slash = strrchr(args->file, '/');

@ -75,7 +75,7 @@ void gpr_default_log(gpr_log_func_args *args) {
char *final_slash;
const char *display_file;
char time_buffer[64];
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
final_slash = strrchr(args->file, '/');

@ -82,7 +82,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
/* Simple starter implementation */
void gpr_default_log(gpr_log_func_args *args) {
char time_buffer[64];
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
if (localtime_s(&tm, &now.tv_sec)) {

@ -89,7 +89,7 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) {
if (gpr_time_cmp(abs_deadline, gpr_inf_future) == 0) {
SleepConditionVariableCS(cv, &mu->cs, INFINITE);
} else {
gpr_timespec now = gpr_now();
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
gpr_int64 now_ms = now.tv_sec * 1000 + now.tv_nsec / 1000000;
gpr_int64 deadline_ms =
abs_deadline.tv_sec * 1000 + abs_deadline.tv_nsec / 1000000;

@ -55,22 +55,55 @@ static gpr_timespec gpr_from_timespec(struct timespec ts) {
return rv;
}
gpr_timespec gpr_now(void) {
/** maps gpr_clock_type --> clockid_t for clock_gettime */
static clockid_t clockid_for_gpr_clock[] = {
CLOCK_MONOTONIC,
CLOCK_REALTIME
};
void gpr_time_init(void) {}
gpr_timespec gpr_now(gpr_clock_type clock) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
clock_gettime(clockid_for_gpr_clock[clock], &now);
return gpr_from_timespec(now);
}
#else
/* For some reason Apple's OSes haven't implemented clock_gettime. */
#include <sys/time.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
static double g_time_scale;
static uint64_t g_time_start;
void gpr_time_init(void) {
mach_timebase_info_data_t tb = { 0, 1 };
mach_timebase_info(&tb);
g_time_scale = tb.numer;
g_time_scale /= tb.denom;
g_time_start = mach_absolute_time();
}
gpr_timespec gpr_now(void) {
gpr_timespec gpr_now(gpr_clock_type clock) {
gpr_timespec now;
struct timeval now_tv;
gettimeofday(&now_tv, NULL);
now.tv_sec = now_tv.tv_sec;
now.tv_nsec = now_tv.tv_usec * 1000;
double now_dbl;
switch (clock) {
case GPR_CLOCK_REALTIME:
gettimeofday(&now_tv, NULL);
now.tv_sec = now_tv.tv_sec;
now.tv_nsec = now_tv.tv_usec * 1000;
break;
case GPR_CLOCK_MONOTONIC:
now_dbl = (mach_absolute_time() - g_time_start) * g_time_scale;
now.tv_sec = now_dbl * 1e-9;
now.tv_nsec = now_dbl - now.tv_sec * 1e9;
break;
}
return now;
}
#endif
@ -83,7 +116,7 @@ void gpr_sleep_until(gpr_timespec until) {
for (;;) {
/* We could simplify by using clock_nanosleep instead, but it might be
* slightly less portable. */
now = gpr_now();
now = gpr_now(GPR_CLOCK_REALTIME);
if (gpr_time_cmp(until, now) <= 0) {
return;
}

@ -58,7 +58,7 @@ void gpr_sleep_until(gpr_timespec until) {
for (;;) {
/* We could simplify by using clock_nanosleep instead, but it might be
* slightly less portable. */
now = gpr_now();
now = gpr_now(GPR_CLOCK_REALTIME);
if (gpr_time_cmp(until, now) <= 0) {
return;
}

@ -1190,7 +1190,7 @@ static void set_deadline_alarm(grpc_call *call, gpr_timespec deadline) {
}
GRPC_CALL_INTERNAL_REF(call, "alarm");
call->have_alarm = 1;
grpc_alarm_init(&call->alarm, deadline, call_alarm, call, gpr_now());
grpc_alarm_init(&call->alarm, deadline, call_alarm, call, gpr_now(GPR_CLOCK_REALTIME));
}
/* we offset status by a small amount when storing it into transport metadata

@ -325,7 +325,7 @@ void grpc_cq_hack_spin_pollset(grpc_completion_queue *cc) {
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
grpc_pollset_kick(&cc->pollset);
grpc_pollset_work(&cc->pollset,
gpr_time_add(gpr_now(), gpr_time_from_millis(100)));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100)));
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
}

@ -33,6 +33,7 @@
#include <grpc/census.h>
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include "src/core/channel/channel_stack.h"
#include "src/core/debug/trace.h"
#include "src/core/iomgr/iomgr.h"
@ -56,6 +57,7 @@ void grpc_init(void) {
gpr_mu_lock(&g_init_mu);
if (++g_initializations == 1) {
gpr_time_init();
grpc_register_tracer("channel", &grpc_trace_channel);
grpc_register_tracer("surface", &grpc_surface_trace);
grpc_register_tracer("http", &grpc_http_trace);

@ -599,7 +599,7 @@ static void on_header(void *tp, grpc_mdelem *md) {
}
grpc_chttp2_incoming_metadata_buffer_set_deadline(
&stream_parsing->incoming_metadata,
gpr_time_add(gpr_now(), *cached_timeout));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), *cached_timeout));
grpc_mdelem_unref(md);
} else {
grpc_chttp2_incoming_metadata_buffer_add(&stream_parsing->incoming_metadata,

@ -437,7 +437,7 @@ static void deadline_enc(grpc_chttp2_hpack_compressor *c, gpr_timespec deadline,
framer_state *st) {
char timeout_str[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_mdelem *mdelem;
grpc_chttp2_encode_timeout(gpr_time_sub(deadline, gpr_now()), timeout_str);
grpc_chttp2_encode_timeout(gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)), timeout_str);
mdelem = grpc_mdelem_from_metadata_strings(
c->mdctx, grpc_mdstr_ref(c->timeout_key_str),
grpc_mdstr_from_string(c->mdctx, timeout_str));

@ -161,7 +161,7 @@ grpc_mdctx *grpc_mdctx_create(void) {
/* This seed is used to prevent remote connections from controlling hash table
* collisions. It needs to be somewhat unpredictable to a remote connection.
*/
return grpc_mdctx_create_with_seed(gpr_now().tv_nsec);
return grpc_mdctx_create_with_seed(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
}
static void discard_metadata(grpc_mdctx *ctx) {

@ -379,7 +379,7 @@ grpcsharp_channel_args_destroy(grpc_channel_args *args) {
/* Timespec */
GPR_EXPORT gpr_timespec GPR_CALLTYPE gprsharp_now(void) { return gpr_now(); }
GPR_EXPORT gpr_timespec GPR_CALLTYPE gprsharp_now(void) { return gpr_now(GPR_CLOCK_REALTIME); }
GPR_EXPORT gpr_timespec GPR_CALLTYPE gprsharp_inf_future(void) {
return gpr_inf_future;

@ -208,7 +208,7 @@ PHP_METHOD(Timeval, similar) {
* @return Timeval The current time
*/
PHP_METHOD(Timeval, now) {
zval *now = grpc_php_wrap_timeval(gpr_now());
zval *now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME));
RETURN_DESTROY_ZVAL(now);
}

@ -91,7 +91,7 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) {
* - investigate further, this is probably another example of C-level cleanup
* not working consistently in all cases.
*/
next_call.timeout = gpr_time_add(gpr_now(), gpr_time_from_micros(5e3));
next_call.timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(5e3));
do {
rb_thread_call_without_gvl(grpc_rb_completion_queue_next_no_gil,
(void *)&next_call, NULL, NULL);

@ -248,7 +248,7 @@ void cq_verify(cq_verifier *v) {
}
void cq_verify_empty(cq_verifier *v) {
gpr_timespec deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(1));
gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1));
grpc_event ev;
GPR_ASSERT(v->expect.next == &v->expect && "expectation queue must be empty");

@ -124,7 +124,7 @@ static void step_ping_pong_stream(void) {
}
static double now(void) {
gpr_timespec tv = gpr_now();
gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME);
return 1e9 * tv.tv_sec + tv.tv_nsec;
}

@ -241,7 +241,7 @@ int main(int argc, char **argv) {
shutdown_started = 1;
}
ev = grpc_completion_queue_next(
cq, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)));
cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)));
s = ev.tag;
switch (ev.type) {
case GRPC_OP_COMPLETE:

@ -145,7 +145,7 @@ int main(int argc, char **argv) {
gpr_free(args[0]);
gpr_free(args[2]);
gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5)));
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5)));
grpc_test_init(argc, argv);
grpc_init();

@ -51,7 +51,7 @@ static void cb(void *arg, int success) {
}
static void add_test(void) {
gpr_timespec start = gpr_now();
gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME);
int i;
grpc_alarm alarms[20];

@ -113,7 +113,7 @@ static void test_grpc_alarm(void) {
gpr_event_init(&arg.fcb_arg);
grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg,
gpr_now());
gpr_now(GPR_CLOCK_REALTIME));
alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
gpr_mu_lock(&arg.mu);
@ -165,7 +165,7 @@ static void test_grpc_alarm(void) {
gpr_event_init(&arg2.fcb_arg);
grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100),
alarm_cb, &arg2, gpr_now());
alarm_cb, &arg2, gpr_now(GPR_CLOCK_REALTIME));
grpc_alarm_cancel(&alarm_to_cancel);
alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);

@ -254,7 +254,7 @@ static void read_and_write_test(grpc_endpoint_test_config config,
gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
while (!state.read_done || !state.write_done) {
GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0);
GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
grpc_pollset_work(g_pollset, deadline);
}
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
@ -350,14 +350,14 @@ static void shutdown_during_write_test(grpc_endpoint_test_config config,
deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
while (!write_st.done) {
GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0);
GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
grpc_pollset_work(g_pollset, deadline);
}
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
grpc_endpoint_destroy(write_st.ep);
gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
while (!read_st.done) {
GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0);
GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0);
grpc_pollset_work(g_pollset, deadline);
}
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));

@ -187,11 +187,11 @@ void test_times_out(void) {
/* Make sure the event doesn't trigger early */
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
while (gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(2)),
gpr_now()) > 0) {
int is_after_deadline = gpr_time_cmp(connect_deadline, gpr_now()) <= 0;
gpr_now(GPR_CLOCK_REALTIME)) > 0) {
int is_after_deadline = gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0;
if (is_after_deadline &&
gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(1)),
gpr_now()) > 0) {
gpr_now(GPR_CLOCK_REALTIME)) > 0) {
/* allow some slack before insisting that things be done */
} else {
GPR_ASSERT(g_connections_complete ==

@ -135,7 +135,7 @@ static void test_connect(int n) {
gpr_log(GPR_DEBUG, "wait");
while (g_nconnects == nconnects_before &&
gpr_time_cmp(deadline, gpr_now()) > 0) {
gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) {
grpc_pollset_work(&g_pollset, deadline);
}
gpr_log(GPR_DEBUG, "wait done");

@ -296,7 +296,7 @@ static void print_histogram(gpr_histogram *histogram) {
}
static double now(void) {
gpr_timespec tv = gpr_now();
gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME);
return 1e9 * tv.tv_sec + tv.tv_nsec;
}

@ -568,7 +568,7 @@ void test_performance(void) {
double write_time_micro = 0.0;
int nrecords = 0;
setup_test(0);
start_time = gpr_now();
start_time = gpr_now(GPR_CLOCK_REALTIME);
while (1) {
void* record = census_log_start_write(write_size);
if (record == NULL) {
@ -577,7 +577,7 @@ void test_performance(void) {
census_log_end_write(record, write_size);
nrecords++;
}
write_time = gpr_time_sub(gpr_now(), start_time);
write_time = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start_time);
write_time_micro = write_time.tv_sec * 1000000 + write_time.tv_nsec / 1000;
census_log_shutdown();
printf(

@ -40,7 +40,7 @@
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
test_multiple_writers_circular_log();
return 0;
}

@ -40,7 +40,7 @@
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
test_multiple_writers();
return 0;
}

@ -40,7 +40,7 @@
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
test_performance();
return 0;
}

@ -40,7 +40,7 @@
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
test_invalid_record_size();
test_end_write_with_different_size();
test_read_pending_record();

@ -40,7 +40,7 @@
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
test_small_log();
return 0;
}

@ -83,7 +83,7 @@ void empty_test(void) {
result.statistic = &sum;
census_window_stats_get_sums(stats, zero, &result);
GPR_ASSERT(result.count == 0 && sum.value1 == 0 && sum.value2 == 0);
census_window_stats_get_sums(stats, gpr_now(), &result);
census_window_stats_get_sums(stats, gpr_now(GPR_CLOCK_REALTIME), &result);
GPR_ASSERT(result.count == 0 && sum.value1 == 0 && sum.value2 == 0);
census_window_stats_destroy(stats);
}
@ -268,7 +268,7 @@ void rolling_time_test(void) {
struct census_window_stats* stats =
census_window_stats_create(1, &kMinInterval, 7, &kMyStatInfo);
GPR_ASSERT(stats != NULL);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
for (i = 0; i < 100000; i++) {
increment.tv_nsec = rand() % 100000000; /* up to 1/10th second */
when = gpr_time_add(when, increment);
@ -292,7 +292,7 @@ void infinite_interval_test(void) {
gpr_timespec increment = {0, 0};
struct census_window_stats* stats =
census_window_stats_create(1, &gpr_inf_future, 10, &kMyStatInfo);
srand(gpr_now().tv_nsec);
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
for (i = 0; i < count; i++) {
increment.tv_sec = rand() % 21600; /* 6 hours */
when = gpr_time_add(when, increment);

@ -81,22 +81,22 @@ static void test(void) {
GPR_ASSERT(!gpr_cancellable_is_cancelled(&t.cancel));
/* Test timeout on event wait for uncancelled gpr_cancellable */
interval = gpr_now();
interval = gpr_now(GPR_CLOCK_REALTIME);
gpr_event_cancellable_wait(
&t.ev, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), &t.cancel);
interval = gpr_time_sub(gpr_now(), interval);
&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), &t.cancel);
interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval);
GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0);
GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0);
/* Test timeout on cv wait for uncancelled gpr_cancellable */
gpr_mu_lock(&t.mu);
interval = gpr_now();
interval = gpr_now(GPR_CLOCK_REALTIME);
while (!gpr_cv_cancellable_wait(
&t.cv, &t.mu,
gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)),
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)),
&t.cancel)) {
}
interval = gpr_time_sub(gpr_now(), interval);
interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval);
GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0);
GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0);
gpr_mu_unlock(&t.mu);
@ -113,7 +113,7 @@ static void test(void) {
/* Wait a second, and check that no threads have finished waiting. */
gpr_mu_lock(&t.mu);
gpr_cv_wait(&t.cv, &t.mu,
gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)));
GPR_ASSERT(t.n == n);
gpr_mu_unlock(&t.mu);
@ -129,21 +129,21 @@ static void test(void) {
/* Test timeout on cv wait for cancelled gpr_cancellable */
gpr_mu_lock(&t.mu);
interval = gpr_now();
interval = gpr_now(GPR_CLOCK_REALTIME);
while (!gpr_cv_cancellable_wait(
&t.cv, &t.mu,
gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)),
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)),
&t.cancel)) {
}
interval = gpr_time_sub(gpr_now(), interval);
interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval);
GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0);
gpr_mu_unlock(&t.mu);
/* Test timeout on event wait for cancelled gpr_cancellable */
interval = gpr_now();
interval = gpr_now(GPR_CLOCK_REALTIME);
gpr_event_cancellable_wait(
&t.ev, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), &t.cancel);
interval = gpr_time_sub(gpr_now(), interval);
&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), &t.cancel);
interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval);
GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0);
gpr_mu_destroy(&t.mu);

@ -242,12 +242,12 @@ static void test(const char *name, void (*body)(void *m),
void (*extra)(void *m), int timeout_s) {
gpr_int64 iterations = 1024;
struct test *m;
gpr_timespec start = gpr_now();
gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec time_taken;
gpr_timespec deadline =
gpr_time_add(start, gpr_time_from_micros(timeout_s * 1000000));
fprintf(stderr, "%s:", name);
while (gpr_time_cmp(gpr_now(), deadline) < 0) {
while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) {
iterations <<= 1;
fprintf(stderr, " %ld", (long)iterations);
m = test_new(10, iterations);
@ -265,7 +265,7 @@ static void test(const char *name, void (*body)(void *m),
}
test_destroy(m);
}
time_taken = gpr_time_sub(gpr_now(), start);
time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start);
fprintf(stderr, " done %ld.%09d s\n", (long)time_taken.tv_sec,
(int)time_taken.tv_nsec);
}
@ -323,7 +323,7 @@ static void inc_with_1ms_delay(void *v /*=m*/) {
for (i = 0; i != m->iterations; i++) {
gpr_timespec deadline;
gpr_mu_lock(&m->mu);
deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(1000));
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000));
while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) {
}
m->counter++;
@ -339,7 +339,7 @@ static void inc_with_1ms_delay_event(void *v /*=m*/) {
gpr_int64 i;
for (i = 0; i != m->iterations; i++) {
gpr_timespec deadline;
deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(1000));
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000));
GPR_ASSERT(gpr_event_wait(&m->event, deadline) == NULL);
gpr_mu_lock(&m->mu);
m->counter++;
@ -384,7 +384,7 @@ static void consumer(void *v /*=m*/) {
gpr_mu_unlock(&m->mu);
GPR_ASSERT(
!queue_remove(&m->q, &value,
gpr_time_add(gpr_now(), gpr_time_from_micros(1000000))));
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000))));
mark_thread_done(m);
}

@ -69,7 +69,7 @@ static void test_wait_empty(void) {
LOG_TEST("test_wait_empty");
cc = grpc_completion_queue_create();
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_now()).type ==
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_now(GPR_CLOCK_REALTIME)).type ==
GRPC_QUEUE_TIMEOUT);
shutdown_and_destroy(cc);
}

@ -52,11 +52,11 @@ extern "C" {
(GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR)
#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(), \
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \
gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x)))
#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(), \
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \
gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)))
#ifndef GRPC_TEST_CUSTOM_PICK_PORT

Loading…
Cancel
Save