From 2b107f91cefbdc6ab173890c3ccf3693768bc76c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 4 May 2017 18:33:21 -0400 Subject: [PATCH] include/denc: support ENCODE_DUMP Signed-off-by: Sage Weil (cherry picked from commit 97987b4ace737b86a4dc2dce94ce9d330fbe903c) --- src/include/denc.h | 39 +++++++++++++++++++++++++++++++++++++++ src/include/encoding.h | 7 ------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index c058b8e05fc4e..09cc304bd670b 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -52,6 +52,41 @@ struct denc_traits { //using std::cout; +#ifdef ENCODE_DUMP +# include +# include +# include +# include +# define ENCODE_STR(x) #x +# define ENCODE_STRINGIFY(x) ENCODE_STR(x) +# define DENC_DUMP_PRE(Type) \ + char *__denc_dump_pre = p.get_pos(); +# define DENC_DUMP_POST(Type) \ + do { \ + static int i = 0; \ + i++; \ + int bits = 0; \ + for (unsigned t = i; t; bits++) \ + t &= t - 1; \ + if (bits > 2) \ + break; \ + char fn[200]; \ + snprintf(fn, sizeof(fn), \ + ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #Type, \ + getpid(), i++); \ + int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \ + if (fd >= 0) { \ + size_t len = p.get_pos() - __denc_dump_pre; \ + int r = ::write(fd, __denc_dump_pre, len); \ + (void)r; \ + ::close(fd); \ + } \ + } while (0) +#else +# define DENC_DUMP_PRE(Type) +# define DENC_DUMP_POST(Type) +#endif + /* @@ -1428,7 +1463,9 @@ inline typename std::enable_if -# include -# include -# include - -# define ENCODE_STR(x) #x -# define ENCODE_STRINGIFY(x) ENCODE_STR(x) # define ENCODE_DUMP_PRE() \ unsigned pre_off = bl.length() -- 2.39.5