Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace: when profiling, dump a sampling trace #671

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/noun/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ static c3_o _ct_lop_o;
/// Nock PID.
static pid_t _nock_pid_i = 0;

/// dump trace file.
static FILE* _filt_u = NULL;

/// JSON trace file.
static FILE* _file_u = NULL;

Expand Down Expand Up @@ -209,6 +212,28 @@ u3t_samp(void)
return;
}

u3_noun don = u3R->pro.don;
while ( u3_nul != don ) {
u3_noun dot = u3h(don);

while ( u3_nul != dot ) {
u3_noun dit = u3h(dot);
c3_w len_w = u3r_met(3, dit);
c3_c* dit_c = ( c3y == u3a_is_cat(dit) )
? &dit
: ((u3a_atom*)u3a_to_ptr(dit))->buf_w;
fprintf(_filt_u, "/%.*s", len_w, dit_c);

dot = u3t(dot);
}
fprintf(_filt_u, "\n");

don = u3t(don);
}
fprintf(_filt_u, "1\n\n");

return;

c3_w old_wag = u3C.wag_w;
u3C.wag_w &= ~u3o_debug_cpu;
u3C.wag_w &= ~u3o_trace;
Expand Down Expand Up @@ -547,6 +572,24 @@ u3t_init(void)
u3T.far_o = c3n;
u3T.coy_o = c3n;
u3T.euq_o = c3n;

if ( ( u3C.wag_w & u3o_debug_cpu ) && !_filt_u ) {
c3_c fil_c[2048];
snprintf(fil_c, 2048, "%s/.urb/put/trace", u3C.dir_c);

struct stat st;
if ( (-1 == stat(fil_c, &st))
&& (-1 == c3_mkdir(fil_c, 0700)) )
{
fprintf(stderr, "mkdir: %s failed: %s\r\n", fil_c, strerror(errno));
return;
}

snprintf(fil_c, 2048, "%s/.urb/put/trace/dump.txt", u3C.dir_c);

_filt_u = c3_fopen(fil_c, "w");
fprintf(_filt_u, "\n\n\n");
}
}

c3_w
Expand Down
Loading