Skip to content

Commit

Permalink
u3: improve %bout time printing
Browse files Browse the repository at this point in the history
Now prints micro-, milli-, or full seconds, in the style of
u3a_print_memory (|mass).
  • Loading branch information
Fang- committed Apr 10, 2022
1 parent a8071a4 commit 9cdc905
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
21 changes: 21 additions & 0 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,27 @@ u3a_discount_noun(u3_noun som)
}
}

/* u3a_print_time: print microsecond time.
*/
void
u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d)
{
c3_assert( 0 != str_c );

c3_w sec_w = (mic_d / 1000000);
c3_w mec_w = (mic_d % 1000000) / 1000;
c3_w mic_w = (mic_d % 1000);

if ( sec_w ) {
sprintf(str_c, "%s s/%d.%03d.%03d", cap_c, sec_w, mec_w, mic_w);
}
else if ( mec_w ) {
sprintf(str_c, "%s ms/%d.%03d", cap_c, mec_w, mic_w);
}
else {
sprintf(str_c, "%s \xc2\xb5s/%d", cap_c, mic_w);
}
}

/* u3a_print_memory: print memory amount.
*/
Expand Down
5 changes: 5 additions & 0 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@
void
u3a_lop(c3_w lab_w);

/* u3a_print_time: print microsecond time.
*/
void
u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d);

/* u3a_print_memory(): print memory amount.
*/
void
Expand Down
6 changes: 3 additions & 3 deletions pkg/noun/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,8 +1736,8 @@ _n_hilt_hind(u3_noun tok, u3_noun pro)
u3_noun p_tok, q_tok;
if ( (c3y == u3r_cell(tok, &p_tok, &q_tok)) && (c3__bout == p_tok) ) {
u3_atom delta = u3ka_sub(u3i_chub(u3t_trace_time()), u3k(q_tok));
c3_c str_c[64];
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
c3_c str_c[64];
u3a_print_time(str_c, "took", u3r_chub(0, delta));
u3t_slog(u3nc(0, u3i_string(str_c)));
u3z(delta);
}
Expand Down Expand Up @@ -1820,7 +1820,7 @@ _n_hint_hind(u3_noun tok, u3_noun pro)

// format the timing report
c3_c str_c[64];
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
u3a_print_time(str_c, "took", u3r_chub(0, delta));

// join the timing report with the original tank from q_q_tok like so:
// "q_q_tok: report"
Expand Down

0 comments on commit 9cdc905

Please sign in to comment.