[Pvfs2-cvs] commit by kunkel in pvfs2/src/apps/admin:
pvfs2-ping-benchmark.c module.mk.in
CVS commit program
cvs at parl.clemson.edu
Tue Oct 31 04:40:36 EST 2006
Update of /projects/cvsroot/pvfs2/src/apps/admin
In directory parlweb1:/tmp/cvs-serv2783/src/apps/admin
Modified Files:
Tag: pvfs2-kunkel-tas-branch
module.mk.in
Added Files:
Tag: pvfs2-kunkel-tas-branch
pvfs2-ping-benchmark.c
Log Message:
Added pvfs2-ping-benchmark which gets latency by using NOOP operations to a specific server.
--- /dev/null 2004-06-24 14:04:38.000000000 -0400
+++ pvfs2-ping-benchmark.c 2006-10-31 04:40:36.000000000 -0500
@@ -0,0 +1,297 @@
+/*
+ * (C) 2001 Clemson University and The University of Chicago
+ *
+ * See COPYING in top-level directory.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <time.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include "pvfs2.h"
+#include "pvfs2-mgmt.h"
+#include "pint-sysint-utils.h"
+#include "server-config.h"
+#include "pvfs2-internal.h"
+
+#ifndef PVFS2_VERSION
+#define PVFS2_VERSION "Unknown"
+#endif
+
+struct options
+{
+ char *fs_path_hack;
+ char *fs_path_real;
+ char *mnt_point;
+ char * bmi_target;
+ int min_runtime_secs;
+};
+
+inline void start_timer(
+ struct timeval *start_time);
+inline double get_time_diff(
+ struct timeval *start_time);
+static struct options *parse_args(
+ int argc,
+ char *argv[]);
+
+static void usage(
+ int argc,
+ char **argv);
+
+inline void start_timer(
+ struct timeval *start_time)
+{
+ gettimeofday(start_time, NULL);
+}
+
+inline double get_time_diff(
+ struct timeval *start_time)
+{
+ struct timeval end_time;
+ gettimeofday(&end_time, NULL);
+
+ return (end_time.tv_sec - start_time->tv_sec) +
+ (end_time.tv_usec - start_time->tv_usec) / 1000000.0;
+}
+
+int main(
+ int argc,
+ char **argv)
+{
+ int ret = -1;
+ PVFS_fs_id fs_id;
+ struct options *user_opts = NULL;
+ char pvfs_path[PVFS_NAME_MAX] = { 0 };
+ PVFS_credentials creds;
+
+ /* look at command line arguments */
+ user_opts = parse_args(argc, argv);
+ if (!user_opts)
+ {
+ fprintf(stderr, "Error: failed to parse command line " "arguments.\n");
+ usage(argc, argv);
+ return (-1);
+ }
+
+ ret = PVFS_util_init_defaults();
+ if (ret < 0)
+ {
+ PVFS_perror("PVFS_util_init_defaults", ret);
+ return (-1);
+ }
+
+ ret = PVFS_util_get_default_fsid(&fs_id);
+ if (ret < 0)
+ {
+ PVFS_perror("PVFS_util_get_default_fsid", ret);
+ return (-1);
+ }
+ /* translate local path into pvfs2 relative path */
+ ret = PVFS_util_resolve(user_opts->fs_path_hack,
+ &fs_id, pvfs_path, PVFS_NAME_MAX);
+ if (ret < 0)
+ {
+ fprintf(stderr, "Failure: could not find filesystem for %s "
+ "in pvfs2tab \n", user_opts->fs_path_real);
+ return (-1);
+ }
+
+ PVFS_util_gen_credentials(&creds);
+
+ if ( user_opts->bmi_target == 0)
+ {
+ fprintf(stderr, "Error, no bmi-target given\n");
+ usage(argc, argv);
+ exit(1);
+ }
+ else
+ {
+ PVFS_BMI_addr_t addr;
+ int ret;
+ struct timeval start_time;
+ double timediff = 0;
+ long long int iterations = 0;
+
+ ret = BMI_addr_lookup(& addr, user_opts->bmi_target);
+ if( ret != 0)
+ {
+ fprintf(stderr, "Failure: could not lookup bmi address: %s\n",
+ user_opts->bmi_target);
+ return -1;
+ }
+
+ start_timer( & start_time);
+
+ while ( timediff < user_opts->min_runtime_secs)
+ {
+ ret = PVFS_mgmt_noop(fs_id, &creds, addr);
+ timediff = get_time_diff(& start_time);
+ iterations++;
+ }
+ printf("Elapsed time: %f, Noops done: %lld, Noops/sec: %f, sec/Noop:%f\n",
+ timediff, iterations, (double) iterations / timediff,
+ timediff / (double) iterations);
+
+
+ }
+
+
+ PVFS_sys_finalize();
+
+ return (ret);
+}
+
+
+/* parse_args()
+ *
+ * parses command line arguments
+ *
+ * returns pointer to options structure on success, NULL on failure
+ */
+static struct options *parse_args(
+ int argc,
+ char *argv[])
+{
+ char flags[] = "vm:t:s:";
+ int one_opt = 0;
+ int len;
+
+ struct options *tmp_opts = NULL;
+ int ret = -1;
+
+ if (argc == 1)
+ {
+ usage(argc, argv);
+ exit(EXIT_FAILURE);
+ }
+
+ /* create storage for the command line options */
+ tmp_opts = (struct options *) malloc(sizeof(struct options));
+ if (tmp_opts == NULL)
+ {
+ return (NULL);
+ }
+ memset(tmp_opts, 0, sizeof(struct options));
+
+
+ tmp_opts->min_runtime_secs = 10;
+
+ /* look at command line arguments */
+ while ((one_opt = getopt(argc, argv, flags)) != EOF)
+ {
+ switch (one_opt)
+ {
+ case ('v'):
+ printf("%s\n", PVFS2_VERSION);
+ exit(0);
+ case ('t'):
+ tmp_opts->bmi_target = optarg;
+ break;
+ case ('s'):
+ sscanf(optarg, "%d", & tmp_opts->min_runtime_secs);
+ break;
+ case ('m'):
+ /* taken from pvfs2-statfs.c */
+ len = strlen(optarg) + 1;
+ tmp_opts->mnt_point = (char *) malloc(len + 1);
+ if (!tmp_opts->mnt_point)
+ {
+ free(tmp_opts);
+ return NULL;
+ }
+ memset(tmp_opts->mnt_point, 0, len + 1);
+ ret = sscanf(optarg, "%s", tmp_opts->mnt_point);
+ if (ret < 1)
+ {
+ free(tmp_opts);
+ return NULL;
+ }
+ /* TODO: dirty hack... fix later. The remove_dir_prefix()
+ * function expects some trailing segments or at least
+ * a slash off of the mount point
+ */
+ strcat(tmp_opts->mnt_point, "/");
+ break;
+ case ('?'):
+ usage(argc, argv);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (optind != (argc))
+ {
+ usage(argc, argv);
+ exit(EXIT_FAILURE);
+ }
+
+ /* get the path of the file system, this one has a trailing slash
+ * tacked on, see comment below for why
+ */
+ tmp_opts->fs_path_hack = (char *) malloc(strlen(argv[argc - 1]) + 2);
+ if (tmp_opts->fs_path_hack == NULL)
+ {
+ free(tmp_opts);
+ return NULL;
+ }
+ ret = sscanf(argv[argc - 1], "%s", tmp_opts->fs_path_hack);
+ if (ret < 1)
+ {
+ free(tmp_opts->fs_path_hack);
+ free(tmp_opts);
+ return NULL;
+ }
+ /* TODO: this is a hack... fix later. The remove_dir_prefix()
+ * function expects some trailing segments or at least a slash
+ * off of the mount point
+ */
+ strcat(tmp_opts->fs_path_hack, "/");
+
+ /* also preserve the real path, to use in print statements elsewhre */
+ tmp_opts->fs_path_real = (char *) malloc(strlen(argv[argc - 1]) + 2);
+ if (tmp_opts->fs_path_real == NULL)
+ {
+ free(tmp_opts->fs_path_hack);
+ free(tmp_opts);
+ return NULL;
+ }
+ ret = sscanf(argv[argc - 1], "%s", tmp_opts->fs_path_real);
+ if (ret < 1)
+ {
+ free(tmp_opts->fs_path_hack);
+ free(tmp_opts->fs_path_real);
+ free(tmp_opts);
+ return NULL;
+ }
+
+ return (tmp_opts);
+}
+
+static void usage(
+ int argc,
+ char **argv)
+{
+ fprintf(stderr, "%s version %s\n\n", argv[0], PVFS2_VERSION);
+ fprintf(stderr, "Usage : %s [-t target_bmi_address] [-s runtime_sec]"
+ " -m file_system_path\n", argv[0]);
+ fprintf(stderr, "Example: %s -t tcp://localhost:3334 -m /mnt/pvfs2\n", argv[0]);
+ fprintf(stderr, "If no target bmi address is given all addresses are printed");
+ return;
+}
+
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
Index: module.mk.in
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/apps/admin/module.mk.in,v
diff -p -u -r1.41 -r1.41.4.1
--- module.mk.in 26 Sep 2006 03:44:15 -0000 1.41
+++ module.mk.in 31 Oct 2006 09:40:36 -0000 1.41.4.1
@@ -12,6 +12,7 @@ ADMINSRC := \
$(DIR)/pvfs2-rm.c \
$(DIR)/pvfs2-stat.c \
$(DIR)/pvfs2-statfs.c \
+ $(DIR)/pvfs2-ping-benchmark.c \
$(DIR)/pvfs2-perf-mon-example.c \
$(DIR)/pvfs2-event-mon-example.c \
$(DIR)/pvfs2-mkdir.c \
More information about the Pvfs2-cvs
mailing list