void setArgs( struct args& a, int argc, char *argv[]) { for( int ac = 0; ac < argc; ac++) { std::cout << "Checking " << argv[ac] << "\n"; if( ac == 0) continue; std::string arg(argv[ac]); if( arg == "-v" ) { a.v = true; a.vp = ac; } if( arg == "-b" ) { a.b = true; a.bp = ac; } if( arg == "-bbox" ) { a.bbox = true; a.bboxp = ac; } if( arg == "-c" ) { a.c = true; a.cp = ac; } if( arg == "-cd" ) { a.cd = true; a.cdp = ac; } if( arg == "-ptc" ) { a.ptc = true; a.ptcp = ac; } if( arg == "-ptcd" ) { a.ptcd = true; a.ptcdp = ac; } if( a.v ) { if( ac == (a.vp + 1)) { UT_String intarg(argv[ac]); std::cout << "Verbosity argument: " << intarg.toInt() << "\n"; logger.setLogLevel((Logging::LogLevel)intarg.toInt()); } } if( a.bbox ) { if( ac == (a.bboxp + 1)) { a.bboxfile = std::string(argv[ac]); std::cout << "bbox file " << a.bboxfile << "\n"; } } if( a.ptc ) { if( ac == (a.ptcp + 1)) { a.ptcfile = std::string(argv[ac]); std::cout << "pointcloud file " << a.ptcfile << "\n"; } } if( a.ptcd ) { if( ac == (a.ptcdp + 1)) { UT_String farg(argv[ac]); a.ptcdv = farg.toFloat(); std::cout << "pointcloud file density " << a.ptcdv << "\n"; } } if( a.c ) { if( ac == (a.cp + 1)) { a.cFile = std::string(argv[ac]); std::cout << "convert file " << a.cFile << "\n"; } } if( a.cd ) { if( ac == (a.cdp + 1)) { a.cdDir = std::string(argv[ac]); std::cout << "convert dir " << a.cdDir << "\n"; } } } }
int main (int argc, char ** argv) { int i, len, ch, close = 0, res, arg; char buffer[80], * tok, * opt; FILE * file; char * cmd; LGL * lgl; for (i = 1; i < argc; i++) { if (!strcmp (argv[i], "-h")) { printf ("usage: lgluntrace [-h][-v][-e][<trace>[.gz]]\n"); exit (0); } else if (!strcmp (argv[i], "-v")) verbose = 1; else if (!strcmp (argv[i], "-e")) exitonabort = 1; else if (argv[i][0] == '-') die ("invalid command line option '%s' (try '-h')", argv[i]); else if (name) die ("two traces '%s' and '%s' specified (try '-h')", name, argv[i]); else name = argv[i]; } if(name) { len = strlen (name); if (len >= 3 && !strcmp (name + len - 3, ".gz")) { cmd = malloc (len + 20); sprintf (cmd, "gunzip -c %s", name); file = popen (cmd, "r"); free (cmd); if (file) close = 2; } else { file = fopen (name, "r"); if (file) close = 1; } if (!file) die ("can not read '%s'", name); } else name = "<stdin>", file = stdin; if (exitonabort) { msg ("setting signal handlers since '-e' specified"); signal (SIGINT, exitonsig); signal (SIGSEGV, exitonsig); signal (SIGABRT, exitonsig); signal (SIGTERM, exitonsig); } msg ("reading %s", name); buffer[len = 0] = 0; lineno = 1; res = 0; lgl = 0; NEXT: ch = getc (file); if (ch == EOF) goto DONE; if (ch == '\r') goto NEXT; if (ch != '\n') { if (len + 1 >= sizeof (buffer)) perr ("line buffer exceeded"); buffer[len++] = ch; buffer[len] = 0; goto NEXT; } msg ("line %d : %s", lineno, buffer); if (!(tok = strtok (buffer, " "))) perr ("empty line"); else if (!strcmp (tok, "add")) lgladd (lgl, intarg ("add")); else if (!strcmp (tok, "return")) { arg = intarg ("return"); if (arg != res) die ("expected return value %d but got %d", arg, res); } else if (!strcmp (tok, "deref")) res = lglderef (lgl, intarg ("deref")); else if (!strcmp (tok, "failed")) res = lglfailed (lgl, intarg ("failed")); else if (!strcmp (tok, "fixed")) res = lglfixed (lgl, intarg ("fixed")); else if (!strcmp (tok, "repr")) res = lglrepr (lgl, intarg ("repr")); else if (noarg (tok, "incvar")) res = lglincvar (lgl); else if (noarg (tok, "maxvar")) res = lglmaxvar (lgl); else if (noarg (tok, "changed")) res = lglchanged (lgl); else if (noarg (tok, "inconsistent")) res = lglinconsistent (lgl); else if (noarg (tok, "lkhd")) res = lglookahead (lgl); else if (noarg (tok, "fixate")) lglfixate (lgl); else if (noarg (tok, "reduce")) lglreducecache (lgl); else if (noarg (tok, "flush")) lglflushcache (lgl); else if (noarg (tok, "chkclone")) lglchkclone (lgl); else if (!strcmp (tok, "assume")) lglassume (lgl, intarg ("assume")); else if (noarg (tok, "init")) lgl = lglinit (); else if (noarg (tok, "sat")) res = lglsat (lgl); else if (!strcmp (tok, "simp")) res = lglsimp (lgl, intarg ("simp")); else if (noarg (tok, "stats")) lglstats (lgl); else if (!strcmp (tok, "freeze")) lglfreeze (lgl, intarg ("freeze")); else if (!strcmp (tok, "melt")) lglmelt (lgl, intarg ("melt")); else if (!strcmp (tok, "reuse")) lglreuse (lgl, intarg ("reuse")); else if (!strcmp (tok, "frozen")) res = lglfrozen (lgl, intarg ("frozen")); else if (!strcmp (tok, "usable")) res = lglusable (lgl, intarg ("usable")); else if (!strcmp (tok, "reusable")) res = lglreusable (lgl, intarg ("reusable")); else if (noarg (tok, "setphases")) lglsetphases (lgl); else if (!strcmp (tok, "setphase")) lglsetphase (lgl, intarg ("setphase")); else if (!strcmp (tok, "resetphase")) lglresetphase (lgl, intarg ("resetphase")); else if (!strcmp (tok, "option")) { if (!(opt = strtok (0, " "))) perr ("option name missing"); lglsetopt (lgl, opt, intarg ("option")); } else if (noarg (tok, "release")) lglrelease (lgl); else perr ("invalid command '%s'", tok); lineno++; len = 0; goto NEXT; DONE: if(close == 1) fclose (file); if(close == 2) pclose (file); msg ("done %s", name); return 0; }
int main(int argc, char **argv) { pthread_t thr; char *host; int port; int i; int c; char random_state[16]; while ((c = getopt(argc, argv, "c:g:i:k:r:t:")) != EOF) { switch (c) { case 'c': num_connections = intarg(argv[0], optarg); break; case 'g': probability_get = intarg(argv[0], optarg); break; case 'i': num_iterations = intarg(argv[0], optarg); break; case 'k': num_keys = intarg(argv[0], optarg); break; case 'r': num_requests = intarg(argv[0], optarg); break; case 's': seed = intarg(argv[0], optarg); break; case 't': poll_wait_sec = intarg(argv[0], optarg); break; default: usage(argv[0]); break; } } initstate(seed, random_state, sizeof(random_state)); if (argc < optind + 2) usage(argv[0]); host = argv[optind++]; port = intarg(argv[0], argv[optind]); fds = malloc(num_connections * sizeof(int)); if (fds == NULL) { perror("malloc"); exit(1); } for (i = 0; i < num_connections; i++) { fds[i] = clientsock(host, port); if (fds[i] < 0) { perror(host); exit(1); } if ((i % 25) == 0) { printf("\rOpened %d connections", i); fflush(stdout); } set_nodelay(fds[i], 1); set_nonblock(fds[i]); } printf("\rOpened %d connections\n", num_connections); fd_in_use = calloc(1, fds[num_connections - 1]); if (fd_in_use == NULL) { perror("calloc"); exit(1); } pthread_mutex_init(&stats_mutex, NULL); pthread_mutex_init(&fd_mutex, NULL); for (i = 0; i < num_requests; i++) pthread_create(&thr, NULL, thread_main, NULL); while (iteration_count < num_iterations) { poll(NULL, 0, 1000); stats(); } stats(); putchar('\n'); }