[sheepdog] [PATCH v2] dog: add elapsed time to measure the program is fast or not
Hitoshi Mitake
mitake.hitoshi at gmail.com
Mon Jul 14 14:17:28 CEST 2014
At Fri, 11 Jul 2014 09:49:38 +0800,
Ruoyu wrote:
>
> To be compatible with OpenStack glance and cinder driver, we cannot
> show elapsed time by default. Therefore, the new option -t (--time)
> is added in dog command line to achieve it. For example:
>
> dog cluster info -t
> dog vdi check test -t
>
> Signed-off-by: Ruoyu <liangry at ucweb.com>
> ---
> dog/alter.c | 4 ++--
> dog/cluster.c | 14 +++++++-------
> dog/dog.c | 15 +++++++++++++++
> dog/node.c | 14 +++++++-------
> dog/vdi.c | 44 +++++++++++++++++++++++++-------------------
> include/util.h | 4 ++++
> lib/util.c | 25 +++++++++++++++++++++++++
> 7 files changed, 85 insertions(+), 35 deletions(-)
Applied, thanks.
Just curious, are you using sheepdog with OpenStack?
Thanks,
Hitoshi
>
> diff --git a/dog/alter.c b/dog/alter.c
> index 7af7f9f..432f01b 100644
> --- a/dog/alter.c
> +++ b/dog/alter.c
> @@ -223,9 +223,9 @@ static int alter_vdi_copy(int argc, char **argv)
> }
>
> static struct subcommand alter_cmd[] = {
> - {"cluster-copy", NULL, "caph", "set the cluster's redundancy level",
> + {"cluster-copy", NULL, "capht", "set the cluster's redundancy level",
> NULL, CMD_NEED_NODELIST, alter_cluster_copy, alter_options},
> - {"vdi-copy", "<vdiname>", "caph", "set the vdi's redundancy level",
> + {"vdi-copy", "<vdiname>", "capht", "set the vdi's redundancy level",
> NULL, CMD_NEED_ARG|CMD_NEED_NODELIST, alter_vdi_copy, alter_options},
> {NULL,},
> };
> diff --git a/dog/cluster.c b/dog/cluster.c
> index 69ec07c..fa62366 100644
> --- a/dog/cluster.c
> +++ b/dog/cluster.c
> @@ -572,22 +572,22 @@ static int cluster_check(int argc, char **argv)
> }
>
> static struct subcommand cluster_cmd[] = {
> - {"info", NULL, "aprhv", "show cluster information",
> + {"info", NULL, "aprhvt", "show cluster information",
> NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
> - {"format", NULL, "bctaph", "create a Sheepdog store",
> + {"format", NULL, "bctapht", "create a Sheepdog store",
> NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
> - {"shutdown", NULL, "aph", "stop Sheepdog",
> + {"shutdown", NULL, "apht", "stop Sheepdog",
> NULL, 0, cluster_shutdown, cluster_options},
> - {"snapshot", "<tag|idx> <path>", "aph", "snapshot/restore the cluster",
> + {"snapshot", "<tag|idx> <path>", "apht", "snapshot/restore the cluster",
> cluster_snapshot_cmd, CMD_NEED_ARG,
> cluster_snapshot, cluster_options},
> - {"recover", NULL, "afph",
> + {"recover", NULL, "afpht",
> "See 'dog cluster recover' for more information",
> cluster_recover_cmd, CMD_NEED_ARG,
> cluster_recover, cluster_options},
> - {"reweight", NULL, "aph", "reweight the cluster", NULL, 0,
> + {"reweight", NULL, "apht", "reweight the cluster", NULL, 0,
> cluster_reweight, cluster_options},
> - {"check", NULL, "aph", "check and repair cluster", NULL,
> + {"check", NULL, "apht", "check and repair cluster", NULL,
> CMD_NEED_NODELIST, cluster_check, cluster_options},
> {NULL,},
> };
> diff --git a/dog/dog.c b/dog/dog.c
> index 7d1153d..4eb4ad8 100644
> --- a/dog/dog.c
> +++ b/dog/dog.c
> @@ -32,6 +32,7 @@ struct node_id sd_nid = {
> bool highlight = true;
> bool raw_output;
> bool verbose;
> +bool elapsed_time;
>
> static const struct sd_option dog_options[] = {
>
> @@ -42,6 +43,7 @@ static const struct sd_option dog_options[] = {
> " single spaces and print all sizes in decimal bytes"},
> {'v', "verbose", false, "print more information than default"},
> {'h', "help", false, "display this help and exit"},
> + {'t', "time", false, "show elapsed time"},
>
> { 0, NULL, false, NULL },
> };
> @@ -453,6 +455,9 @@ int main(int argc, char **argv)
> const struct sd_option *sd_opts;
> uint8_t sdhost[16];
> int sdport;
> + struct timespec start, end;
> +
> + start = get_time_tick();
>
> log_dog_operation(argc, argv);
>
> @@ -520,6 +525,9 @@ int main(int argc, char **argv)
> case 'h':
> subcommand_usage(argv[1], argv[2], EXIT_SUCCESS);
> break;
> + case 't':
> + elapsed_time = true;
> + break;
> case '?':
> usage(commands, EXIT_USAGE);
> break;
> @@ -565,5 +573,12 @@ int main(int argc, char **argv)
> ret = command_fn(argc, argv);
> if (ret == EXIT_USAGE)
> subcommand_usage(argv[1], argv[2], EXIT_USAGE);
> +
> + if (elapsed_time) {
> + end = get_time_tick();
> + printf("\nElapsed time: %.3lf seconds\n",
> + get_time_interval(&start, &end));
> + }
> +
> return ret;
> }
> diff --git a/dog/node.c b/dog/node.c
> index a9799ff..83ff541 100644
> --- a/dog/node.c
> +++ b/dog/node.c
> @@ -609,19 +609,19 @@ static int node_log(int argc, char **argv)
> }
>
> static struct subcommand node_cmd[] = {
> - {"kill", "<node id>", "aprhl", "kill node", NULL,
> + {"kill", "<node id>", "aprhlt", "kill node", NULL,
> CMD_NEED_NODELIST, node_kill, node_options},
> - {"list", NULL, "aprh", "list nodes", NULL,
> + {"list", NULL, "aprht", "list nodes", NULL,
> CMD_NEED_NODELIST, node_list},
> - {"info", NULL, "aprh", "show information about each node", NULL,
> + {"info", NULL, "aprht", "show information about each node", NULL,
> CMD_NEED_NODELIST, node_info},
> - {"recovery", NULL, "aphPr", "show recovery information of nodes", NULL,
> + {"recovery", NULL, "aphPrt", "show recovery information of nodes", NULL,
> CMD_NEED_NODELIST, node_recovery, node_options},
> - {"md", "[disks]", "aprAh", "See 'dog node md' for more information",
> + {"md", "[disks]", "aprAht", "See 'dog node md' for more information",
> node_md_cmd, CMD_NEED_ARG, node_md, node_options},
> - {"stat", NULL, "aprwh", "show stat information about the node", NULL,
> + {"stat", NULL, "aprwht", "show stat information about the node", NULL,
> 0, node_stat, node_options},
> - {"log", NULL, "aph", "show or set log level of the node", node_log_cmd,
> + {"log", NULL, "apht", "show or set log level of the node", node_log_cmd,
> CMD_NEED_ARG, node_log},
> {NULL,},
> };
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 49a2139..1443cf4 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -2458,59 +2458,65 @@ static int vdi_cache(int argc, char **argv)
> }
>
> static struct subcommand vdi_cmd[] = {
> - {"check", "<vdiname>", "saph", "check and repair image's consistency",
> + {"check", "<vdiname>", "sapht", "check and repair image's consistency",
> NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
> vdi_check, vdi_options},
> - {"create", "<vdiname> <size>", "Pycaphrv", "create an image",
> + {"create", "<vdiname> <size>", "Pycaphrvt", "create an image",
> NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
> vdi_create, vdi_options},
> - {"snapshot", "<vdiname>", "saphrv", "create a snapshot",
> + {"snapshot", "<vdiname>", "saphrvt", "create a snapshot",
> NULL, CMD_NEED_ARG,
> vdi_snapshot, vdi_options},
> - {"clone", "<src vdi> <dst vdi>", "sPnaphrv", "clone an image",
> + {"clone", "<src vdi> <dst vdi>", "sPnaphrvt", "clone an image",
> NULL, CMD_NEED_ARG,
> vdi_clone, vdi_options},
> - {"delete", "<vdiname>", "saph", "delete an image",
> + {"delete", "<vdiname>", "sapht", "delete an image",
> NULL, CMD_NEED_ARG,
> vdi_delete, vdi_options},
> - {"rollback", "<vdiname>", "saphfrv", "rollback to a snapshot",
> + {"rollback", "<vdiname>", "saphfrvt", "rollback to a snapshot",
> NULL, CMD_NEED_ARG,
> vdi_rollback, vdi_options},
> - {"list", "[vdiname]", "aprh", "list images",
> + {"list", "[vdiname]", "aprht", "list images",
> NULL, 0, vdi_list, vdi_options},
> - {"tree", NULL, "aph", "show images in tree view format",
> + {"tree", NULL, "apht", "show images in tree view format",
> NULL, 0, vdi_tree, vdi_options},
> - {"graph", NULL, "aph", "show images in Graphviz dot format",
> + {"graph", NULL, "apht", "show images in Graphviz dot format",
> NULL, 0, vdi_graph, vdi_options},
> - {"object", "<vdiname>", "isaph", "show object information in the image",
> + {"object", "<vdiname>", "isapht",
> + "show object information in the image",
> vdi_object_cmd, CMD_NEED_ARG,
> vdi_object, vdi_options},
> - {"track", "<vdiname>", "isapho",
> + {"track", "<vdiname>", "isaphot",
> "show the object epoch trace in the image",
> NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
> vdi_track, vdi_options},
> - {"setattr", "<vdiname> <key> [value]", "dxaph", "set a VDI attribute",
> + {"setattr", "<vdiname> <key> [value]", "dxapht", "set a VDI attribute",
> NULL, CMD_NEED_ARG,
> vdi_setattr, vdi_options},
> - {"getattr", "<vdiname> <key>", "aph", "get a VDI attribute",
> + {"getattr", "<vdiname> <key>", "apht", "get a VDI attribute",
> NULL, CMD_NEED_ARG,
> vdi_getattr, vdi_options},
> - {"resize", "<vdiname> <new size>", "aph", "resize an image",
> + {"resize", "<vdiname> <new size>", "apht", "resize an image",
> NULL, CMD_NEED_ARG,
> vdi_resize, vdi_options},
> - {"read", "<vdiname> [<offset> [<len>]]", "saph", "read data from an image",
> + {"read", "<vdiname> [<offset> [<len>]]", "sapht",
> + "read data from an image",
> NULL, CMD_NEED_ARG,
> vdi_read, vdi_options},
> - {"write", "<vdiname> [<offset> [<len>]]", "apwh", "write data to an image",
> + {"write", "<vdiname> [<offset> [<len>]]", "apwht",
> + "write data to an image",
> NULL, CMD_NEED_ARG,
> vdi_write, vdi_options},
> - {"backup", "<vdiname> <backup>", "sFaph", "create an incremental backup between two snapshots",
> + {"backup", "<vdiname> <backup>", "sFapht",
> + "create an incremental backup between two snapshots",
> NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
> vdi_backup, vdi_options},
> - {"restore", "<vdiname> <backup>", "saph", "restore snapshot images from a backup",
> + {"restore", "<vdiname> <backup>", "sapht",
> + "restore snapshot images from a backup",
> NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
> vdi_restore, vdi_options},
> - {"cache", "<vdiname>", "saph", "Run 'dog vdi cache' for more information",
> + {"cache", "<vdiname>", "sapht",
> + "Run 'dog vdi cache' for more information",
> vdi_cache_cmd, CMD_NEED_ARG,
> vdi_cache, vdi_options},
> {NULL,},
> diff --git a/include/util.h b/include/util.h
> index c7a1921..d230f7f 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -125,6 +125,10 @@ int atomic_create_and_write(const char *path, const char *buf, size_t len,
> void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen);
> void trim_zero_blocks(void *buf, uint64_t *poffset, uint32_t *plen);
>
> +struct timespec get_time_tick(void);
> +double get_time_interval(const struct timespec *start,
> + const struct timespec *end);
> +
> /* a type safe version of qsort() */
> #define xqsort(base, nmemb, compar) \
> ({ \
> diff --git a/lib/util.c b/lib/util.c
> index 408fc19..9a3adcd 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -806,3 +806,28 @@ void trim_zero_blocks(void *buf, uint64_t *poffset, uint32_t *plen)
> if (orig_offset < *poffset)
> memmove(p, p + *poffset - orig_offset, *plen);
> }
> +
> +struct timespec get_time_tick(void)
> +{
> + struct timespec ts;
> + int ret;
> +
> + ts.tv_sec = 0;
> + ts.tv_nsec = 0;
> +
> + ret = clock_gettime(CLOCK_MONOTONIC, &ts);
> + if (ret < 0)
> + sd_err("clock_gettime failure: %m");
> +
> + return ts;
> +}
> +
> +double get_time_interval(const struct timespec *start,
> + const struct timespec *end)
> +{
> + assert(start);
> + assert(end);
> +
> + return ((end->tv_nsec - start->tv_nsec) * 0.000000001)
> + + end->tv_sec - start->tv_sec;
> +}
> --
> 1.8.3.2
>
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
More information about the sheepdog
mailing list