ia64/xen-unstable

view tools/xenstore/speedtest.c @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 4e0c94871be2
children
line source
1 /*
2 Xen Store Daemon Speed test
3 Copyright (C) 2005 Rusty Russell IBM Corporation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
20 #include <stdlib.h>
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <errno.h>
28 #include "utils.h"
29 #include "xs.h"
30 #include "list.h"
31 #include "talloc.h"
33 static void do_command(const char *cmd)
34 {
35 int ret;
37 ret = system(cmd);
38 if (ret == -1 || !WIFEXITED(ret) || WEXITSTATUS(ret) != 0)
39 barf_perror("Failed '%s': %i", cmd, ret);
40 }
42 static int start_daemon(void)
43 {
44 int fds[2], pid;
46 do_command(talloc_asprintf(NULL, "rm -rf testsuite/tmp/*"));
48 /* Start daemon. */
49 pipe(fds);
50 if ((pid = fork())) {
51 /* Child writes PID when its ready: we wait for that. */
52 char buffer[20];
53 close(fds[1]);
54 if (read(fds[0], buffer, sizeof(buffer)) < 0)
55 barf("Failed to summon daemon");
56 close(fds[0]);
57 } else {
58 dup2(fds[1], STDOUT_FILENO);
59 close(fds[0]);
60 #if 0
61 execlp("valgrind", "valgrind", "-q", "--suppressions=testsuite/vg-suppressions", "xenstored_test", "--output-pid",
62 "--no-fork", "--trace-file=/tmp/trace", NULL);
63 #else
64 execlp("./xenstored_test", "xenstored_test", "--output-pid", "--no-fork", NULL);
65 // execlp("strace", "strace", "-o", "/tmp/out", "./xenstored_test", "--output-pid", "--no-fork", NULL);
66 #endif
67 exit(1);
68 }
69 return pid;
70 }
72 static void kill_daemon(int pid)
73 {
74 int saved_errno = errno;
75 kill(pid, SIGTERM);
76 errno = saved_errno;
77 }
79 #define NUM_ENTRIES 50
81 /* We create the given number of trees, each with NUM_ENTRIES, using
82 * transactions. */
83 int main(int argc, char *argv[])
84 {
85 int i, j, pid, print;
86 struct xs_handle *h;
88 if (argc != 2)
89 barf("Usage: speedtest <numdomains>");
91 pid = start_daemon();
92 h = xs_daemon_open();
93 print = atoi(argv[1]) / 76;
94 if (!print)
95 print = 1;
96 for (i = 0; i < atoi(argv[1]); i ++) {
97 char name[64];
99 if (i % print == 0)
100 write(1, ".", 1);
101 if (!xs_transaction_start(h)) {
102 kill_daemon(pid);
103 barf_perror("Starting transaction");
104 }
105 sprintf(name, "/%i", i);
106 if (!xs_mkdir(h, name)) {
107 kill_daemon(pid);
108 barf_perror("Making directory %s", name);
109 }
111 for (j = 0; j < NUM_ENTRIES; j++) {
112 sprintf(name, "/%i/%i", i, j);
113 if (!xs_write(h, name, name, strlen(name))) {
114 kill_daemon(pid);
115 barf_perror("Making directory %s", name);
116 }
117 }
118 if (!xs_transaction_end(h, false)) {
119 kill_daemon(pid);
120 barf_perror("Ending transaction");
121 }
122 }
123 write(1, "\n", 1);
125 kill_daemon(pid);
126 wait(NULL);
127 return 0;
128 }