diff options
author | Amar Tumballi <amarts@redhat.com> | 2017-09-25 16:44:06 +0530 |
---|---|---|
committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-11-06 14:23:49 +0000 |
commit | 125fc934e7f4c669f67e5eec5b0e3dae3a2b6d72 (patch) | |
tree | 24d1aa5139ad5766c4e9bc9e6add7e55df8fe329 /libglusterfs/src/latency.c | |
parent | e86d71b7b4653ddd66db7f3a16074e46ed24848f (diff) |
stack: change gettimeofday() to clock_gettime()
For achieving the above, needed below changes too.
* more sanity into how 'frame->op' is assigned.
* infra to have 'stats' as separate section in 'xlator_t' structure
Updates #137
Change-Id: I36679bf9577f3ed00a695b4e7d92870dcb3db8e1
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'libglusterfs/src/latency.c')
-rw-r--r-- | libglusterfs/src/latency.c | 162 |
1 files changed, 36 insertions, 126 deletions
diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c index 1d75f5b98ce..d0039a1f730 100644 --- a/libglusterfs/src/latency.c +++ b/libglusterfs/src/latency.c @@ -21,146 +21,43 @@ #include "statedump.h" #include "libglusterfs-messages.h" -static int gf_set_fop_from_fn_pointer_warning; -void -gf_set_fop_from_fn_pointer (call_frame_t *frame, struct xlator_fops *fops, void *fn) -{ - glusterfs_fop_t fop = -1; - - if (fops->stat == *(fop_stat_t *)&fn) - fop = GF_FOP_STAT; - else if (fops->readlink == *(fop_readlink_t *)&fn) - fop = GF_FOP_READLINK; - else if (fops->mknod == *(fop_mknod_t *)&fn) - fop = GF_FOP_MKNOD; - else if (fops->mkdir == *(fop_mkdir_t *)&fn) - fop = GF_FOP_MKDIR; - else if (fops->unlink == *(fop_unlink_t *)&fn) - fop = GF_FOP_UNLINK; - else if (fops->rmdir == *(fop_rmdir_t *)&fn) - fop = GF_FOP_RMDIR; - else if (fops->symlink == *(fop_symlink_t *)&fn) - fop = GF_FOP_SYMLINK; - else if (fops->rename == *(fop_rename_t *)&fn) - fop = GF_FOP_RENAME; - else if (fops->link == *(fop_link_t *)&fn) - fop = GF_FOP_LINK; - else if (fops->truncate == *(fop_truncate_t *)&fn) - fop = GF_FOP_TRUNCATE; - else if (fops->open == *(fop_open_t *)&fn) - fop = GF_FOP_OPEN; - else if (fops->readv == *(fop_readv_t *)&fn) - fop = GF_FOP_READ; - else if (fops->writev == *(fop_writev_t *)&fn) - fop = GF_FOP_WRITE; - else if (fops->statfs == *(fop_statfs_t *)&fn) - fop = GF_FOP_STATFS; - else if (fops->flush == *(fop_flush_t *)&fn) - fop = GF_FOP_FLUSH; - else if (fops->fsync == *(fop_fsync_t *)&fn) - fop = GF_FOP_FSYNC; - else if (fops->setxattr == *(fop_setxattr_t *)&fn) - fop = GF_FOP_SETXATTR; - else if (fops->getxattr == *(fop_getxattr_t *)&fn) - fop = GF_FOP_GETXATTR; - else if (fops->removexattr == *(fop_removexattr_t *)&fn) - fop = GF_FOP_REMOVEXATTR; - else if (fops->opendir == *(fop_opendir_t *)&fn) - fop = GF_FOP_OPENDIR; - else if (fops->fsyncdir == *(fop_fsyncdir_t *)&fn) - fop = GF_FOP_FSYNCDIR; - else if (fops->access == *(fop_access_t *)&fn) - fop = GF_FOP_ACCESS; - else if (fops->create == *(fop_create_t *)&fn) - fop = GF_FOP_CREATE; - else if (fops->ftruncate == *(fop_ftruncate_t *)&fn) - fop = GF_FOP_FTRUNCATE; - else if (fops->fstat == *(fop_fstat_t *)&fn) - fop = GF_FOP_FSTAT; - else if (fops->lk == *(fop_lk_t *)&fn) - fop = GF_FOP_LK; - else if (fops->lookup == *(fop_lookup_t *)&fn) - fop = GF_FOP_LOOKUP; - else if (fops->readdir == *(fop_readdir_t *)&fn) - fop = GF_FOP_READDIR; - else if (fops->inodelk == *(fop_inodelk_t *)&fn) - fop = GF_FOP_INODELK; - else if (fops->finodelk == *(fop_finodelk_t *)&fn) - fop = GF_FOP_FINODELK; - else if (fops->entrylk == *(fop_entrylk_t *)&fn) - fop = GF_FOP_ENTRYLK; - else if (fops->fentrylk == *(fop_fentrylk_t *)&fn) - fop = GF_FOP_FENTRYLK; - else if (fops->xattrop == *(fop_xattrop_t *)&fn) - fop = GF_FOP_XATTROP; - else if (fops->fxattrop == *(fop_fxattrop_t *)&fn) - fop = GF_FOP_FXATTROP; - else if (fops->fgetxattr == *(fop_fgetxattr_t *)&fn) - fop = GF_FOP_FGETXATTR; - else if (fops->fsetxattr == *(fop_fsetxattr_t *)&fn) - fop = GF_FOP_FSETXATTR; - else if (fops->rchecksum == *(fop_rchecksum_t *)&fn) - fop = GF_FOP_RCHECKSUM; - else if (fops->setattr == *(fop_setattr_t *)&fn) - fop = GF_FOP_SETATTR; - else if (fops->fsetattr == *(fop_fsetattr_t *)&fn) - fop = GF_FOP_FSETATTR; - else if (fops->readdirp == *(fop_readdirp_t *)&fn) - fop = GF_FOP_READDIRP; - else if (fops->getspec == *(fop_getspec_t *)&fn) - fop = GF_FOP_GETSPEC; - else if (fops->ipc == *(fop_ipc_t *)&fn) - fop = GF_FOP_IPC; - else { - fop = GF_FOP_NULL; - GF_LOG_OCCASIONALLY(gf_set_fop_from_fn_pointer_warning, - "latency", - GF_LOG_WARNING, - "Unknown FOP type"); - } - - frame->op = fop; -} - - void gf_update_latency (call_frame_t *frame) { double elapsed; - struct timeval *begin, *end; + struct timespec *begin, *end; fop_latency_t *lat; begin = &frame->begin; end = &frame->end; - elapsed = (end->tv_sec - begin->tv_sec) * 1e6 - + (end->tv_usec - begin->tv_usec); - - lat = &frame->this->latencies[frame->op]; + if (!(begin->tv_sec && end->tv_sec)) + goto out; - lat->total += elapsed; - lat->count++; - lat->mean = lat->mean + (elapsed - lat->mean) / lat->count; -} + elapsed = (end->tv_sec - begin->tv_sec) * 1e9 + + (end->tv_nsec - begin->tv_nsec); -void -gf_latency_begin (call_frame_t *frame, void *fn) -{ - gf_set_fop_from_fn_pointer (frame, frame->this->fops, fn); + /* Can happen mostly at initiator xlator, as STACK_WIND/UNWIND macros + set it right anyways for those frames */ + if (!frame->op) + frame->op = frame->root->op; - gettimeofday (&frame->begin, NULL); -} + lat = &frame->this->stats.interval.latencies[frame->op]; + if (lat->max < elapsed) + lat->max = elapsed; -void -gf_latency_end (call_frame_t *frame) -{ - gettimeofday (&frame->end, NULL); + if (lat->min > elapsed) + lat->min = elapsed; - gf_update_latency (frame); + lat->total += elapsed; + lat->count++; +out: + return; } + void gf_proc_dump_latency_info (xlator_t *xl) { @@ -175,13 +72,26 @@ gf_proc_dump_latency_info (xlator_t *xl) gf_proc_dump_build_key (key, key_prefix, "%s", (char *)gf_fop_list[i]); + fop_latency_t *lat = &xl->stats.interval.latencies[i]; + + /* Doesn't make sense to continue if there are no fops + came in the given interval */ + if (!lat->count) + continue; + gf_proc_dump_write (key, "%.03f,%"PRId64",%.03f", - xl->latencies[i].mean, - xl->latencies[i].count, - xl->latencies[i].total); + (lat->total / lat->count), lat->count, + lat->total); } - memset (xl->latencies, 0, sizeof (xl->latencies)); + memset (xl->stats.interval.latencies, 0, + sizeof (xl->stats.interval.latencies)); + + /* make sure 'min' is set to high value, so it would be + properly set later */ + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + xl->stats.interval.latencies[i].min = 0xffffffff; + } } |