diff options
author | Craig Tiller <ctiller@google.com> | 2017-02-02 16:08:05 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-02-02 16:08:05 -0800 |
commit | 7dc4ea66f0688c30aa7ddd865074a808fd20f076 (patch) | |
tree | 98559190df65980bc3818f99bda09a3b595266a1 /src/core/lib/profiling | |
parent | 95ca017ce85ecdabe6e39275acfe9db736f97735 (diff) |
Make the microbenchmark profile gatherer run some in parallel
Diffstat (limited to 'src/core/lib/profiling')
-rw-r--r-- | src/core/lib/profiling/basic_timers.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/core/lib/profiling/basic_timers.c b/src/core/lib/profiling/basic_timers.c index bdf9af2339..c4f2772822 100644 --- a/src/core/lib/profiling/basic_timers.c +++ b/src/core/lib/profiling/basic_timers.c @@ -44,6 +44,8 @@ #include <grpc/support/time.h> #include <stdio.h> +#include "src/core/lib/support/env.h" + typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type; typedef struct gpr_timer_entry { @@ -74,7 +76,7 @@ typedef struct gpr_timer_log_list { static __thread gpr_timer_log *g_thread_log; static gpr_once g_once_init = GPR_ONCE_INIT; static FILE *output_file; -static const char *output_filename = "latency_trace.txt"; +static const char *output_filename_or_null = NULL; static pthread_mutex_t g_mu; static pthread_cond_t g_cv; static gpr_timer_log_list g_in_progress_logs; @@ -85,6 +87,16 @@ static __thread int g_thread_id; static int g_next_thread_id; static int g_writing_enabled = 1; +static const char *output_filename() { + if (output_filename_or_null == NULL) { + output_filename_or_null = gpr_getenv("LATENCY_TRACE"); + if (output_filename_or_null == NULL) { + output_filename_or_null = "latency_trace.txt"; + } + } + return output_filename_or_null; +} + static int timer_log_push_back(gpr_timer_log_list *list, gpr_timer_log *log) { if (list->head == NULL) { list->head = list->tail = log; @@ -134,7 +146,7 @@ static void timer_log_remove(gpr_timer_log_list *list, gpr_timer_log *log) { static void write_log(gpr_timer_log *log) { size_t i; if (output_file == NULL) { - output_file = fopen(output_filename, "w"); + output_file = fopen(output_filename(), "w"); } for (i = 0; i < log->num_entries; i++) { gpr_timer_entry *entry = &(log->log[i]); @@ -198,7 +210,7 @@ static void finish_writing(void) { } void gpr_timers_set_log_filename(const char *filename) { - output_filename = filename; + output_filename_or_null = filename; } static void init_output() { |