ref: 56cc98ba722d066c454b107a786b51cb740bd2b2
parent: 34be16ef74b0c991850ee82931e9bd21f01a0a4f
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Dec 13 12:51:52 EST 2021
check, dump: move dump functions from check.c to dump.c
--- a/check.c
+++ b/check.c
@@ -6,8 +6,6 @@
#include "dat.h"
#include "fns.h"
-char spc[128];
-
static int
isfree(vlong bp)
{
@@ -189,154 +187,4 @@
putblk(b);
}
return ok;
-}
-
-void
-rshowblk(int fd, Blk *b, int indent, int recurse)
-{
- Blk *c;
- int i;
- Kvp kv;
- Msg m;
-
- if(indent > sizeof(spc)/4)
- indent = sizeof(spc)/4;
- if(b == nil){
- fprint(fd, "NIL\n");
- return;
- }
- fprint(fd, "%.*s +{%B}\n", 4*indent, spc, b->bp);
- if(b->type == Tpivot){
- for(i = 0; i < b->nbuf; i++){
- getmsg(b, i, &m);
- fprint(fd, "%.*s[%03d]|%M\n", 4*indent, spc, i, &m);
- }
- }
- for(i = 0; i < b->nval; i++){
- getval(b, i, &kv);
- fprint(fd, "%.*s[%03d]|%P\n", 4*indent, spc, i, &kv);
- if(b->type == Tpivot){
- if((c = getblk(kv.bp, 0)) == nil)
- sysfatal("failed load: %r");
- if(recurse)
- rshowblk(fd, c, indent + 1, 1);
- putblk(c);
- }
- }
-}
-
-
-void
-initshow(void)
-{
- int i;
-
- memset(spc, ' ', sizeof(spc));
- for(i = 0; i < sizeof(spc); i += 4)
- spc[i] = '|';
-}
-
-void
-showblk(int fd, Blk *b, char *m, int recurse)
-{
- fprint(fd, "=== %s\n", m);
- rshowblk(fd, b, 0, recurse);
-}
-
-void
-showtree(int fd, Tree *t, char *m)
-{
- Blk *b;
- int h;
-
- fprint(fd, "=== [%s] %B\n", m, fs->snap.bp);
- fprint(fd, "\tht: %d\n", fs->snap.ht);
- fprint(fd, "\trt: %B\n", fs->snap.bp);
- b = getroot(t, &h);
- rshowblk(fd, b, 0, 1);
- putblk(b);
-}
-
-void
-showfs(int fd, char **ap, int na)
-{
- char *e, *name;
- Tree t;
-
- name = "main";
- if(na == 1)
- name = ap[0];
- if((e = opensnap(&t, name)) != nil){
- fprint(fd, "open %s: %s\n", name, e);
- return;
- }
- showtree(fd, &t, name);
-}
-
-void
-showsnap(int fd, char **, int)
-{
- showtree(fd, &fs->snap, "snaps");
-}
-
-void
-showcache(int fd, char**, int)
-{
- Bucket *bkt;
- Blk *b;
- int i;
-
- for(i = 0; i < fs->cmax; i++){
- bkt = &fs->cache[i];
- lock(bkt);
- if(bkt->b != nil)
- fprint(fd, "bkt%d\n", i);
- for(b = bkt->b; b != nil; b = b->hnext)
- if(b->ref != 1)
- fprint(fd, "\t%p[ref=%ld, t=%d] => %B\n", b, b->ref, b->type, b->bp);
- unlock(bkt);
- }
-}
-
-void
-showpath(int fd, Path *p, int np)
-{
-#define A(b) (b ? b->bp.addr : -1)
- int i;
- char *op[] = {
- [POmod] = "POmod",
- [POrot] = "POrot",
- [POsplit] = "POsplit",
- [POmerge] = "POmerge",
- };
-
- fprint(fd, "path:\n");
- for(i = 0; i < np; i++){
- fprint(fd, "\t[%d] ==>\n"
- "\t\t%s: b(%p)=%llx [%s]\n"
- "\t\tnl(%p)=%llx, nr(%p)=%llx\n"
- "\t\tidx=%d, midx=%d\n"
- "\t\tpullsz=%d, npull=%d, \n"
- "\t\tclear=(%d. %d)\n",
- i, op[p[i].op],
- p[i].b, A(p[i].b), (p[i].b == nil) ? "nil" : (p[i].b->type == Tleaf ? "leaf" : "pivot"),
- p[i].nl, A(p[i].nl),
- p[i].nr, A(p[i].nr),
- p[i].idx, p[i].midx,
- p[i].pullsz, p[i].npull,
- p[i].lo, p[i].hi);
- }
-}
-
-void
-showfree(int fd, char **, int)
-{
- Arange *r;
- int i;
-
- for(i = 0; i < fs->narena; i++){
- fprint(fd, "arena %d:\n", i);
- for(r = (Arange*)avlmin(fs->arenas[i].free); r != nil; r = (Arange*)avlnext(r))
- fprint(fd, "\t%llx+%llx\n", r->off, r->len);
- }
}
--- a/dump.c
+++ b/dump.c
@@ -8,6 +8,8 @@
#include "dat.h"
#include "fns.h"
+char spc[128];
+
static int
showkey(Fmt *fmt, Key *k)
{
@@ -205,4 +207,153 @@
q = va_arg(fmt->args, Qid);
return fmtprint(fmt, "(%llx %ld %d)", q.path, q.vers, q.type);
+}
+
+void
+rshowblk(int fd, Blk *b, int indent, int recurse)
+{
+ Blk *c;
+ int i;
+ Kvp kv;
+ Msg m;
+
+ if(indent > sizeof(spc)/4)
+ indent = sizeof(spc)/4;
+ if(b == nil){
+ fprint(fd, "NIL\n");
+ return;
+ }
+ fprint(fd, "%.*s +{%B}\n", 4*indent, spc, b->bp);
+ if(b->type == Tpivot){
+ for(i = 0; i < b->nbuf; i++){
+ getmsg(b, i, &m);
+ fprint(fd, "%.*s[%03d]|%M\n", 4*indent, spc, i, &m);
+ }
+ }
+ for(i = 0; i < b->nval; i++){
+ getval(b, i, &kv);
+ fprint(fd, "%.*s[%03d]|%P\n", 4*indent, spc, i, &kv);
+ if(b->type == Tpivot){
+ if((c = getblk(kv.bp, 0)) == nil)
+ sysfatal("failed load: %r");
+ if(recurse)
+ rshowblk(fd, c, indent + 1, 1);
+ putblk(c);
+ }
+ }
+}
+
+void
+showblk(int fd, Blk *b, char *m, int recurse)
+{
+ fprint(fd, "=== %s\n", m);
+ rshowblk(fd, b, 0, recurse);
+}
+
+void
+showtree(int fd, Tree *t, char *m)
+{
+ Blk *b;
+ int h;
+
+ fprint(fd, "=== [%s] %B\n", m, fs->snap.bp);
+ fprint(fd, "\tht: %d\n", fs->snap.ht);
+ fprint(fd, "\trt: %B\n", fs->snap.bp);
+ b = getroot(t, &h);
+ rshowblk(fd, b, 0, 1);
+ putblk(b);
+}
+
+void
+showfs(int fd, char **ap, int na)
+{
+ char *e, *name;
+ Tree t;
+
+ name = "main";
+ if(na == 1)
+ name = ap[0];
+ if((e = opensnap(&t, name)) != nil){
+ fprint(fd, "open %s: %s\n", name, e);
+ return;
+ }
+ showtree(fd, &t, name);
+}
+
+void
+showsnap(int fd, char **, int)
+{
+ showtree(fd, &fs->snap, "snaps");
+}
+
+void
+showcache(int fd, char**, int)
+{
+ Bucket *bkt;
+ Blk *b;
+ int i;
+
+ for(i = 0; i < fs->cmax; i++){
+ bkt = &fs->cache[i];
+ lock(bkt);
+ if(bkt->b != nil)
+ fprint(fd, "bkt%d\n", i);
+ for(b = bkt->b; b != nil; b = b->hnext)
+ if(b->ref != 1)
+ fprint(fd, "\t%p[ref=%ld, t=%d] => %B\n", b, b->ref, b->type, b->bp);
+ unlock(bkt);
+ }
+}
+
+void
+showpath(int fd, Path *p, int np)
+{
+#define A(b) (b ? b->bp.addr : -1)
+ int i;
+ char *op[] = {
+ [POmod] = "POmod",
+ [POrot] = "POrot",
+ [POsplit] = "POsplit",
+ [POmerge] = "POmerge",
+ };
+
+ fprint(fd, "path:\n");
+ for(i = 0; i < np; i++){
+ fprint(fd, "\t[%d] ==>\n"
+ "\t\t%s: b(%p)=%llx [%s]\n"
+ "\t\tnl(%p)=%llx, nr(%p)=%llx\n"
+ "\t\tidx=%d, midx=%d\n"
+ "\t\tpullsz=%d, npull=%d, \n"
+ "\t\tclear=(%d. %d)\n",
+ i, op[p[i].op],
+ p[i].b, A(p[i].b), (p[i].b == nil) ? "nil" : (p[i].b->type == Tleaf ? "leaf" : "pivot"),
+ p[i].nl, A(p[i].nl),
+ p[i].nr, A(p[i].nr),
+ p[i].idx, p[i].midx,
+ p[i].pullsz, p[i].npull,
+ p[i].lo, p[i].hi);
+ }
+}
+
+void
+showfree(int fd, char **, int)
+{
+ Arange *r;
+ int i;
+
+ for(i = 0; i < fs->narena; i++){
+ fprint(fd, "arena %d:\n", i);
+ for(r = (Arange*)avlmin(fs->arenas[i].free); r != nil; r = (Arange*)avlnext(r))
+ fprint(fd, "\t%llx+%llx\n", r->off, r->len);
+ }
+}
+
+void
+initshow(void)
+{
+ int i;
+
+ memset(spc, ' ', sizeof(spc));
+ for(i = 0; i < sizeof(spc); i += 4)
+ spc[i] = '|';
}