]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/denc: support ENCODE_DUMP
authorSage Weil <sage@redhat.com>
Thu, 4 May 2017 22:33:21 +0000 (18:33 -0400)
committerSage Weil <sage@redhat.com>
Fri, 5 May 2017 19:21:20 +0000 (15:21 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 97987b4ace737b86a4dc2dce94ce9d330fbe903c)

src/include/denc.h
src/include/encoding.h

index c058b8e05fc4ebf3b9bb07dc91f1c2fd5b7e1dae..09cc304bd670b7f2b1eb4d87959811d02e5e62ee 100644 (file)
@@ -52,6 +52,41 @@ struct denc_traits {
 //using std::cout;
 
 
+#ifdef ENCODE_DUMP
+# include <stdio.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
+# 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<traits::supported == 1 &&
     _denc_friend(*this, p);                                            \
   }                                                                    \
   void encode(bufferlist::contiguous_appender& p) const {              \
+    DENC_DUMP_PRE(Type);                                               \
     _denc_friend(*this, p);                                            \
+    DENC_DUMP_POST(Type);                                              \
   }                                                                    \
   void decode(buffer::ptr::iterator& p) {                              \
     _denc_friend(*this, p);                                            \
@@ -1444,7 +1481,9 @@ inline typename std::enable_if<traits::supported == 1 &&
     _denc_friend(*this, p, f);                                         \
   }                                                                    \
   void encode(bufferlist::contiguous_appender& p, uint64_t f) const {  \
+    DENC_DUMP_PRE(Type);                                               \
     _denc_friend(*this, p, f);                                         \
+    DENC_DUMP_POST(Type);                                              \
   }                                                                    \
   void decode(buffer::ptr::iterator& p, uint64_t f=0) {                        \
     _denc_friend(*this, p, f);                                         \
index cbc762351d7b9d8fe91cbbee7dbfd95e0a3692ef..32c1fc6e8f9e19777c070ba8827210d283ed74c3 100644 (file)
@@ -112,13 +112,6 @@ WRITE_INTTYPE_ENCODER(uint16_t, le16)
 WRITE_INTTYPE_ENCODER(int16_t, le16)
 
 #ifdef ENCODE_DUMP
-# include <stdio.h>
-# include <sys/types.h>
-# include <sys/stat.h>
-# include <fcntl.h>
-
-# define ENCODE_STR(x) #x
-# define ENCODE_STRINGIFY(x) ENCODE_STR(x)
 
 # define ENCODE_DUMP_PRE()                     \
   unsigned pre_off = bl.length()