diff options
author | Håvard Pettersen <havardpe@oath.com> | 2022-03-31 11:44:10 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2022-04-01 10:24:32 +0000 |
commit | d71f76a73fe54558f613e75a3a8cfd70fc46a7e8 (patch) | |
tree | 7d170e5b792dbf5fed06ff7c7b2db398b6cb64c7 /fbench | |
parent | 1bb3dd192f4bcb91e710fe19ca54b2b8935ffb83 (diff) |
use getopt/getopt_long directly
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/fbench/fbench.cpp | 50 | ||||
-rw-r--r-- | fbench/src/filterfile/filterfile.cpp | 8 | ||||
-rw-r--r-- | fbench/src/splitfile/splitfile.cpp | 18 | ||||
-rw-r--r-- | fbench/src/util/filereader.cpp | 12 | ||||
-rw-r--r-- | fbench/src/util/filereader.h | 4 |
5 files changed, 35 insertions, 57 deletions
diff --git a/fbench/src/fbench/fbench.cpp b/fbench/src/fbench/fbench.cpp index 0cd9498258e..c69d4f5af18 100644 --- a/fbench/src/fbench/fbench.cpp +++ b/fbench/src/fbench/fbench.cpp @@ -18,6 +18,7 @@ #include <csignal> #include <cinttypes> #include <cstdlib> +#include <unistd.h> namespace { @@ -367,66 +368,63 @@ FBench::Main(int argc, char *argv[]) int printInterval = 0; // parse options and override defaults. - int idx; int opt; - const char *arg; bool optError; - idx = 1; optError = false; - while((opt = GetOpt(argc, argv, "H:A:T:C:K:Da:n:c:l:i:s:q:o:r:m:p:kdxyzP", arg, idx)) != -1) { + while((opt = getopt(argc, argv, "H:A:T:C:K:Da:n:c:l:i:s:q:o:r:m:p:kdxyzP")) != -1) { switch(opt) { case 'A': - authority = arg; + authority = optarg; break; case 'H': - extraHeaders += std::string(arg) + "\r\n"; - if (strncmp(arg, "Host:", 5) == 0) { + extraHeaders += std::string(optarg) + "\r\n"; + if (strncmp(optarg, "Host:", 5) == 0) { fprintf(stderr, "Do not override 'Host:' header, use -A option instead\n"); return -1; } break; case 'T': - ca_certs_file_name = std::string(arg); + ca_certs_file_name = std::string(optarg); break; case 'C': - cert_chain_file_name = std::string(arg); + cert_chain_file_name = std::string(optarg); break; case 'K': - private_key_file_name = std::string(arg); + private_key_file_name = std::string(optarg); break; case 'D': allow_default_tls = true; break; case 'a': - queryStringToAppend = std::string(arg); + queryStringToAppend = std::string(optarg); break; case 'n': - numClients = atoi(arg); + numClients = atoi(optarg); break; case 'c': - cycleTime = atoi(arg); + cycleTime = atoi(optarg); break; case 'l': - byteLimit = atoi(arg); + byteLimit = atoi(optarg); break; case 'i': - ignoreCount = atoi(arg); + ignoreCount = atoi(optarg); break; case 's': - seconds = atoi(arg); + seconds = atoi(optarg); break; case 'q': - queryFilePattern = arg; + queryFilePattern = optarg; break; case 'o': - outputFilePattern = arg; + outputFilePattern = optarg; break; case 'r': - restartLimit = atoi(arg); + restartLimit = atoi(optarg); break; case 'm': - maxLineSize = atoi(arg); + maxLineSize = atoi(optarg); if (maxLineSize < minLineSize) { maxLineSize = minLineSize; } @@ -435,7 +433,7 @@ FBench::Main(int argc, char *argv[]) usePostMode = true; break; case 'p': - printInterval = atoi(arg); + printInterval = atoi(optarg); if (printInterval < 0) optError = true; break; @@ -461,12 +459,12 @@ FBench::Main(int argc, char *argv[]) } } - if ( argc < (idx + 2) || optError) { + if ( argc < (optind + 2) || optError) { Usage(); return -1; } // Hostname/port must be in pair - int args = (argc - idx); + int args = (argc - optind); if (args % 2 != 0) { fprintf(stderr, "Not equal number of hostnames and ports\n"); return -1; @@ -481,10 +479,10 @@ FBench::Main(int argc, char *argv[]) for (int i=0; i<hosts; ++i) { - _hostnames.push_back(std::string(argv[idx+2*i])); - int port = atoi(argv[idx+2*i+1]); + _hostnames.push_back(std::string(argv[optind+2*i])); + int port = atoi(argv[optind+2*i+1]); if (port == 0) { - fprintf(stderr, "Not a valid port:\t%s\n", argv[idx+2*i+1]); + fprintf(stderr, "Not a valid port:\t%s\n", argv[optind+2*i+1]); return -1; } _ports.push_back(port); diff --git a/fbench/src/filterfile/filterfile.cpp b/fbench/src/filterfile/filterfile.cpp index 446a4ae2429..7c2edce3640 100644 --- a/fbench/src/filterfile/filterfile.cpp +++ b/fbench/src/filterfile/filterfile.cpp @@ -3,6 +3,7 @@ #include <iostream> #include <string.h> #include <cassert> +#include <unistd.h> /** * Extract query urls from web logs. The filterfile application reads @@ -20,14 +21,11 @@ main(int argc, char** argv) int bufsize = 10240; // parse options and override defaults. - int optIdx; int opt; - const char *arg; bool optError; - optIdx = 1; optError = false; - while((opt = GetOpt(argc, argv, "ahm:", arg, optIdx)) != -1) { + while((opt = getopt(argc, argv, "ahm:")) != -1) { switch(opt) { case 'a': allowAllParams = true; @@ -36,7 +34,7 @@ main(int argc, char** argv) showUsage = true; break; case 'm': - bufsize = atoi(arg); + bufsize = atoi(optarg); if (bufsize < 10240) { bufsize = 10240; } diff --git a/fbench/src/splitfile/splitfile.cpp b/fbench/src/splitfile/splitfile.cpp index abf42f0e9ba..d3c4fc35b54 100644 --- a/fbench/src/splitfile/splitfile.cpp +++ b/fbench/src/splitfile/splitfile.cpp @@ -3,6 +3,7 @@ #include <fstream> #include <vector> #include <memory> +#include <unistd.h> /** * Split a text file randomly in a number of parts. Process an input @@ -19,20 +20,17 @@ main(int argc, char** argv) int linebufsize = 10240; // parse options and override defaults. - int idx; int opt; - const char *arg; bool optError; - idx = 1; optError = false; - while((opt = GetOpt(argc, argv, "p:m:", arg, idx)) != -1) { + while((opt = getopt(argc, argv, "p:m:")) != -1) { switch(opt) { case 'p': - pattern = arg; + pattern = optarg; break; case 'm': - linebufsize = atoi(arg); + linebufsize = atoi(optarg); if (linebufsize < 10240) { linebufsize = 10240; } @@ -43,7 +41,7 @@ main(int argc, char** argv) } } - if (argc < (idx + 1) || argc > (idx + 2) || optError) { + if (argc < (optind + 1) || argc > (optind + 2) || optError) { printf("usage: vespa-fbench-split-file [-p pattern] [-m maxLineSize] <numparts> [<file>]\n\n"); printf(" -p pattern : output name pattern ['query%%03d.txt']\n"); printf(" -m <num> : max line size for input/output lines.\n"); @@ -57,7 +55,7 @@ main(int argc, char** argv) return -1; } - int outcnt = atoi(argv[idx]); + int outcnt = atoi(argv[optind]); if (outcnt < 1) { printf("too few output files!\n"); return -1; @@ -70,8 +68,8 @@ main(int argc, char** argv) std::unique_ptr<FileReader> input = std::make_unique<FileReader>(); std::vector<std::unique_ptr<std::ostream>> output; - if (argc > (idx + 1)) { - if (!input->Open(argv[idx + 1])) { + if (argc > (optind + 1)) { + if (!input->Open(argv[optind + 1])) { printf("could not open input file!\n"); return -1; } diff --git a/fbench/src/util/filereader.cpp b/fbench/src/util/filereader.cpp index 71c1b5ae703..1b2ce61dfc3 100644 --- a/fbench/src/util/filereader.cpp +++ b/fbench/src/util/filereader.cpp @@ -4,18 +4,6 @@ #include <unistd.h> #include <vespa/vespalib/util/size_literals.h> -int GetOpt (int argc, char *argv[], const char *optionsString, - const char* &optionArgument, - int &optionIndex) -{ - optind = optionIndex; - - int rc = getopt(argc, argv, optionsString); - optionArgument = optarg; - optionIndex = optind; - return rc; -} - FileReader::FileReader() : _backing(), _file(&std::cin), diff --git a/fbench/src/util/filereader.h b/fbench/src/util/filereader.h index 96fae6d2858..0cf8bdae2ea 100644 --- a/fbench/src/util/filereader.h +++ b/fbench/src/util/filereader.h @@ -5,10 +5,6 @@ #include <memory> #include <vector> -int GetOpt (int argc, char *argv[], const char *optionsString, - const char* &optionArgument, - int &optionIndex); - /** * This is a wrapper class for std::ifstream that may be used when * reading line based text files. An internal buffer is used to |