X-Git-Url: http://git.samba.org/samba.git/?p=tridge%2Fdbench.git;a=blobdiff_plain;f=child.c;h=807cc05df75f3d0569be86ca9d89e9eade9eb259;hp=ba4866257972613322d8e69aa3109fc361b60959;hb=a72bc292425a370c04c1d61b23b651fdde67c5ba;hpb=cbc285bb42ae84a9a2983c3fe4c60813a27ef641 diff --git a/child.c b/child.c index ba48662..807cc05 100644 --- a/child.c +++ b/child.c @@ -1,6 +1,7 @@ /* - dbench version 1 - Copyright (C) Andrew Tridgell 1999 + dbench version 3 + + Copyright (C) Andrew Tridgell 1999-2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,124 +28,154 @@ #include "dbench.h" -int line_count=0; - -char *client_filename = DATADIR "client.txt"; - - -static int sigsegv(int sig) -{ - char line[200]; - printf("segv at line %d\n", line_count); - sprintf(line, "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d", - getpid(), getpid()); - system(line); - exit(1); -} - - -FILE * open_client_dump(void) -{ - FILE *f; - - if ((f = fopen(client_filename, "rt")) != NULL) - return f; - - fprintf(stderr, - "dbench: error opening %s: %s", client_filename, - strerror(errno)); +#define ival(s) strtol(s, NULL, 0) - return NULL; -} -void child_run(int client) +/* run a test that simulates an approximate netbench client load */ +void child_run(struct child_struct *child, const char *loadfile) { int i; - char fname[128]; char line[1024]; - char cname[20]; - FILE *f; - char *params[20]; - - signal(SIGSEGV, sigsegv); + char *cname; + char **sparams, **params; + char *p; + const char *status; + char *fname = NULL; + char *fname2 = NULL; + FILE *f = fopen(loadfile, "r"); + pid_t parent = getppid(); + extern double targetrate; + + child->line = 0; + + asprintf(&cname,"client%d", child->id); + + sparams = calloc(20, sizeof(char *)); + for (i=0;i<20;i++) { + sparams[i] = malloc(100); + } - sprintf(cname,"CLIENT%d", client); +again: + nb_time_reset(child); - f = open_client_dump(); + while (fgets(line, sizeof(line)-1, f)) { + params = sparams; - if (!f) { - perror("client.txt"); - return; - } + if (child->done || kill(parent, 0) == -1) { + goto done; + } - while (fgets(line, sizeof(line)-1, f)) { - line_count++; + child->line++; line[strlen(line)-1] = 0; - all_string_sub(line,"CLIENT1", cname); + all_string_sub(line,"client1", cname); all_string_sub(line,"\\", "/"); all_string_sub(line," /", " "); - for (i=0;i<20;i++) params[i] = ""; - - /* parse the command parameters */ - params[0] = strtok(line," "); - i = 0; - while (params[i]) params[++i] = strtok(NULL," "); - - params[i] = ""; - - if (i < 2) continue; - - if (strcmp(params[1],"REQUEST") == 0) { - if (!strcmp(params[0],"SMBopenX")) { - strcpy(fname, params[5]); - } else if (!strcmp(params[0],"SMBclose")) { - nb_close(atoi(params[3])); - } else if (!strcmp(params[0],"SMBmkdir")) { - nb_mkdir(params[3]); - } else if (!strcmp(params[0],"CREATE")) { - nb_create(params[3], atoi(params[5])); - } else if (!strcmp(params[0],"SMBrmdir")) { - nb_rmdir(params[3]); - } else if (!strcmp(params[0],"SMBunlink")) { - strcpy(fname, params[3]); - } else if (!strcmp(params[0],"SMBmv")) { - nb_rename(params[3], params[5]); - } else if (!strcmp(params[0],"SMBgetatr")) { - strcpy(fname, params[3]); - } else if (!strcmp(params[0],"SMBwrite")) { - nb_write(atoi(params[3]), - atoi(params[5]), atoi(params[7])); - } else if (!strcmp(params[0],"SMBwritebraw")) { - nb_write(atoi(params[3]), - atoi(params[7]), atoi(params[5])); - } else if (!strcmp(params[0],"SMBreadbraw")) { - nb_read(atoi(params[3]), - atoi(params[7]), atoi(params[5])); - } else if (!strcmp(params[0],"SMBread")) { - nb_read(atoi(params[3]), - atoi(params[5]), atoi(params[7])); + p = line; + for (i=0; + i<19 && next_token(&p, params[i], " "); + i++) ; + + params[i][0] = 0; + + if (i < 2 || params[0][0] == '#') continue; + + if (!strncmp(params[0],"SMB", 3)) { + printf("ERROR: You are using a dbench 1 load file\n"); + exit(1); + } + + if (i > 0 && isdigit(params[0][0])) { + double targett = strtod(params[0], NULL); + if (targetrate != 0) { + nb_target_rate(child, targetrate); + } else { + nb_time_delay(child, targett); } + params++; + i--; + } + + if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 && + strncmp(params[i-1], "0x", 2) != 0) { + printf("Badly formed status at line %d\n", child->line); + continue; + } + + if (fname) { + free(fname); + fname = NULL; + } + if (fname2) { + free(fname2); + fname2 = NULL; + } + + if (i>1 && params[1][0] == '/') { + asprintf(&fname, "%s%s", child->directory, params[1]); + } + if (i>2 && params[2][0] == '/') { + asprintf(&fname2, "%s%s", child->directory, params[2]); + } + + status = params[i-1]; + + if (!strcmp(params[0],"NTCreateX")) { + nb_createx(child, fname, ival(params[2]), ival(params[3]), + ival(params[4]), status); + } else if (!strcmp(params[0],"Close")) { + nb_close(child, ival(params[1]), status); + } else if (!strcmp(params[0],"Rename")) { + nb_rename(child, fname, fname2, status); + } else if (!strcmp(params[0],"Unlink")) { + nb_unlink(child, fname, ival(params[2]), status); + } else if (!strcmp(params[0],"Deltree")) { + nb_deltree(child, fname); + } else if (!strcmp(params[0],"Rmdir")) { + nb_rmdir(child, fname, status); + } else if (!strcmp(params[0],"Mkdir")) { + nb_mkdir(child, fname, status); + } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) { + nb_qpathinfo(child, fname, ival(params[2]), status); + } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) { + nb_qfileinfo(child, ival(params[1]), ival(params[2]), status); + } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) { + nb_qfsinfo(child, ival(params[1]), status); + } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) { + nb_sfileinfo(child, ival(params[1]), ival(params[2]), status); + } else if (!strcmp(params[0],"FIND_FIRST")) { + nb_findfirst(child, fname, ival(params[2]), + ival(params[3]), ival(params[4]), status); + } else if (!strcmp(params[0],"WriteX")) { + nb_writex(child, ival(params[1]), + ival(params[2]), ival(params[3]), ival(params[4]), + status); + } else if (!strcmp(params[0],"LockX")) { + nb_lockx(child, ival(params[1]), + ival(params[2]), ival(params[3]), status); + } else if (!strcmp(params[0],"UnlockX")) { + nb_unlockx(child, ival(params[1]), + ival(params[2]), ival(params[3]), status); + } else if (!strcmp(params[0],"ReadX")) { + nb_readx(child, ival(params[1]), + ival(params[2]), ival(params[3]), ival(params[4]), + status); + } else if (!strcmp(params[0],"Flush")) { + nb_flush(child, ival(params[1]), status); + } else if (!strcmp(params[0],"Sleep")) { + nb_sleep(child, ival(params[1]), status); } else { - if (!strcmp(params[0],"SMBopenX")) { - if (!strncmp(params[2], "ERR", 3)) continue; - nb_open(fname, atoi(params[3]), atoi(params[5])); - } else if (!strcmp(params[0],"SMBgetatr")) { - if (!strncmp(params[2], "ERR", 3)) continue; - nb_stat(fname, atoi(params[3])); - } else if (!strcmp(params[0],"SMBunlink")) { - if (!strncmp(params[2], "ERR", 3)) continue; - nb_unlink(fname); - } + printf("[%d] Unknown operation %s\n", child->line, params[0]); } } - fclose(f); - sprintf(fname,"CLIENTS/CLIENT%d", client); - rmdir(fname); - rmdir("CLIENTS"); + rewind(f); + goto again; - printf("+"); +done: + child->cleanup = 1; + fclose(f); + nb_cleanup(child); }