From 6f4d00ee45693290fae042b27536b54f77b96acd Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 23 Sep 2013 23:00:39 +0200 Subject: fossil: import from plan 9 R=rsc https://codereview.appspot.com/7988047 --- src/cmd/fossil/srcload.c | 270 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/cmd/fossil/srcload.c (limited to 'src/cmd/fossil/srcload.c') diff --git a/src/cmd/fossil/srcload.c b/src/cmd/fossil/srcload.c new file mode 100644 index 00000000..8cf63b4f --- /dev/null +++ b/src/cmd/fossil/srcload.c @@ -0,0 +1,270 @@ +#include "stdinc.h" +#include +#include "dat.h" +#include "fns.h" +#include "error.h" + +int num = 100; +int length = 20*1024; +int block= 1024; +int bush = 4; +int iter = 100; +Biobuf *bout; +int maxdepth; + +Source *mkroot(Cache*); +void new(Source*, int trace, int); +int delete(Source*); +int count(Source *s, int); +void stats(Source *s); +void dump(Source *s, int ident, ulong entry); +static void bench(Source *r); + +void +main(int argc, char *argv[]) +{ + int i; + Fs *fs; + int csize = 1000; + ulong t; + Source *r; + + ARGBEGIN{ + case 'i': + iter = atoi(ARGF()); + break; + case 'n': + num = atoi(ARGF()); + break; + case 'l': + length = atoi(ARGF()); + break; + case 'b': + block = atoi(ARGF()); + break; + case 'u': + bush = atoi(ARGF()); + break; + case 'c': + csize = atoi(ARGF()); + break; + }ARGEND; + + vtAttach(); + + bout = vtMemAllocZ(sizeof(Biobuf)); + Binit(bout, 1, OWRITE); + + fmtinstall('V', vtScoreFmt); + fmtinstall('R', vtErrFmt); + + fs = fsOpen(argv[0], nil, csize, OReadWrite); + if(fs == nil) + sysfatal("could not open fs: %r"); + + t = time(0); + + srand(0); + + r = fs->source; + dump(r, 0, 0); + + fprint(2, "count = %d\n", count(r, 1)); + for(i=0; i maxdepth) + maxdepth = depth; + + Bflush(bout); + + n = sourceGetDirSize(s); + for(i=0; idsize, 1+frand()>.5, 0); + if(ss == nil){ + Bprint(bout, "could not create directory: %R\n"); + return; + } + if(trace){ + int j; + for(j=1; joffset); + } + sourceClose(ss); +} + +int +delete(Source *s) +{ + int i, n; + Source *ss; + + n = sourceGetDirSize(s); + /* check if empty */ + for(i=0; idir && delete(ss)){ + sourceClose(ss); + return 1; + } + if(1) + break; + sourceClose(ss); + } + + + sourceRemove(ss); + return 1; +} + +void +dump(Source *s, int ident, ulong entry) +{ + ulong i, n; + Source *ss; + Entry e; + + for(i=0; idir){ + Bprint(bout, " data size: %llud\n", e.size); + return; + } + n = sourceGetDirSize(s); + Bprint(bout, " dir size: %lud\n", n); + for(i=0; i max) + max = c; + sourceClose(ss); + } +fprint(2, "count = %d top = %d depth=%d maxcount %d\n", cc, n, maxdepth, max); +} -- cgit v1.2.3