mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-09-20 15:08:34 +03:00
space profiling works with U3_MEMORY_DEBUG
This commit is contained in:
parent
b84aa72678
commit
3155535c80
6
i/n/a.h
6
i/n/a.h
@ -6,7 +6,7 @@
|
||||
**/
|
||||
/* U3_MEMORY_DEBUG: add debugging information to heap. Breaks image.
|
||||
*/
|
||||
# define U3_MEMORY_DEBUG
|
||||
# undef U3_MEMORY_DEBUG
|
||||
|
||||
|
||||
/** Constants.
|
||||
@ -264,10 +264,6 @@
|
||||
c3_global c3_w u3_Code;
|
||||
#endif
|
||||
|
||||
/* u3_Prof: memory profile.
|
||||
*/
|
||||
c3_global u3_weak u3_Prof;
|
||||
|
||||
# define u3_Loom ((c3_w *)(void *)U3_OS_LoomBase)
|
||||
|
||||
/** Functions.
|
||||
|
2
i/n/v.h
2
i/n/v.h
@ -27,6 +27,8 @@
|
||||
u3_noun sen; // instance string
|
||||
u3_noun own; // owner list
|
||||
|
||||
u3_noun sac; // space profiling
|
||||
|
||||
u3_noun roe; // temporary unsaved events
|
||||
u3_noun key; // log key, or 0
|
||||
|
||||
|
19
n/a.c
19
n/a.c
@ -1310,9 +1310,13 @@ u3a_mark_ptr(void* ptr_v)
|
||||
c3_w siz_w;
|
||||
|
||||
#ifdef U3_MEMORY_DEBUG
|
||||
if ( box_u->eus_w == 0 ) {
|
||||
if ( 0 == box_u->eus_w ) {
|
||||
siz_w = box_u->siz_w;
|
||||
}
|
||||
}
|
||||
else if ( 0xffffffff == box_u->eus_w ) { // see _raft_prof()
|
||||
siz_w = 0xffffffff;
|
||||
box_u->eus_w = 0;
|
||||
}
|
||||
else {
|
||||
siz_w = 0;
|
||||
}
|
||||
@ -1331,6 +1335,10 @@ u3a_mark_ptr(void* ptr_v)
|
||||
use_ws -= 1;
|
||||
siz_w = 0;
|
||||
}
|
||||
// else if ( 0x80000000 == (c3_w)use_ws ) { // see _raft_prof()
|
||||
// use_ws = -1;
|
||||
// siz_w = 0xffffffff;
|
||||
// }
|
||||
else {
|
||||
use_ws = -1;
|
||||
siz_w = box_u->siz_w;
|
||||
@ -1370,7 +1378,7 @@ u3a_mark_noun(u3_noun som)
|
||||
c3_w* dog_w = u3a_to_ptr(som);
|
||||
c3_w new_w = u3a_mark_ptr(dog_w);
|
||||
|
||||
if ( 0 == new_w ) {
|
||||
if ( 0 == new_w || 0xffffffff == new_w ) { // see u3a_mark_ptr()
|
||||
return siz_w;
|
||||
}
|
||||
else {
|
||||
@ -1471,7 +1479,10 @@ u3a_sweep(void)
|
||||
(u3_noun)u3a_to_pom(u3a_outa(u3a_boxto(box_w))),
|
||||
((u3a_noun *)(u3a_boxto(box_w)))->mug_w,
|
||||
box_u->use_w, box_u->eus_w);
|
||||
// u3m_p("weak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
|
||||
//static int xuc_i = 0;
|
||||
//if ( 2 != ++xuc_i && 3 != xuc_i ) {
|
||||
// u3m_p("weak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
|
||||
//}
|
||||
}
|
||||
weq_w += box_u->siz_w;
|
||||
}
|
||||
|
2
n/h.c
2
n/h.c
@ -634,7 +634,7 @@ u3h_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun))
|
||||
c3_w
|
||||
_ch_mark_buck(u3h_buck* hab_u)
|
||||
{
|
||||
c3_w tot_w = 0;
|
||||
c3_w tot_w = 0;
|
||||
c3_w i_w;
|
||||
|
||||
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
|
||||
|
5
n/m.c
5
n/m.c
@ -869,11 +869,6 @@ u3m_soft_top(c3_w sec_w, // timer seconds
|
||||
/* Make sure the inner routine did not create garbage.
|
||||
*/
|
||||
if ( u3C.wag_w & u3o_debug_ram ) {
|
||||
if ( u3_none != u3_Prof ) {
|
||||
fprintf(stderr,"should be checking!\r\n");
|
||||
u3z(u3_Prof);
|
||||
u3_Prof = u3_none;
|
||||
}
|
||||
u3m_grab(pro, u3_none);
|
||||
}
|
||||
|
||||
|
1
n/v.c
1
n/v.c
@ -79,6 +79,7 @@ u3v_start(u3_noun now)
|
||||
{
|
||||
u3v_time(now);
|
||||
u3v_numb();
|
||||
u3A->sac = u3_nul;
|
||||
|
||||
{
|
||||
c3_c* wen_c = u3r_string(u3A->wen);
|
||||
|
1
v/loop.c
1
v/loop.c
@ -420,7 +420,6 @@ u3_lo_open(void)
|
||||
//
|
||||
// Assumption: there are no noun roots outside u3A.
|
||||
//
|
||||
u3_Prof = u3_none;
|
||||
u3m_grab(u3_none);
|
||||
}
|
||||
#if 0
|
||||
|
194
v/raft.c
194
v/raft.c
@ -1691,6 +1691,198 @@ _raft_kick_all(u3_noun vir)
|
||||
}
|
||||
}
|
||||
|
||||
/* _raft_spac(): print n spaces.
|
||||
*/
|
||||
void _raft_spac(c3_w n)
|
||||
{
|
||||
for (; n > 0; n--)
|
||||
(fprintf(stderr," "));
|
||||
}
|
||||
|
||||
/* _raft_print_memory: print memory amount. cf u3a_print_memory().
|
||||
*/
|
||||
void
|
||||
_raft_print_memory(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(stderr, "GB/%d.%03d.%03d.%03d\r\n",
|
||||
gib_w, mib_w, kib_w, bib_w));
|
||||
}
|
||||
else if ( mib_w ) {
|
||||
(fprintf(stderr, "MB/%d.%03d.%03d\r\n", mib_w, kib_w, bib_w));
|
||||
}
|
||||
else if ( kib_w ) {
|
||||
(fprintf(stderr, "KB/%d.%03d\r\n", kib_w, bib_w));
|
||||
}
|
||||
else {
|
||||
(fprintf(stderr, "B/%d\r\n", bib_w));
|
||||
}
|
||||
}
|
||||
|
||||
/* _raft_prof_noun(): get memory usage, in words, of noun. RETAIN.
|
||||
*/
|
||||
c3_w
|
||||
_raft_prof_noun(u3p(u3h_root) hax, u3_noun non, c3_t dud)
|
||||
{
|
||||
return 0;
|
||||
/*
|
||||
u3_weak got = u3h_git(hax, dud ? non & 0x7fffffff : non);
|
||||
|
||||
if (u3_none != got) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
c3_w res;
|
||||
|
||||
if (!(non & 0x80000000)) {
|
||||
res = 1;
|
||||
}
|
||||
if (_(u3ud(non))) {
|
||||
res = 3 + 3 + u3r_met(5, non);
|
||||
}
|
||||
else {
|
||||
res = 3 + 2
|
||||
+ _raft_prof_noun(hax, u3h(non), dud)
|
||||
+ _raft_prof_noun(hax, u3t(non), dud);
|
||||
}
|
||||
|
||||
u3h_put(hax, dud ? non & 0x7fffffff : non, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* _raft_prof(): print memory profile. RETAIN.
|
||||
*/
|
||||
c3_w
|
||||
_raft_prof(u3p(u3h_root) hax, 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)) {
|
||||
_raft_spac(den);
|
||||
(fprintf(stderr, "mistyped mass\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
if (c3y == h_mas) {
|
||||
_raft_spac(den);
|
||||
_raft_print_memory(_raft_prof_noun(hax, t_mas, 0));
|
||||
_raft_spac(den);
|
||||
_raft_print_memory(_raft_prof_noun(hax, t_mas, 1));
|
||||
_raft_spac(den);
|
||||
tot_w += u3a_mark_noun(t_mas);
|
||||
_raft_print_memory(tot_w);
|
||||
|
||||
/* The basic issue here is that t_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 t_mas
|
||||
* to appear to appear unmarked, but its children should
|
||||
* be already marked.
|
||||
*/
|
||||
if ( _(u3a_is_dog(t_mas)) ) {
|
||||
u3a_box* box_u = u3a_botox(u3a_to_ptr(t_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->siz_w ) {
|
||||
box_u->siz_w = 0x80000000;
|
||||
}
|
||||
else {
|
||||
box_u->siz_w -= 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return tot_w;
|
||||
}
|
||||
else if (c3n == h_mas) {
|
||||
u3_noun it_mas, tt_mas, pit_mas, qit_mas;
|
||||
while (u3_nul != t_mas)
|
||||
{
|
||||
_raft_spac(den);
|
||||
if (c3n == u3r_cell(t_mas, &it_mas, &tt_mas)) {
|
||||
(fprintf(stderr, "mistyped mass list\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
else if (c3n == u3r_cell(it_mas, &pit_mas, &qit_mas)) {
|
||||
(fprintf(stderr, "mistyped mass list element\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
else {
|
||||
c3_c* pit_c = u3m_pretty(pit_mas);
|
||||
(fprintf(stderr, "%s\r\n", pit_c));
|
||||
free(pit_c);
|
||||
|
||||
tot_w += _raft_prof(hax, den+2, qit_mas);
|
||||
|
||||
t_mas = tt_mas;
|
||||
}
|
||||
}
|
||||
return tot_w;
|
||||
}
|
||||
else {
|
||||
_raft_spac(den);
|
||||
(fprintf(stderr, "mistyped mass head\r\n"));
|
||||
u3m_p("mas",h_mas);
|
||||
return tot_w;
|
||||
}
|
||||
}
|
||||
|
||||
/* _raft_grab(): garbage collect, checking for profiling. RETAIN.
|
||||
*/
|
||||
static void
|
||||
_raft_grab(u3_noun ova)
|
||||
{
|
||||
if ( u3_nul != u3A->sac ) {
|
||||
c3_w usr_w = 0, ova_w = 0, sac_w = 0, utv_w = 0, utm_w = 0, wep_w = 0;
|
||||
|
||||
usr_w = _raft_prof(u3_nul, 0, u3A->sac);
|
||||
fprintf(stderr, "total userspace: ");
|
||||
_raft_print_memory(usr_w);
|
||||
|
||||
ova_w = u3a_mark_noun(ova);
|
||||
fprintf(stderr, "effects list: ");
|
||||
_raft_print_memory(ova_w);
|
||||
|
||||
sac_w = u3a_mark_noun(u3A->sac);
|
||||
fprintf(stderr, "space profile: ");
|
||||
_raft_print_memory(sac_w);
|
||||
|
||||
utv_w = u3v_mark();
|
||||
fprintf(stderr, "arvo stuff: ");
|
||||
_raft_print_memory(utv_w);
|
||||
|
||||
utm_w = u3m_mark();
|
||||
fprintf(stderr, "road stuff: ");
|
||||
_raft_print_memory(utm_w);
|
||||
|
||||
fprintf(stderr, "total marked: ");
|
||||
_raft_print_memory(usr_w + ova_w + sac_w + utv_w + utm_w);
|
||||
|
||||
wep_w = u3a_sweep();
|
||||
fprintf(stderr, "sweep: ");
|
||||
_raft_print_memory(wep_w);
|
||||
|
||||
u3z(u3A->sac);
|
||||
u3A->sac = u3_nul;
|
||||
} else {
|
||||
// u3m_grab(ova, u3_none);
|
||||
}
|
||||
}
|
||||
|
||||
int FOO;
|
||||
|
||||
/* u3_raft_work(): work.
|
||||
@ -1803,6 +1995,8 @@ u3_raft_work(void)
|
||||
_raft_kick_all(vir);
|
||||
egg_u->did = c3y;
|
||||
egg_u->vir = 0;
|
||||
|
||||
_raft_grab(ova);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
165
v/reck.c
165
v/reck.c
@ -66,138 +66,6 @@ _reck_lily(u3_noun fot, u3_noun txt, c3_l* tid_l)
|
||||
}
|
||||
}
|
||||
|
||||
/* _reck_spac(): print n spaces.
|
||||
*/
|
||||
void _reck_spac(c3_w n)
|
||||
{
|
||||
for (; n > 0; n--)
|
||||
(fprintf(stderr," "));
|
||||
}
|
||||
|
||||
/* _reck_print_memory: print memory amount. cf u3a_print_memory().
|
||||
*/
|
||||
void
|
||||
_reck_print_memory(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(stderr, "GB/%d.%03d.%03d.%03d\r\n",
|
||||
gib_w, mib_w, kib_w, bib_w));
|
||||
}
|
||||
else if ( mib_w ) {
|
||||
(fprintf(stderr, "MB/%d.%03d.%03d\r\n", mib_w, kib_w, bib_w));
|
||||
}
|
||||
else if ( kib_w ) {
|
||||
(fprintf(stderr, "KB/%d.%03d\r\n", kib_w, bib_w));
|
||||
}
|
||||
else {
|
||||
(fprintf(stderr, "B/%d\r\n", bib_w));
|
||||
}
|
||||
}
|
||||
|
||||
/* _reck_meme_noun(): get memory usage, in words, of noun. RETAIN.
|
||||
*/
|
||||
c3_w
|
||||
_reck_meme_noun(u3p(u3h_root) hax, u3_noun non, c3_t dud)
|
||||
{
|
||||
return 0;
|
||||
/*
|
||||
u3_weak got = u3h_git(hax, dud ? non & 0x7fffffff : non);
|
||||
|
||||
if (u3_none != got) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
c3_w res;
|
||||
|
||||
if (!(non & 0x80000000)) {
|
||||
res = 1;
|
||||
}
|
||||
if (_(u3ud(non))) {
|
||||
res = 3 + 3 + u3r_met(5, non);
|
||||
}
|
||||
else {
|
||||
res = 3 + 2
|
||||
+ _reck_meme_noun(hax, u3h(non), dud)
|
||||
+ _reck_meme_noun(hax, u3t(non), dud);
|
||||
}
|
||||
|
||||
u3h_put(hax, dud ? non & 0x7fffffff : non, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* _reck_noun_grab(): get memory usage, in words, of noun from GC. RETAIN.
|
||||
* XXX what about unmarking stuff? what's a GC cycle?
|
||||
*/
|
||||
c3_w
|
||||
_reck_noun_grab(u3_noun non)
|
||||
{
|
||||
return u3a_mark_noun(non);
|
||||
}
|
||||
|
||||
/* _reck_meme_prof(): print memory profile. RETAIN.
|
||||
*/
|
||||
c3_w
|
||||
_reck_meme_prof(u3p(u3h_root) hax, 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)) {
|
||||
_reck_spac(den);
|
||||
(fprintf(stderr, "mistyped mass\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
if (c3y == h_mas) {
|
||||
_reck_spac(den);
|
||||
_reck_print_memory(_reck_meme_noun(hax, t_mas, false));
|
||||
_reck_spac(den);
|
||||
_reck_print_memory(_reck_meme_noun(hax, t_mas, true));
|
||||
_reck_spac(den);
|
||||
tot_w += _reck_noun_grab(t_mas);
|
||||
_reck_print_memory(tot_w);
|
||||
return tot_w;
|
||||
}
|
||||
else if (c3n == h_mas) {
|
||||
u3_noun it_mas, tt_mas, pit_mas, qit_mas;
|
||||
while (u3_nul != t_mas)
|
||||
{
|
||||
_reck_spac(den);
|
||||
if (c3n == u3r_cell(t_mas, &it_mas, &tt_mas)) {
|
||||
(fprintf(stderr, "mistyped mass list\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
else if (c3n == u3r_cell(it_mas, &pit_mas, &qit_mas)) {
|
||||
(fprintf(stderr, "mistyped mass list element\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
else {
|
||||
c3_c* pit_c = u3m_pretty(pit_mas);
|
||||
(fprintf(stderr, "%s\r\n", pit_c));
|
||||
free(pit_c);
|
||||
|
||||
tot_w += _reck_meme_prof(hax, den+2, qit_mas);
|
||||
|
||||
t_mas = tt_mas;
|
||||
}
|
||||
}
|
||||
return tot_w;
|
||||
}
|
||||
else {
|
||||
_reck_spac(den);
|
||||
(fprintf(stderr, "mistyped mass head\r\n"));
|
||||
return tot_w;
|
||||
}
|
||||
}
|
||||
|
||||
/* _reck_kick_term(): apply terminal outputs.
|
||||
*/
|
||||
static u3_noun
|
||||
@ -245,36 +113,7 @@ _reck_kick_term(u3_noun pox, c3_l tid_l, u3_noun fav)
|
||||
|
||||
case c3__mass: p_fav = u3t(fav);
|
||||
{
|
||||
u3_Prof = u3k(p_fav);
|
||||
//c3_w usr_w, utm_w, utv_w, ext_w, wep_w;
|
||||
//uL(fprintf(uH, "memory profile:\r\n"));
|
||||
|
||||
//// u3p(u3h_root) hax = u3h_new();
|
||||
|
||||
//usr_w = _reck_meme_prof(u3_nul, 0, p_fav);
|
||||
//(fprintf(stderr, "total userspace: "));
|
||||
//_reck_print_memory(usr_w);
|
||||
|
||||
//utm_w = u3m_mark();
|
||||
//(fprintf(stderr, "u3m stuff: "));
|
||||
//_reck_print_memory(utm_w);
|
||||
|
||||
//utv_w = u3v_mark();
|
||||
//(fprintf(stderr, "u3v stuff: "));
|
||||
//_reck_print_memory(utv_w);
|
||||
|
||||
//ext_w = u3a_mark_noun(pox) + u3a_mark_noun(fav);
|
||||
//(fprintf(stderr, "extra stuff: "));
|
||||
//_reck_print_memory(ext_w);
|
||||
|
||||
//(fprintf(stderr, "total memory: "));
|
||||
//_reck_print_memory(usr_w + utm_w + utv_w + ext_w);
|
||||
|
||||
//wep_w = u3a_sweep();
|
||||
//(fprintf(stderr, "sweep memory: "));
|
||||
//_reck_print_memory(wep_w);
|
||||
|
||||
//// u3h_free(hax);
|
||||
u3A->sac = u3k(p_fav);
|
||||
|
||||
u3z(pox); u3z(fav); return c3y;
|
||||
} break;
|
||||
@ -400,7 +239,7 @@ _reck_kick_spec(u3_noun pox, u3_noun fav)
|
||||
u3z(pox); u3z(fav); return c3n;
|
||||
}
|
||||
else switch ( it_pox ) {
|
||||
default: return c3n;
|
||||
default: u3z(pox); u3z(fav); return c3n;
|
||||
|
||||
case c3__http: {
|
||||
u3_noun pud = tt_pox;
|
||||
|
Loading…
Reference in New Issue
Block a user