include/denc: clean up ENCODE_DUMP a bit

- PATH_MAX for string
- ENCODE_DUMP -> ENCODE_DUMP_PATH
- some comments!

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2017-05-08 11:54:54 -04:00
parent c5a46089f0
commit 439fdbe3bf
2 changed files with 19 additions and 10 deletions

View File

@ -56,8 +56,16 @@ struct denc_traits {
//#include <iostream>
//using std::cout;
// Define this to compile in a dump of all encoded objects to disk to
// populate ceph-object-corpus. Note that there is an almost
// identical implementation in encoding.h, but you only need to define
// ENCODE_DUMP_PATH here.
//
// See src/test/encoding/generate-corpus-objects.sh.
//
//#define ENCODE_DUMP_PATH /tmp/something
#ifdef ENCODE_DUMP
#ifdef ENCODE_DUMP_PATH
# include <stdio.h>
# include <sys/types.h>
# include <sys/stat.h>
@ -66,6 +74,9 @@ struct denc_traits {
# define ENCODE_STRINGIFY(x) ENCODE_STR(x)
# define DENC_DUMP_PRE(Type) \
char *__denc_dump_pre = p.get_pos();
// this hackery with bits below is just to get a semi-reasonable
// distribution across time. it is somewhat exponential but not
// quite.
# define DENC_DUMP_POST(Type) \
do { \
static int i = 0; \
@ -75,9 +86,9 @@ struct denc_traits {
t &= t - 1; \
if (bits > 2) \
break; \
char fn[200]; \
char fn[PATH_MAX]; \
snprintf(fn, sizeof(fn), \
ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #Type, \
ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #Type, \
getpid(), i++); \
int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
if (fd >= 0) { \

View File

@ -111,13 +111,10 @@ WRITE_INTTYPE_ENCODER(int32_t, le32)
WRITE_INTTYPE_ENCODER(uint16_t, le16)
WRITE_INTTYPE_ENCODER(int16_t, le16)
#ifdef ENCODE_DUMP
// see denc.h for ENCODE_DUMP_PATH discussion and definition.
#ifdef ENCODE_DUMP_PATH
# define ENCODE_DUMP_PRE() \
unsigned pre_off = bl.length()
// NOTE: This is almost an exponential backoff, but because we count
// bits we get a better sample of things we encode later on.
# define ENCODE_DUMP_POST(cl) \
do { \
static int i = 0; \
@ -127,8 +124,8 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
t &= t - 1; \
if (bits > 2) \
break; \
char fn[200]; \
snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #cl, getpid(), i++); \
char fn[PATH_MAX]; \
snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
if (fd >= 0) { \
bufferlist sub; \
@ -142,6 +139,7 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
# define ENCODE_DUMP_POST(cl)
#endif
#define WRITE_CLASS_ENCODER(cl) \
inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { \
ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); } \