Skip to content

Commit c986e5a

Browse files
committed
Add a /dump-series refinement to STATS
This is a debugging utility to dump all series in a pool. If the pool id is negative, all series in the system will be dumped >> stats/dump-series -1; dump all series in the system ... >> stats/dump-series 4 ;dump all series in pool 4 ...
1 parent 836bd49 commit c986e5a

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

src/boot/natives.r

+1
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ stats: native [
929929
/profile {Returns profiler object}
930930
/timer {High resolution time difference from start}
931931
/evals {Number of values evaluated by interpreter}
932+
/dump-series pool-id [integer!] {Dump all series in pool pool-id, -1 for all pools}
932933
]
933934

934935
do-codec: native [

src/core/d-dump.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
**
2828
***********************************************************************/
2929

30+
#include <stdio.h>
3031
#include "sys-core.h"
3132

3233

@@ -49,9 +50,9 @@
4950
SERIES_REST(series),
5051
SERIES_FLAGS(series)
5152
);
52-
if (SERIES_WIDE(series) == sizeof(REBVAL))
53+
if (SERIES_WIDE(series) == sizeof(REBVAL)) {
5354
Dump_Values(BLK_HEAD(series), SERIES_TAIL(series));
54-
else
55+
} else
5556
Dump_Bytes(series->data, (SERIES_TAIL(series)+1) * SERIES_WIDE(series));
5657
}
5758

@@ -122,6 +123,7 @@
122123

123124
cp = buf;
124125
for (l = 0; l < count; l++) {
126+
REBVAL *val = (REBVAL*)bp;
125127
cp = Form_Hex_Pad(cp, l, 8);
126128

127129
*cp++ = ':';
@@ -137,8 +139,13 @@
137139
cp = Form_Hex_Pad(cp, *bp++, 8);
138140
*cp++ = ' ';
139141
}
142+
n = 0;
143+
if (IS_WORD((REBVAL*)val) || IS_GET_WORD((REBVAL*)val) || IS_SET_WORD((REBVAL*)val)) {
144+
char * name = Get_Word_Name((REBVAL*)val);
145+
n = snprintf(cp, sizeof(buf) - (cp - buf), " (%s)", name);
146+
}
140147

141-
*cp = 0;
148+
*(cp + n) = 0;
142149
Debug_Str(buf);
143150
cp = buf;
144151
}

src/core/m-gc.c

+1
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ static void Mark_Series(REBSER *series, REBCNT depth);
746746
}
747747

748748

749+
749750
/***********************************************************************
750751
**
751752
*/ void Save_Series(REBSER *series)

src/core/m-pools.c

+45
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,51 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
704704
}
705705
}
706706

707+
/***********************************************************************
708+
**
709+
*/ void Dump_Series_In_Pool(int pool_id)
710+
/*
711+
** Dump all series in the pool @pool_id, -1 for all pools
712+
**
713+
***********************************************************************/
714+
{
715+
REBSEG *seg;
716+
REBSER *series;
717+
REBCNT count;
718+
REBCNT n = 0;
719+
720+
for (seg = Mem_Pools[SERIES_POOL].segs; seg; seg = seg->next) {
721+
series = (REBSER *) (seg + 1);
722+
for (count = Mem_Pools[SERIES_POOL].units; count > 0; count--) {
723+
SKIP_WALL(series);
724+
if (!SERIES_FREED(series)) {
725+
if (pool_id < 0 || FIND_POOL(SERIES_TOTAL(series)) == pool_id) {
726+
Debug_Fmt(
727+
Str_Dump[0], //"%s Series %x %s: Wide: %2d Size: %6d - Bias: %d Tail: %d Rest: %d Flags: %x"
728+
"Dump",
729+
series,
730+
(SERIES_LABEL(series) ? SERIES_LABEL(series) : "-"),
731+
SERIES_WIDE(series),
732+
SERIES_TOTAL(series),
733+
SERIES_BIAS(series),
734+
SERIES_TAIL(series),
735+
SERIES_REST(series),
736+
SERIES_FLAGS(series)
737+
);
738+
//Dump_Series(series, "Dump");
739+
if (SERIES_WIDE(series) == sizeof(REBVAL)) {
740+
Debug_Values(BLK_HEAD(series), SERIES_TAIL(series), 1024); /* FIXME limit */
741+
} else{
742+
Dump_Bytes(series->data, (SERIES_TAIL(series)+1) * SERIES_WIDE(series));
743+
}
744+
}
745+
}
746+
series++;
747+
SKIP_WALL(series);
748+
}
749+
}
750+
}
751+
707752

708753
/***********************************************************************
709754
**

src/core/n-system.c

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@
162162
return R_RET;
163163
}
164164

165+
if (D_REF(5)) {
166+
REBVAL *pool_id = D_ARG(6);
167+
Dump_Series_In_Pool(VAL_INT32(pool_id));
168+
return R_NONE;
169+
}
170+
165171
if (D_REF(1)) flags = 3;
166172
n = Inspect_Series(flags);
167173

0 commit comments

Comments
 (0)