From 9b2b80dded8d1aa4d1d1c96669f12421fe5737e9 Mon Sep 17 00:00:00 2001 From: Rich Prohaska <prohaska@tokutek.com> Date: Wed, 20 Jan 2010 17:03:03 +0000 Subject: [PATCH] add tracing for getting a handle on node serialization costs refs[t:2261] git-svn-id: file:///svn/toku/tokudb@17123 c7de825b-a66e-492c-adef-691d508d4ae1 --- linux/file.c | 17 +++++++++++++++++ newbrt/brt-serialize.c | 21 +++++++++------------ toku_include/toku_portability.h | 1 + 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/linux/file.c b/linux/file.c index 92f180f03a5..1f3853da917 100644 --- a/linux/file.c +++ b/linux/file.c @@ -96,6 +96,23 @@ toku_os_full_write (int fd, const void *buf, size_t len) { assert(len == 0); } +ssize_t +toku_os_write (int fd, const void *buf, size_t len) { + while (len > 0) { + ssize_t r; + if (t_write) { + r = t_write(fd, buf, len); + } else { + r = write(fd, buf, len); + } + if (r <= 0) + return r; + len -= r; + buf += r; + } + return 0; +} + static uint64_t get_tnow(void) { struct timeval tv; int r = gettimeofday(&tv, NULL); assert(r == 0); diff --git a/newbrt/brt-serialize.c b/newbrt/brt-serialize.c index 2e2ff421cb0..be3a14096f3 100644 --- a/newbrt/brt-serialize.c +++ b/newbrt/brt-serialize.c @@ -590,10 +590,9 @@ static void *decompress_worker(void *arg) { #define DO_TOKU_TRACE 0 #if DO_TOKU_TRACE -static int toku_trace_fd = -1; - +const int toku_trace_fd = -1; static inline void do_toku_trace(const char *cp, int len) { - write(toku_trace_fd, cp, len); + toku_os_write(toku_trace_fd, cp, len); } #define toku_trace(a) do_toku_trace(a, strlen(a)) #else @@ -832,7 +831,6 @@ deserialize_brtnode_from_rbuf (BLOCKNUM blocknum, u_int32_t fullhash, BRTNODE *b toku_free(rb->buf); rb->buf = NULL; } - toku_trace("deserial done"); *brtnode = result; //toku_verify_counts(result); return 0; @@ -845,9 +843,9 @@ verify_decompressed_brtnode_checksum (struct rbuf *rb) { if (rb->size >= 4) { uint32_t verify_size = rb->size - 4; //Not counting the checksum - toku_trace("x1764 start"); - uint32_t crc = x1764_memory(rb->buf, verify_size); toku_trace("x1764"); + uint32_t crc = x1764_memory(rb->buf, verify_size); + toku_trace("x1764 done"); uint32_t *crcp = (uint32_t*)(((uint8_t*)rb->buf) + verify_size); uint32_t storedcrc = toku_dtoh32(*crcp); @@ -863,6 +861,7 @@ verify_decompressed_brtnode_checksum (struct rbuf *rb) { static int decompress_brtnode_from_raw_block_into_rbuf(u_int8_t *raw_block, struct rbuf *rb, BLOCKNUM blocknum) { + toku_trace("decompress"); int r; int i; // get the number of compressed sub blocks @@ -983,18 +982,14 @@ deserialize_brtnode_from_rbuf_versioned (u_int32_t version, BLOCKNUM blocknum, u // Read brt node from file into struct. Perform version upgrade if necessary. int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash, BRTNODE *brtnode, struct brt_header *h) { + toku_trace("deserial start"); + int r; struct rbuf rb = {.buf = NULL, .size = 0, .ndone = 0}; if (0) printf("Deserializing Block %" PRId64 "\n", blocknum.b); if (h->panic) return h->panic; -#if DO_TOKU_TRACE - if (toku_trace_fd == -1) - toku_trace_fd = open(DEV_NULL_FILE, O_WRONLY); - toku_trace("deserial start"); -#endif - // get the file offset and block size for the block DISKOFF offset, size; toku_translate_blocknum_to_offset_size(h->blocktable, blocknum, &offset, &size); @@ -1027,6 +1022,8 @@ toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash, BR //TODO: #1924 verify some form of checksum during 'deserialization'??? r = deserialize_brtnode_from_rbuf_versioned(layout_version, blocknum, fullhash, brtnode, h, &rb); + toku_trace("deserial done"); + cleanup: if (rb.buf) toku_free(rb.buf); if (raw_block) toku_free(raw_block); diff --git a/toku_include/toku_portability.h b/toku_include/toku_portability.h index b4a8f7f8af7..71dea76d367 100644 --- a/toku_include/toku_portability.h +++ b/toku_include/toku_portability.h @@ -135,6 +135,7 @@ void os_free(void*); // full_pwrite and full_write performs a pwrite, and checks errors. It doesn't return unless all the data was written. */ void toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default"))); void toku_os_full_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default"))); +ssize_t toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default"))); // wrapper around fsync int toku_file_fsync(int fd); -- 2.30.9