From 0ef473194045273f7dfe73f109f0a65e683ed027 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 6 Feb 2019 23:43:09 -0500 Subject: [PATCH] adds (failing) |mass from raft --- vere/serf.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 225 insertions(+), 3 deletions(-) diff --git a/vere/serf.c b/vere/serf.c index 25c46c1e61..c3ff263874 100644 --- a/vere/serf.c +++ b/vere/serf.c @@ -68,6 +68,208 @@ ** == == :: */ +/* _serf_space(): print n spaces. +*/ +void _serf_space(FILE* fil_u, c3_w n) +{ + for (; n > 0; n--) + (fprintf(fil_u," ")); +} + +/* _serf_print_memory(): print memory amount. +** +** Helper for _serf_prof(), just an un-captioned u3a_print_memory(). +*/ +void +_serf_print_memory(FILE* fil_u, c3_w wor_w) +{ + c3_w byt_w = (wor_w * 4); + c3_w gib_w = (byt_w / 1000000000); + c3_w mib_w = (byt_w % 1000000000) / 1000000; + c3_w kib_w = (byt_w % 1000000) / 1000; + c3_w bib_w = (byt_w % 1000); + + if ( gib_w ) { + (fprintf(fil_u, "GB/%d.%03d.%03d.%03d\r\n", + gib_w, mib_w, kib_w, bib_w)); + } + else if ( mib_w ) { + (fprintf(fil_u, "MB/%d.%03d.%03d\r\n", mib_w, kib_w, bib_w)); + } + else if ( kib_w ) { + (fprintf(fil_u, "KB/%d.%03d\r\n", kib_w, bib_w)); + } + else { + (fprintf(fil_u, "B/%d\r\n", bib_w)); + } +} + +/* _serf_prof(): print memory profile. RETAIN. +*/ +c3_w +_serf_prof(FILE* fil_u, c3_w den, u3_noun mas) +{ + c3_w tot_w = 0; + u3_noun h_mas, t_mas; + + if ( c3n == u3r_cell(mas, &h_mas, &t_mas) ) { + _serf_space(fil_u, den); + fprintf(fil_u, "mistyped mass\r\n"); + return tot_w; + } + else if ( _(u3du(h_mas)) ) { + _serf_space(fil_u, den); + fprintf(fil_u, "mistyped mass head\r\n"); + { + c3_c* lab_c = u3m_pretty(h_mas); + fprintf(fil_u, "h_mas: %s", lab_c); + free(lab_c); + } + return tot_w; + } + else { + _serf_space(fil_u, den); + + { + c3_c* lab_c = u3m_pretty(h_mas); + fprintf(fil_u, "%s: ", lab_c); + free(lab_c); + } + + u3_noun it_mas, tt_mas; + + if ( c3n == u3r_cell(t_mas, &it_mas, &tt_mas) ) { + fprintf(fil_u, "mistyped mass tail\r\n"); + return tot_w; + } + else if ( c3y == it_mas ) { + tot_w += u3a_mark_noun(tt_mas); + _serf_print_memory(fil_u, tot_w); + +#if 1 + /* The basic issue here is that tt_mas is included in + * u3A->sac, so they can't both be roots in the normal + * sense. When we mark u3A->sac later on, we want tt_mas + * to appear unmarked, but its children should be already + * marked. + */ + if ( _(u3a_is_dog(tt_mas)) ) { + u3a_box* box_u = u3a_botox(u3a_to_ptr(tt_mas)); +#ifdef U3_MEMORY_DEBUG + if ( 1 == box_u->eus_w ) { + box_u->eus_w = 0xffffffff; + } + else { + box_u->eus_w -= 1; + } +#else + if ( -1 == (c3_w)box_u->use_w ) { + box_u->use_w = 0x80000000; + } + else { + box_u->use_w += 1; + } +#endif + } +#endif + + return tot_w; + } + else if ( c3n == it_mas ) { + fprintf(fil_u, "\r\n"); + + while ( _(u3du(tt_mas)) ) { + tot_w += _serf_prof(fil_u, den+2, u3h(tt_mas)); + tt_mas = u3t(tt_mas); + } + + _serf_space(fil_u, den); + fprintf(fil_u, "--"); + _serf_print_memory(fil_u, tot_w); + + return tot_w; + + } + else { + _serf_space(fil_u, den); + fprintf(fil_u, "mistyped (strange) mass tail\r\n"); + return tot_w; + } + } +} + +/* _serf_grab(): garbage collect, checking for profiling. RETAIN. +*/ +static void +_serf_grab(u3_noun sac, u3_noun ovo, u3_noun vir) +{ + if ( u3_nul == sac) { + if ( u3C.wag_w & (u3o_debug_ram | u3o_check_corrupt) ) { + u3m_grab(sac, ovo, vir, u3_none); + } + } + else { + c3_w usr_w = 0, man_w = 0, sac_w = 0, ova_w = 0, vir_w = 0; + + FILE* fil_u; + +#ifdef U3_MEMORY_LOG + { + u3_noun wen = u3dc("scot", c3__da, u3k(u3A->now)); + c3_c* wen_c = u3r_string(wen); + + c3_c nam_c[2048]; + snprintf(nam_c, 2048, "%s/.urb/put/mass", u3P.dir_c); + + struct stat st; + if ( -1 == stat(nam_c, &st) ) { + mkdir(nam_c, 0700); + } + + c3_c man_c[2048]; + snprintf(man_c, 2048, "%s/%s.txt", nam_c, wen_c); + + fil_u = fopen(man_c, "w"); + fprintf(fil_u, "%s\r\n", wen_c); + + free(wen_c); + u3z(wen); + } +#else + { + fil_u = stderr; + } +#endif + + c3_assert( u3R == &(u3H->rod_u) ); + + fprintf(fil_u, "\r\n"); + usr_w = _serf_prof(fil_u, 0, sac); + u3a_print_memory(fil_u, "total userspace", usr_w); + + man_w = u3m_mark(fil_u); + + sac_w = u3a_mark_noun(sac); + u3a_print_memory(fil_u, "space profile", sac_w); + + ova_w = u3a_mark_noun(ovo); + u3a_print_memory(fil_u, "event", ova_w); + + vir_w = u3a_mark_noun(vir); + u3a_print_memory(fil_u, "effects", vir_w); + + u3a_print_memory(fil_u, "total marked", usr_w + man_w + sac_w + ova_w + vir_w); + + u3a_print_memory(fil_u, "sweep", u3a_sweep()); + +#ifdef U3_MEMORY_LOG + { + fclose(fil_u); + } +#endif + } +} + /* _serf_fail(): failure stub. */ static void @@ -127,8 +329,6 @@ _serf_lame(c3_d evt_d, u3_noun ovo, u3_noun why, u3_noun tan) static void _serf_sure(u3_noun ovo, u3_noun vir, u3_noun cor) { - u3z(ovo); - u3z(u3A->roc); u3A->roc = cor; @@ -160,7 +360,29 @@ _serf_sure(u3_noun ovo, u3_noun vir, u3_noun cor) } } - _serf_send_complete(vir); + u3_noun sac = u3_nul; + + // intercept |mass + // + { + u3_noun riv = vir; + + while ( u3_nul != riv ) { + u3_noun fec = u3t(u3h(riv)); + + if ( c3__mass == u3h(fec) ) { + sac = u3k(u3t(fec)); + break; + } + + riv = u3t(riv); + } + } + + _serf_send_complete(u3k(vir)); + _serf_grab(sac, ovo, vir); + + u3z(sac); u3z(ovo); u3z(vir); } /* _serf_poke_live(): apply event.