automatically split json trace outputs at 100000 line intervals

This commit is contained in:
Isaac Visintainer 2019-01-31 22:31:20 -08:00
parent 634e9bf42d
commit 323c453404
4 changed files with 33 additions and 12 deletions

View File

@ -86,7 +86,7 @@
/* u3t_trace_open(): opens the path for writing tracing information.
*/
void
u3t_trace_open(c3_c*);
u3t_trace_open();
/* u3t_trace_close(): closes the trace file. optional.
*/

View File

@ -583,7 +583,7 @@
c3_c* gen_c; // -G, czar generator
c3_o gab; // -g, test garbage collection
c3_c* dns_c; // -H, ames bootstrap domain
c3_c* json_file_c; // -j, json trace
c3_o tra; // -j, json trace
c3_w kno_w; // -K, kernel version
c3_c* key_c; // -k, private key file
c3_o net; // -L, local-only networking

View File

@ -3,7 +3,10 @@
** This file is in the public domain.
*/
#include "all.h"
#include "vere/vere.h"
#include <pthread.h>
#include <time.h>
#include <sys/stat.h>
static c3_o _ct_lop_o;
@ -300,14 +303,25 @@ u3t_flee(void)
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
u3t_trace_open(c3_c* trace_file_name)
u3t_trace_open()
{
printf("trace: tracing to %s\n", trace_file_name);
trace_file_u = fopen(trace_file_name, "w");
c3_c fil_c[2048];
snprintf(fil_c, 2048, "%s/.urb/put/trace", u3_Host.dir_c);
struct stat st;
if ( -1 == stat(fil_c, &st) ) {
mkdir(fil_c, 0700);
}
snprintf(fil_c, 2048, "%s/%ld.json", fil_c, time(NULL));
trace_file_u = fopen(fil_c, "w");
nock_pid_i = (int)getpid();
fprintf(trace_file_u, "[ ");
@ -335,6 +349,7 @@ u3t_trace_open(c3_c* trace_file_name)
"{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, "
"\"tid\": 2, \"args\": {\"sort_index\": 2}},\n",
nock_pid_i);
trace_counter = 5;
}
/* u3t_trace_close(): closes a trace file. optional.
@ -440,6 +455,12 @@ u3t_nock_trace_pop()
if (!trace_file_u)
return;
if ( trace_counter >= 100000 ) {
u3t_trace_close();
u3t_trace_open();
}
u3_noun trace = u3R->pro.trace;
u3R->pro.trace = u3k(u3t(trace));
@ -462,6 +483,7 @@ u3t_nock_trace_pop()
duration);
free(name);
trace_counter++;
}
u3z(trace);
@ -482,6 +504,7 @@ u3t_event_trace(const c3_c* name, c3_c type)
type,
nock_pid_i,
u3t_trace_time());
trace_counter++;
}
extern FILE*

View File

@ -83,6 +83,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.qui = c3n;
u3_Host.ops_u.rep = c3n;
u3_Host.ops_u.tex = c3n;
u3_Host.ops_u.tra = c3n;
u3_Host.ops_u.veb = c3n;
u3_Host.ops_u.kno_w = DefaultKernel;
@ -91,7 +92,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.nam_c = 0;
while ( -1 != (ch_i=getopt(argc, argv,
"G:B:K:A:H:w:u:j:e:E:f:F:k:m:p:LabcCdgqstvxPDRS")) ) {
"G:B:K:A:H:w:u:e:E:f:F:k:m:p:LjabcCdgqstvxPDRS")) ) {
switch ( ch_i ) {
case 'B': {
@ -131,10 +132,6 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.url_c = strdup(optarg);
break;
}
case 'j': {
u3_Host.ops_u.json_file_c = strdup(optarg);
break;
}
case 'x': {
u3_Host.ops_u.tex = c3y;
break;
@ -170,6 +167,7 @@ _main_getopt(c3_i argc, c3_c** argv)
return c3y;
}
case 'L': { u3_Host.ops_u.net = c3n; break; }
case 'j': { u3_Host.ops_u.tra = c3y; break; }
case 'a': { u3_Host.ops_u.abo = c3y; break; }
case 'b': { u3_Host.ops_u.bat = c3y; break; }
case 'c': { u3_Host.ops_u.nuu = c3y; break; }
@ -656,9 +654,9 @@ main(c3_i argc,
/* Set tracing flag
*/
if ( u3_Host.ops_u.json_file_c ) {
if ( _(u3_Host.ops_u.tra) ) {
u3C.wag_w |= u3o_trace;
u3t_trace_open(u3_Host.ops_u.json_file_c);
u3t_trace_open();
}
}
u3m_boot(u3_Host.ops_u.nuu,