4 Copyright (C) Andrew Tridgell 1999-2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* This file links against either fileio.c to do operations against a
22 local filesystem (making dbench), or sockio.c to issue SMB-like
23 command packets over a socket (making tbench).
25 So, the pattern of operations and the control structure is the same
26 for both benchmarks, but the operations performed are different.
31 #define ival(s) strtol(s, NULL, 0)
33 static void nb_target_rate(struct child_struct *child, double rate)
35 static double last_bytes;
36 static struct timeval last_time;
39 if (last_bytes == 0) {
40 last_bytes = child->bytes;
41 last_time = timeval_current();
46 tdelay = (child->bytes - last_bytes)/(1.0e6*rate) - timeval_elapsed(&last_time);
48 tdelay = - timeval_elapsed(&last_time);
50 if (tdelay > 0 && rate != 0) {
53 child->max_latency = MAX(child->max_latency, -tdelay);
56 last_time = timeval_current();
57 last_bytes = child->bytes;
60 static void nb_time_reset(struct child_struct *child)
62 child->starttime = timeval_current();
65 static void nb_time_delay(struct child_struct *child, double targett)
67 double elapsed = timeval_elapsed(&child->starttime);
68 if (targett > elapsed) {
69 msleep(1000*(targett - elapsed));
70 } else if (elapsed - targett > child->max_latency) {
71 child->max_latency = MAX(elapsed - targett, child->max_latency);
77 /* run a test that simulates an approximate netbench client load */
78 void child_run(struct child_struct *child, const char *loadfile)
83 char **sparams, **params;
88 FILE *f = fopen(loadfile, "r");
89 pid_t parent = getppid();
94 asprintf(&cname,"client%d", child->id);
96 sparams = calloc(20, sizeof(char *));
98 sparams[i] = malloc(100);
102 nb_time_reset(child);
104 while (fgets(line, sizeof(line)-1, f)) {
107 if (child->done || kill(parent, 0) == -1) {
113 line[strlen(line)-1] = 0;
115 all_string_sub(line,"client1", cname);
116 all_string_sub(line,"\\", "/");
117 all_string_sub(line," /", " ");
121 i<19 && next_token(&p, params[i], " ");
126 if (i < 2 || params[0][0] == '#') continue;
128 if (!strncmp(params[0],"SMB", 3)) {
129 printf("ERROR: You are using a dbench 1 load file\n");
133 if (i > 0 && isdigit(params[0][0])) {
134 targett = strtod(params[0], NULL);
141 if (options.targetrate != 0 || targett == 0.0) {
142 nb_target_rate(child, options.targetrate);
144 nb_time_delay(child, targett);
146 child->lasttime = timeval_current();
148 if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
149 strncmp(params[i-1], "0x", 2) != 0) {
150 printf("Badly formed status at line %d\n", child->line);
163 if (i>1 && params[1][0] == '/') {
164 asprintf(&fname, "%s%s", child->directory, params[1]);
166 if (i>2 && params[2][0] == '/') {
167 asprintf(&fname2, "%s%s", child->directory, params[2]);
170 status = params[i-1];
172 if (!strcmp(params[0],"NTCreateX")) {
173 nb_createx(child, fname, ival(params[2]), ival(params[3]),
174 ival(params[4]), status);
175 } else if (!strcmp(params[0],"Close")) {
176 nb_close(child, ival(params[1]), status);
177 } else if (!strcmp(params[0],"Rename")) {
178 nb_rename(child, fname, fname2, status);
179 } else if (!strcmp(params[0],"Unlink")) {
180 nb_unlink(child, fname, ival(params[2]), status);
181 } else if (!strcmp(params[0],"Deltree")) {
182 nb_deltree(child, fname);
183 } else if (!strcmp(params[0],"Rmdir")) {
184 nb_rmdir(child, fname, status);
185 } else if (!strcmp(params[0],"Mkdir")) {
186 nb_mkdir(child, fname, status);
187 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
188 nb_qpathinfo(child, fname, ival(params[2]), status);
189 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
190 nb_qfileinfo(child, ival(params[1]), ival(params[2]), status);
191 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
192 nb_qfsinfo(child, ival(params[1]), status);
193 } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) {
194 nb_sfileinfo(child, ival(params[1]), ival(params[2]), status);
195 } else if (!strcmp(params[0],"FIND_FIRST")) {
196 nb_findfirst(child, fname, ival(params[2]),
197 ival(params[3]), ival(params[4]), status);
198 } else if (!strcmp(params[0],"WriteX")) {
199 nb_writex(child, ival(params[1]),
200 ival(params[2]), ival(params[3]), ival(params[4]),
202 } else if (!strcmp(params[0],"LockX")) {
203 nb_lockx(child, ival(params[1]),
204 ival(params[2]), ival(params[3]), status);
205 } else if (!strcmp(params[0],"UnlockX")) {
206 nb_unlockx(child, ival(params[1]),
207 ival(params[2]), ival(params[3]), status);
208 } else if (!strcmp(params[0],"ReadX")) {
209 nb_readx(child, ival(params[1]),
210 ival(params[2]), ival(params[3]), ival(params[4]),
212 } else if (!strcmp(params[0],"Flush")) {
213 nb_flush(child, ival(params[1]), status);
214 } else if (!strcmp(params[0],"Sleep")) {
215 nb_sleep(child, ival(params[1]), status);
217 printf("[%d] Unknown operation %s\n", child->line, params[0]);