#include "lib/lib.h"
#include "lib/fastbuf.h"
#include "lib/mempool.h"
+#include "lib/stkstring.h"
#include "lib/sorter/common.h"
#include <string.h>
#include <sys/time.h>
#include <time.h>
-#include <alloca.h>
-#define F_SIZE(x) ({ byte *buf = alloca(16); format_size(buf, x); buf; })
-#define F_BSIZE(b) F_SIZE(sbuck_size(b))
+#define F_BSIZE(b) stk_fsize(sbuck_size(b))
static u64
sorter_clock(void)
ASSERT(join->runs == 2);
join->runs--;
join_size = sbuck_size(join) - join_size;
- SORT_TRACE("Mergesort pass %d (final run, %s, %dMB/s)", pass, F_SIZE(join_size), sorter_speed(ctx, join_size));
+ SORT_TRACE("Mergesort pass %d (final run, %s, %dMB/s)", pass, stk_fsize(join_size), sorter_speed(ctx, join_size));
sbuck_drop(ins[0]);
sbuck_drop(ins[1]);
return;
}
SORT_TRACE("Radix split (%d buckets, %s min, %s max, %s avg, %dMB/s)", nbuck,
- F_SIZE(min), F_SIZE(max), F_SIZE(sum / nbuck), sorter_speed(ctx, sum));
+ stk_fsize(min), stk_fsize(max), stk_fsize(sum / nbuck), sorter_speed(ctx, sum));
sbuck_drop(b);
}
#include "lib/lib.h"
#include "lib/fastbuf.h"
#include "lib/mempool.h"
+#include "lib/stkstring.h"
#include "lib/sorter/common.h"
#include <fcntl.h>
ctx->big_buf_size = 2*bs;
ctx->big_buf_half = ((byte*) ctx->big_buf) + bs;
ctx->big_buf_half_size = bs;
- SORT_XTRACE(2, "Allocated sorting buffer (2*%jd bytes)", (uintmax_t) bs);
+ SORT_XTRACE(2, "Allocated sorting buffer (2*%s)", stk_fsize(bs));
}
void
ctx->big_buf = NULL;
SORT_XTRACE(2, "Freed sorting buffer");
}
-
-void
-format_size(byte *buf, u64 x)
-{
- if (x < 10<<10)
- sprintf(buf, "%.1fK", (double)x/(1<<10));
- else if (x < 1<<20)
- sprintf(buf, "%dK", (int)(x/(1<<10)));
- else if (x < 10<<20)
- sprintf(buf, "%.1fM", (double)x/(1<<20));
- else if (x < 1<<30)
- sprintf(buf, "%dM", (int)(x/(1<<20)));
- else if (x < (u64)10<<30)
- sprintf(buf, "%.1fG", (double)x/(1<<30));
- else if (x != ~(u64)0)
- sprintf(buf, "%dG", (int)(x/(1<<30)));
- else
- strcpy(buf, "unknown");
-}
*dst = 0;
}
+void
+stk_fsize_internal(char *buf, u64 x)
+{
+ if (x < 1<<10)
+ sprintf(buf, "%dB", (int)x);
+ if (x < 10<<10)
+ sprintf(buf, "%.1fK", (double)x/(1<<10));
+ else if (x < 1<<20)
+ sprintf(buf, "%dK", (int)(x/(1<<10)));
+ else if (x < 10<<20)
+ sprintf(buf, "%.1fM", (double)x/(1<<20));
+ else if (x < 1<<30)
+ sprintf(buf, "%dM", (int)(x/(1<<20)));
+ else if (x < (u64)10<<30)
+ sprintf(buf, "%.1fG", (double)x/(1<<30));
+ else if (x != ~(u64)0)
+ sprintf(buf, "%dG", (int)(x/(1<<30)));
+ else
+ strcpy(buf, "unknown");
+}
+
#ifdef TEST
int main(void)
puts(stk_hexdump(a, 3));
char *ary[] = { "The", "jaws", "that", "bite" };
puts(stk_strjoin(ary, 4, ' '));
+ puts(stk_fsize(1234567));
return 0;
}
/*
* UCW Library -- Strings Allocated on the Stack
*
- * (c) 2005--2006 Martin Mares <mj@ucw.cz>
+ * (c) 2005--2007 Martin Mares <mj@ucw.cz>
* (c) 2005 Tomas Valla <tom@ucw.cz>
*
* This software may be freely distributed and used according to the terms
#define stk_printf(f...) ({ uns _l=stk_printf_internal(f); char *_x=alloca(_l); sprintf(_x, f); _x; })
#define stk_hexdump(s,n) ({ uns _n=(n); char *_x=alloca(3*_n+1); stk_hexdump_internal(_x,(byte*)(s),_n); _x; })
#define stk_str_unesc(s) ({ byte *_s=(s); byte *_d=alloca(strlen(_s)+1); str_unesc(_d, _s); _d; })
+#define stk_fsize(n) ({ char *_s=alloca(16); stk_fsize_internal(_s, n); _s; })
uns stk_array_len(char **s, uns cnt);
void stk_array_join(char *x, char **s, uns cnt, uns sep);
uns stk_printf_internal(char *x, ...) FORMAT_CHECK(printf,1,2);
void stk_hexdump_internal(char *dst, byte *src, uns n);
+void stk_fsize_internal(char *dst, u64 size);
Out: Beware the Jabberwock, my son!
42 65 77
The jaws that bite
+ 1.2M