--------------------- PatchSet 10196 Date: 2007/12/06 06:28:33 Author: adri Branch: s27_adri Tag: (none) Log: * Bring over the valgrind debugging stuff, untested. A later commit will remove it from squid.h among other things. * a few ancilliary bits and pieces. Members: libcore/tools.c:1.1.2.1->1.1.2.2 libcore/tools.h:1.1.2.1->1.1.2.2 libcore/valgrind.h:1.1->1.1.2.1 Index: squid/libcore/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libcore/Attic/tools.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/libcore/tools.c 2 Dec 2007 02:01:33 -0000 1.1.2.1 +++ squid/libcore/tools.c 6 Dec 2007 06:28:33 -0000 1.1.2.2 @@ -157,3 +157,41 @@ /* I think I got that right */ } + +void +gb_flush(gb_t * g) +{ + g->gb += (g->bytes >> 30); + g->bytes &= (1 << 30) - 1; +} + +double +gb_to_double(const gb_t * g) +{ + return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); +} + +const char * +gb_to_str(const gb_t * g) +{ + /* + * it is often convenient to call gb_to_str several times for _one_ printf + */ +#define max_cc_calls 5 + typedef char GbBuf[32]; + static GbBuf bufs[max_cc_calls]; + static int call_id = 0; + double value = gb_to_double(g); + char *buf = bufs[call_id++]; + if (call_id >= max_cc_calls) + call_id = 0; + /* select format */ + if (value < 1e9) + snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); + else if (value < 1e12) + snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); + else + snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); + return buf; +} + Index: squid/libcore/tools.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libcore/Attic/tools.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/libcore/tools.h 2 Dec 2007 02:01:33 -0000 1.1.2.1 +++ squid/libcore/tools.h 6 Dec 2007 06:28:33 -0000 1.1.2.2 @@ -5,7 +5,7 @@ * * Adrian Chadd * - * $Id: tools.h,v 1.1.2.1 2007/12/02 02:01:33 adri Exp $ + * $Id: tools.h,v 1.1.2.2 2007/12/06 06:28:33 adri Exp $ */ #ifndef __LIBCORE_TOOLS_H__ #define __LIBCORE_TOOLS_H__ @@ -36,7 +36,20 @@ extern void dlinkMoveList(dlink_list *from, dlink_list *to); extern int dlink_list_length(dlink_list *m); dlink_node * dlinkFind(dlink_list *m, void *data); - void mem_frob(void *data, int len); +/* gb related stuff */ +typedef struct { + size_t count; + size_t bytes; + size_t gb; +} gb_t; + +#define gb_flush_limit (0x3FFFFFFF) +#define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; } + +extern void gb_flush(gb_t * g); +extern double gb_to_double(const gb_t * g); +extern const char * gb_to_str(const gb_t * g); + #endif /* __LIBCORE_TOOLS_H__ */ --- /dev/null Fri Dec 7 01:18:28 2007 +++ squid/libcore/valgrind.h Fri Dec 7 01:18:28 2007 @@ -0,0 +1,21 @@ +#ifndef __LIBCORE_VALGRIND_H__ +#define __LIBCORE_VALGRIND_H__ + +/* + * valgrind debug support + */ +#if WITH_VALGRIND +#include +#else +#define VALGRIND_MAKE_NOACCESS(a,b) (0) +#define VALGRIND_MAKE_WRITABLE(a,b) (0) +#define VALGRIND_MAKE_READABLE(a,b) (0) +#define VALGRIND_CHECK_WRITABLE(a,b) (0) +#define VALGRIND_CHECK_READABLE(a,b) (0) +#define VALGRIND_MALLOCLIKE_BLOCK(a,b,c,d) +#define VALGRIND_FREELIKE_BLOCK(a,b) +#define RUNNING_ON_VALGRIND 0 +#endif /* WITH_VALGRIND */ + + +#endif