]> git-server-git.apps.pok.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>
Thu, 4 May 2017 22:33:21 +0000 (18:33 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/denc.h
src/include/encoding.h

index e3a8f29e2651857eaafa4d47813f8c419a3561bb..7b15b3948564bfe934c7bd0dd2d6fc706fd7888b 100644 (file)
@@ -57,6 +57,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
+
 
 /*
 
@@ -1511,7 +1546,9 @@ inline typename std::enable_if<traits::supported &&
     _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);                                            \
@@ -1527,7 +1564,9 @@ inline typename std::enable_if<traits::supported &&
     _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 d6e25306d833d5be48ba9bd702ea8059e7af0a2f..085eec7cf3c0500749c66cc036639e60c8c75cb4 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()