From ea6f2fd87b8ec005c1a6f5f2f9a0dbc08fe95e4c Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Fri, 1 Feb 2019 17:00:22 -0800 Subject: [PATCH] splits log files between arvo events --- include/vere/vere.h | 10 ++++++- noun/trace.c | 68 ++++++++++++++++++--------------------------- vere/main.c | 3 ++ vere/raft.c | 5 ++++ 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/include/vere/vere.h b/include/vere/vere.h index 79b4ee146e..accc014794 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -565,6 +565,14 @@ c3_o vog; // did they vote for us? } u3_rnam; + /* u3_trac: tracing information. + */ + typedef struct _u3_trac { + c3_w nid_w; // nock pid + FILE* fil_u; // trace file (json) + c3_w con_w; // trace counter + } u3_trac; + /* u3_opts: command line configuration. */ typedef struct _u3_opts { @@ -625,7 +633,7 @@ c3_o liv; // if u3_no, shut down c3_i xit_i; // exit code for shutdown void* tls_u; // server SSL_CTX* - FILE* trace_file_u; // trace file to write to + u3_trac tra_u; // tracing information } u3_host; // host == computer == process # define u3L u3_Host.lup_u // global event loop diff --git a/noun/trace.c b/noun/trace.c index c757f2159e..a6ce5bc2f6 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -301,10 +301,6 @@ u3t_flee(void) u3z(don); } -static FILE* trace_file_u = NULL; -static int nock_pid_i = 0; -static int trace_counter; - /* u3t_trace_open(): opens a trace file and writes the preamble. */ void @@ -324,35 +320,35 @@ u3t_trace_open() snprintf(fil_c, 2048, "%s/%s.json", fil_c, wen_c); free(wen_c); - trace_file_u = fopen(fil_c, "w"); - nock_pid_i = (int)getpid(); - fprintf(trace_file_u, "[ "); + u3_Host.tra_u.fil_u = fopen(fil_c, "w"); + u3_Host.tra_u.nid_w = (int)getpid(); + + fprintf(u3_Host.tra_u.fil_u, "[ "); // We have two "threads", the event processing and the nock stuff. // tid 1 = event processing // tid 2 = nock processing - fprintf( - trace_file_u, + fprintf(u3_Host.tra_u.fil_u, "{\"name\": \"process_name\", \"ph\": \"M\", \"pid\": %d, \"args\": " "{\"name\": \"urbit\"}},\n", - nock_pid_i); - fprintf(trace_file_u, + u3_Host.tra_u.nid_w); + fprintf(u3_Host.tra_u.fil_u, "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 1, " "\"args\": {\"name\": \"Event Processing\"}},\n", - nock_pid_i); - fprintf(trace_file_u, + u3_Host.tra_u.nid_w); + fprintf(u3_Host.tra_u.fil_u, "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " "\"tid\": 1, \"args\": {\"sort_index\": 1}},\n", - nock_pid_i); - fprintf(trace_file_u, + u3_Host.tra_u.nid_w); + fprintf(u3_Host.tra_u.fil_u, "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 2, " "\"args\": {\"name\": \"Nock\"}},\n", - nock_pid_i); - fprintf(trace_file_u, + u3_Host.tra_u.nid_w); + fprintf(u3_Host.tra_u.fil_u, "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " "\"tid\": 2, \"args\": {\"sort_index\": 2}},\n", - nock_pid_i); - trace_counter = 5; + u3_Host.tra_u.nid_w); + u3_Host.tra_u.con_w = 5; } /* u3t_trace_close(): closes a trace file. optional. @@ -360,11 +356,12 @@ u3t_trace_open() void u3t_trace_close() { - if (!trace_file_u) + if (!u3_Host.tra_u.fil_u) return; // We don't terminate the JSON because of the file format. - fclose(trace_file_u); + fclose(u3_Host.tra_u.fil_u); + u3_Host.tra_u.con_w = 0; } /* u3t_trace_time(): microsecond clock @@ -383,7 +380,7 @@ c3_d u3t_trace_time() c3_o u3t_nock_trace_push(u3_noun lab) { - if (!trace_file_u) + if (!u3_Host.tra_u.fil_u) return c3n; if ( (u3_nul == u3R->pro.trace) || @@ -455,15 +452,9 @@ trace_pretty(u3_noun som) void u3t_nock_trace_pop() { - if (!trace_file_u) + if (!u3_Host.tra_u.fil_u) return; - if ( trace_counter >= 100000 ) { - u3t_trace_close(); - u3t_trace_open(); - } - - u3_noun trace = u3R->pro.trace; u3R->pro.trace = u3k(u3t(trace)); @@ -476,17 +467,17 @@ u3t_nock_trace_pop() if (duration > 33) { c3_c* name = trace_pretty(lab); - fprintf(trace_file_u, + fprintf(u3_Host.tra_u.fil_u, "{\"cat\": \"nock\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " "\"tid\": 2, \"ts\": %" PRIu64 ", \"dur\": %" PRIu64 "}, \n", name, 'X', - nock_pid_i, + u3_Host.tra_u.nid_w, start_time, duration); free(name); - trace_counter++; + u3_Host.tra_u.con_w++; } u3z(trace); @@ -497,22 +488,17 @@ u3t_nock_trace_pop() void u3t_event_trace(const c3_c* name, c3_c type) { - if (!trace_file_u) + if (!u3_Host.tra_u.fil_u) return; - if ( trace_counter >= 100000 ) { - u3t_trace_close(); - u3t_trace_open(); - } - - fprintf(trace_file_u, + fprintf(u3_Host.tra_u.fil_u, "{\"cat\": \"event\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " "\"tid\": 1, \"ts\": %" PRIu64 ", \"id\": \"0x100\"}, \n", name, type, - nock_pid_i, + u3_Host.tra_u.nid_w, u3t_trace_time()); - trace_counter++; + u3_Host.tra_u.con_w++; } extern FILE* diff --git a/vere/main.c b/vere/main.c index eee9184951..7cd1eed850 100644 --- a/vere/main.c +++ b/vere/main.c @@ -656,6 +656,9 @@ main(c3_i argc, */ if ( _(u3_Host.ops_u.tra) ) { u3C.wag_w |= u3o_trace; + u3_Host.tra_u.nid_w = 0; + u3_Host.tra_u.fil_u = NULL; + u3_Host.tra_u.con_w = 0; } } u3m_boot(u3_Host.ops_u.nuu, diff --git a/vere/raft.c b/vere/raft.c index 668e0a951a..17293b1fc2 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -2052,6 +2052,11 @@ _raft_pump(u3_noun ovo) void u3_raft_chip(void) { + if ( (u3C.wag_w & u3o_trace) && (u3_Host.tra_u.con_w >= 100000) ) { + u3t_trace_close(); + u3t_trace_open(); + } + u3_weak rus = _raft_poke(); _raft_crop();