ia64/xen-unstable

changeset 7038:6aef7d1062bb

Add check for speed (takes 33 minutes on my laptop, OUCH!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
author Rusty Russell <rusty@rustcorp.com.au>
date Fri Sep 23 14:24:58 2005 +0100 (2005-09-23)
parents 8a757f283fb8
children 76af1a1df67c
files tools/xenstore/Makefile tools/xenstore/speedtest.c
line diff
     1.1 --- a/tools/xenstore/Makefile	Fri Sep 23 13:30:54 2005 +0100
     1.2 +++ b/tools/xenstore/Makefile	Fri Sep 23 14:24:58 2005 +0100
     1.3 @@ -50,6 +50,11 @@ xs_random: xs_random.o xs_test_lib.o xs_
     1.4  xs_stress: xs_stress.o xs_test_lib.o xs_lib.o talloc.o utils.o
     1.5  xs_crashme: xs_crashme.o xs_lib.o talloc.o utils.o
     1.6  
     1.7 +speedtest: speedtest.o xs.o xs_lib.o utils.o talloc.o
     1.8 +
     1.9 +check-speed: speedtest xenstored_test $(TESTDIR)
    1.10 +	$(TESTENV) time ./speedtest 100
    1.11 +
    1.12  xs_test.o xs_stress.o xenstored_core_test.o xenstored_watch_test.o xenstored_transaction_test.o xenstored_domain_test.o xs_random.o xs_test_lib.o talloc_test.o fake_libxc.o xs_crashme.o: CFLAGS=$(BASECFLAGS) $(TESTFLAGS)
    1.13  
    1.14  xenstored_%_test.o: xenstored_%.c
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/xenstore/speedtest.c	Fri Sep 23 14:24:58 2005 +0100
     2.3 @@ -0,0 +1,130 @@
     2.4 +/* 
     2.5 +    Xen Store Daemon Speed test
     2.6 +    Copyright (C) 2005 Rusty Russell IBM Corporation
     2.7 +
     2.8 +    This program is free software; you can redistribute it and/or modify
     2.9 +    it under the terms of the GNU General Public License as published by
    2.10 +    the Free Software Foundation; either version 2 of the License, or
    2.11 +    (at your option) any later version.
    2.12 +
    2.13 +    This program is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.16 +    GNU General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU General Public License
    2.19 +    along with this program; if not, write to the Free Software
    2.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.21 +*/
    2.22 +
    2.23 +#include <stdlib.h>
    2.24 +#include <sys/types.h>
    2.25 +#include <sys/wait.h>
    2.26 +#include <stdio.h>
    2.27 +#include <stdarg.h>
    2.28 +#include <unistd.h>
    2.29 +#include <fcntl.h>
    2.30 +#include <errno.h>
    2.31 +#include "utils.h"
    2.32 +#include "xs.h"
    2.33 +#include "list.h"
    2.34 +#include "talloc.h"
    2.35 +
    2.36 +static void do_command(const char *cmd)
    2.37 +{
    2.38 +	int ret;
    2.39 +
    2.40 +	ret = system(cmd);
    2.41 +	if (ret == -1 || !WIFEXITED(ret) || WEXITSTATUS(ret) != 0)
    2.42 +		barf_perror("Failed '%s': %i", cmd, ret);
    2.43 +}
    2.44 +
    2.45 +static int start_daemon(void)
    2.46 +{
    2.47 +	int fds[2], pid;
    2.48 +
    2.49 +	do_command(talloc_asprintf(NULL, "rm -rf testsuite/tmp/*"));
    2.50 +
    2.51 +	/* Start daemon. */
    2.52 +	pipe(fds);
    2.53 +	if ((pid = fork())) {
    2.54 +		/* Child writes PID when its ready: we wait for that. */
    2.55 +		char buffer[20];
    2.56 +		close(fds[1]);
    2.57 +		if (read(fds[0], buffer, sizeof(buffer)) < 0)
    2.58 +			barf("Failed to summon daemon");
    2.59 +		close(fds[0]);
    2.60 +	} else {
    2.61 +		dup2(fds[1], STDOUT_FILENO);
    2.62 +		close(fds[0]);
    2.63 +#if 0
    2.64 +		execlp("valgrind", "valgrind", "-q", "--suppressions=testsuite/vg-suppressions", "xenstored_test", "--output-pid",
    2.65 +		       "--no-fork", "--trace-file=/tmp/trace", NULL);
    2.66 +#else
    2.67 +		execlp("./xenstored_test", "xenstored_test", "--output-pid", "--no-fork", NULL);
    2.68 +//		execlp("strace", "strace", "-o", "/tmp/out", "./xenstored_test", "--output-pid", "--no-fork", NULL);
    2.69 +#endif
    2.70 +		exit(1);
    2.71 +	}
    2.72 +	return pid;
    2.73 +}
    2.74 +
    2.75 +static void kill_daemon(int pid)
    2.76 +{
    2.77 +	int saved_errno = errno;
    2.78 +	kill(pid, SIGTERM);
    2.79 +	errno = saved_errno;
    2.80 +}
    2.81 +
    2.82 +#define NUM_ENTRIES 50
    2.83 +
    2.84 +/* We create the given number of trees, each with NUM_ENTRIES, using
    2.85 + * transactions. */
    2.86 +int main(int argc, char *argv[])
    2.87 +{
    2.88 +	int i, j, pid, print;
    2.89 +	struct xs_handle *h;
    2.90 +
    2.91 +	if (argc != 2)
    2.92 +		barf("Usage: speedtest <numdomains>");
    2.93 +
    2.94 +	pid = start_daemon();
    2.95 +	h = xs_daemon_open();
    2.96 +	print = atoi(argv[1]) / 76;
    2.97 +	if (!print)
    2.98 +		print = 1;
    2.99 +	for (i = 0; i < atoi(argv[1]); i ++) {
   2.100 +		char name[64];
   2.101 +
   2.102 +		if (i % print == 0)
   2.103 +			write(1, ".", 1);
   2.104 +		if (!xs_transaction_start(h, "/")) {
   2.105 +			kill_daemon(pid);
   2.106 +			barf_perror("Starting transaction");
   2.107 +		}
   2.108 +		sprintf(name, "/%i", i);
   2.109 +		if (!xs_mkdir(h, name)) {
   2.110 +			kill_daemon(pid);
   2.111 +			barf_perror("Making directory %s", name);
   2.112 +		}
   2.113 +
   2.114 +		for (j = 0; j < NUM_ENTRIES; j++) {
   2.115 +			sprintf(name, "/%i/%i", i, j);
   2.116 +			if (!xs_write(h, name, name, strlen(name))) {
   2.117 +				kill_daemon(pid);
   2.118 +				barf_perror("Making directory %s", name);
   2.119 +			}
   2.120 +		}
   2.121 +		if (!xs_transaction_end(h, false)) {
   2.122 +			kill_daemon(pid);
   2.123 +			barf_perror("Ending transaction");
   2.124 +		}
   2.125 +	}
   2.126 +	write(1, "\n", 1);
   2.127 +
   2.128 +	kill_daemon(pid);
   2.129 +	wait(NULL);
   2.130 +	return 0;
   2.131 +}
   2.132 +	
   2.133 +