From 9181871ff49a5b1e5b1acc9c8a96c99d28e80a5e Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Wed, 25 Jul 2012 06:27:57 +0530 Subject: libglusterfs/statedump: add start and end markers in the statedump file Also do not overwrite the statedump file if statedump is taken on the same process again. Instead add the timestamp to the filename Change-Id: I451a0decf2dad5c398631cab1fc2a69811c69af8 BUG: 843408 Signed-off-by: Raghavendra Bhat Reviewed-on: http://review.gluster.com/3738 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Anand Avati --- libglusterfs/src/statedump.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 1abd603ad..1158a2d82 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -60,8 +60,9 @@ gf_proc_dump_open (char *dump_dir, char *brickname) char path[PATH_MAX] = {0,}; int dump_fd = -1; - snprintf (path, sizeof (path), "%s/%s.%d.dump", (dump_dir ? - dump_dir : "/tmp"), brickname, getpid()); + snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, + (dump_dir ? dump_dir : "/tmp"), brickname, getpid(), + (uint64_t) time (NULL)); dump_fd = open (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600); if (dump_fd < 0) @@ -622,6 +623,9 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) int ret = -1; glusterfs_graph_t *trav = NULL; char brick_name[PATH_MAX] = {0,}; + struct timeval tv = {0,}; + char timestr[256] = {0,}; + char sign_string[512] = {0,}; gf_proc_dump_lock (); @@ -641,6 +645,25 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) if (ret < 0) goto out; + //continue even though gettimeofday() has failed + ret = gettimeofday (&tv, NULL); + if (0 == ret) { + gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf (timestr + strlen (timestr), + sizeof timestr - strlen (timestr), + ".%"GF_PRI_SUSECONDS, tv.tv_usec); + } + + snprintf (sign_string, sizeof (sign_string), "DUMP-START-TIME: %s\n", + timestr); + + //swallow the errors of write for start and end marker + ret = write (gf_dump_fd, sign_string, strlen (sign_string)); + + memset (sign_string, 0, sizeof (sign_string)); + memset (timestr, 0, sizeof (timestr)); + memset (&tv, 0, sizeof (tv)); + if (GF_PROC_DUMP_IS_OPTION_ENABLED (mem)) { gf_proc_dump_mem_info (); gf_proc_dump_mempool_info (ctx); @@ -672,6 +695,18 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) i++; } + ret = gettimeofday (&tv, NULL); + if (0 == ret) { + gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf (timestr + strlen (timestr), + sizeof timestr - strlen (timestr), + ".%"GF_PRI_SUSECONDS, tv.tv_usec); + } + + snprintf (sign_string, sizeof (sign_string), "\nDUMP-END-TIME: %s", + timestr); + ret = write (gf_dump_fd, sign_string, strlen (sign_string)); + out: if (gf_dump_fd != -1) gf_proc_dump_close (); -- cgit