summaryrefslogtreecommitdiffstats
path: root/xlators/debug
diff options
context:
space:
mode:
authorKaleb S. KEITHLEY <kkeithle@redhat.com>2014-06-16 12:29:03 -0400
committerVijay Bellur <vbellur@redhat.com>2014-11-20 06:59:16 -0800
commit9797bd197d48ca17a124c245295937ac3d48ab58 (patch)
tree174fe233d2f1e34e5ce16818e02f68c4f030c4b8 /xlators/debug
parent27c2be4af6f2dc0a18410e17862bb5d3a07231f3 (diff)
core: use gf_time_fmt() instead of localtime()+strftime()
gf_time_fmt() has existed since 3.3; it provides consistent timestamps (i.e. UTC times) throughout the implementation. (BTW, the other name for UTC is GMT.) N.B. many (all?) commercial storage solutions use UTC time for logging. This makes for easier debugging across geographically distributed systems. Also adding a "%s" fmt for portably printing time as simple numeric value on systems regardless of whether 32-bit or 64-bit time_t. Plus a minor tweak to return a ptr to the dest-string to allow gf_time_fmt() to be passed as a param in a *printf(). Someday we should pick the "one true" timestamp format and revise all calls to gf_time_fmt() to use it instead of the five or six different formats. Change-Id: I78202ae14b7246fa424efeea56bf2463e14abfb0 BUG: 1109917 Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com> Reviewed-on: http://review.gluster.org/8085 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Niels de Vos <ndevos@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/debug')
-rw-r--r--xlators/debug/trace/src/trace.c59
1 files changed, 22 insertions, 37 deletions
diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c
index c1293127495..88a41ae480f 100644
--- a/xlators/debug/trace/src/trace.c
+++ b/xlators/debug/trace/src/trace.c
@@ -25,21 +25,18 @@ trace_stat_to_str(struct iatt *buf, char *str, size_t len)
char atime_buf[256] = {0,};
char mtime_buf[256] = {0,};
char ctime_buf[256] = {0,};
- uint64_t ia_time = 0;
if (!buf)
return;
- ia_time = buf->ia_atime;
- strftime (atime_buf, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
- ia_time = buf->ia_mtime;
- strftime (mtime_buf, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (atime_buf, sizeof atime_buf, buf->ia_atime,
+ gf_timefmt_dirent);
- ia_time = buf->ia_ctime;
- strftime (ctime_buf, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (mtime_buf, sizeof mtime_buf, buf->ia_mtime,
+ gf_timefmt_dirent);
+
+ gf_time_fmt (ctime_buf, sizeof ctime_buf, buf->ia_ctime,
+ gf_timefmt_dirent);
snprintf (str, len,
"gfid=%s ino=%"PRIu64", mode=%o, "
@@ -60,24 +57,18 @@ trace_stat_to_str(struct iatt *buf, char *str, size_t len)
int
dump_history_trace (circular_buffer_t *cb, void *data)
{
- char *string = NULL;
- struct tm *tm = NULL;
- char timestr[256] = {0,};
-
- string = (char *)cb->data;
- tm = localtime (&cb->tv.tv_sec);
+ char timestr[256] = {0,};
/* Since we are continuing with adding entries to the buffer even when
gettimeofday () fails, it's safe to check tm and then dump the time
at which the entry was added to the buffer */
- if (tm) {
- strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
- snprintf (timestr + strlen (timestr), 256 - strlen (timestr),
- ".%"GF_PRI_SUSECONDS, cb->tv.tv_usec);
- gf_proc_dump_write ("TIME", "%s", timestr);
- }
- gf_proc_dump_write ("FOP", "%s\n", string);
+ gf_time_fmt (timestr, sizeof timestr, cb->tv.tv_sec, gf_timefmt_Ymd_T);
+ snprintf (timestr + strlen (timestr), 256 - strlen (timestr),
+ ".%"GF_PRI_SUSECONDS, cb->tv.tv_usec);
+ gf_proc_dump_write ("TIME", "%s", timestr);
+
+ gf_proc_dump_write ("FOP", "%s\n", cb->data);
return 0;
}
@@ -2033,7 +2024,6 @@ int
trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- uint64_t ia_time = 0;
char actime_str[256] = {0,};
char modtime_str[256] = {0,};
trace_conf_t *conf = NULL;
@@ -2070,13 +2060,11 @@ trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
}
if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
- ia_time = stbuf->ia_atime;
- strftime (actime_str, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (actime_str, sizeof actime_str,
+ stbuf->ia_atime, gf_timefmt_bdT);
- ia_time = stbuf->ia_mtime;
- strftime (modtime_str, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (modtime_str, sizeof modtime_str,
+ stbuf->ia_mtime, gf_timefmt_bdT);
snprintf (string, sizeof (string),
"%"PRId64": gfid=%s path=%s "
@@ -2104,7 +2092,6 @@ int
trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- uint64_t ia_time = 0;
char actime_str[256] = {0,};
char modtime_str[256] = {0,};
trace_conf_t *conf = NULL;
@@ -2139,13 +2126,11 @@ trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
}
if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
- ia_time = stbuf->ia_atime;
- strftime (actime_str, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (actime_str, sizeof actime_str,
+ stbuf->ia_atime, gf_timefmt_bdT);
- ia_time = stbuf->ia_mtime;
- strftime (modtime_str, 256, "[%b %d %H:%M:%S]",
- localtime ((time_t *)&ia_time));
+ gf_time_fmt (modtime_str, sizeof modtime_str,
+ stbuf->ia_mtime, gf_timefmt_bdT);
snprintf (string, sizeof (string),
"%"PRId64": gfid=%s fd=%p "