xrootd
Loading...
Searching...
No Matches
XrdClReplayArgs.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2021 by European Organization for Nuclear Research (CERN)
3// Author: Andreas-Joachim Peters <andreas.joachim.peters@cern.ch>
4//------------------------------------------------------------------------------
5// This file is part of the XRootD software suite.
6//
7// XRootD is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// XRootD is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19//
20// In applying this licence, CERN does not waive the privileges and immunities
21// granted to it by virtue of its status as an Intergovernmental Organization
22// or submit itself to any jurisdiction.
23//------------------------------------------------------------------------------
24
25#include <stdarg.h>
26#include <getopt.h>
27#include <regex>
28#include <map>
29#include <vector>
30namespace XrdCl
31{
32//------------------------------------------------------------------------------
34//------------------------------------------------------------------------------
36{
37 public:
38 ReplayArgs(int argc, char* argv[])
39 : option_long(false)
40 , option_summary(false)
41 , option_print(false)
42 , option_create(false)
43 , option_truncate(false)
44 , option_json(false)
46 , option_verify(false)
47 , option_speed(1.0)
48 {
49 while (1)
50 {
51 int option_index = 0;
52 static struct option long_options[]
53 = { { "help", no_argument, 0, 'h' }, { "print", no_argument, 0, 'p' },
54 { "create", no_argument, 0, 'c' }, { "truncate", no_argument, 0, 't' },
55 { "long", no_argument, 0, 'l' }, { "json", no_argument, 0, 'j' },
56 { "summary", no_argument, 0, 's' }, { "replace", required_argument, 0, 'r' },
57 { "suppress", no_argument, 0, 'f' }, { "verify", no_argument, 0, 'v' },
58 { "speed", required_argument, 0, 'x' }, { 0, 0, 0, 0 } };
59
60 int c = getopt_long(argc, argv, "vjpctshlfr:x:", long_options, &option_index);
61 if (c == -1)
62 break;
63
64 switch (c)
65 {
66 case 'h':
67 usage();
68 break;
69
70 case 'c':
71 option_create = true;
72 option_print = true; // create mode requires to run in simulated mode (print)
73 break;
74
75 case 't':
76 option_create = true;
77 option_print = true; // truncate mode requires to run in simulated mode (print)
78 option_truncate = true;
79 break;
80
81 case 'j':
82 option_json = true;
83 break;
84
85 case 'p':
86 option_print = true;
87 break;
88
89 case 's':
90 option_summary = true;
91 break;
92
93 case 'l':
94 option_long = true;
95 break;
96
97 case 'v':
98 option_verify = true;
99 break;
100
101 case 'x':
102 option_speed = std::strtod(optarg, 0);
103 if (option_speed <= 0)
104 {
105 usage();
106 }
107 break;
108
109 case 'r':
110 option_regex.push_back(optarg);
111 break;
112
113 case 'f':
115 break;
116
117 default:
118 usage();
119 }
120 }
121
124
125 if (option_verify)
126 {
127 option_print = true;
128 option_create = false;
129 option_truncate = false;
130 option_json = false;
131 }
132
133 if (optind < (argc - 1))
134 {
135 usage();
136 }
137
138 if (optind == (argc -1 )) {
139 // we also accept to have no path and read from STDIN
140 _path = argv[optind];
141 }
142 }
143
144 void usage()
145 {
146 std::cerr
147 << "usage: xrdreplay [-p|--print] [-c|--create-data] [t|--truncate-data] [-l|--long] [-s|--summary] [-h|--help] [-r|--replace <arg>:=<newarg>] [-f|--suppress] [-v|--verify] [-x|--speed <value] p<recordfilename>]\n"
148 << std::endl;
149 std::cerr << " -h | --help : show this help" << std::endl;
150 std::cerr
151 << " -f | --suppress : force to run all IO with all successful result status - suppress all others"
152 << std::endl;
153 std::cerr
154 << " - by default the player won't run with an unsuccessful recorded IO"
155 << std::endl;
156 std::cerr << std::endl;
157 std::cerr
158 << " -p | --print : print only mode - shows all the IO for the given replay file without actually running any IO"
159 << std::endl;
160 std::cerr
161 << " -s | --summary : print summary - shows all the aggregated IO counter summed for all files"
162 << std::endl;
163 std::cerr
164 << " -l | --long : print long - show all file IO counter for each individual file"
165 << std::endl;
166 std::cerr << " -v | --verify : verify the existence of all input files"
167 << std::endl;
168 std::cerr
169 << " -x | --speed <x> : change playback speed by factor <x> [ <x> > 0.0 ]"
170 << std::endl;
171 std::cerr
172 << " -r | --replace <a>:=<b> : replace in the argument list the string <a> with <b> "
173 << std::endl;
174 std::cerr
175 << " - option is usable several times e.g. to change storage prefixes or filenames"
176 << std::endl;
177 std::cerr << std::endl;
178 std::cerr
179 << " [recordfilename] : if a file is given, it will be used as record input otherwise STDIN is used to read records!"
180 << std::endl;
181 std::cerr
182 << "example: ... --replace file:://localhost:=root://xrootd.eu/ : redirect local file to remote"
183 << std::endl;
184 std::cerr << std::endl;
185 exit(-1);
186 }
187
188 bool longformat() { return option_long; }
189 bool summary() { return option_summary; }
190 bool print() { return option_print; }
191 bool create() { return option_create; }
192 bool truncate() { return option_truncate; }
193 bool json() { return option_json; }
195 bool verify() { return option_verify; }
196 double speed() { return option_speed; }
197 std::vector<std::string>& regex() { return option_regex; }
198 std::string& path() { return _path; }
199
200 private:
210 std::vector<std::string> option_regex;
211 std::string _path;
212};
213}
Args parse for XrdClReplay.
Definition XrdClReplayArgs.hh:36
bool suppress_error()
Definition XrdClReplayArgs.hh:194
bool option_json
Definition XrdClReplayArgs.hh:206
bool option_create
Definition XrdClReplayArgs.hh:204
ReplayArgs(int argc, char *argv[])
Definition XrdClReplayArgs.hh:38
double speed()
Definition XrdClReplayArgs.hh:196
bool option_long
Definition XrdClReplayArgs.hh:201
double option_speed
Definition XrdClReplayArgs.hh:209
bool print()
Definition XrdClReplayArgs.hh:190
bool longformat()
Definition XrdClReplayArgs.hh:188
std::string _path
Definition XrdClReplayArgs.hh:211
bool verify()
Definition XrdClReplayArgs.hh:195
std::string & path()
Definition XrdClReplayArgs.hh:198
bool summary()
Definition XrdClReplayArgs.hh:189
bool json()
Definition XrdClReplayArgs.hh:193
bool option_summary
Definition XrdClReplayArgs.hh:202
bool create()
Definition XrdClReplayArgs.hh:191
void usage()
Definition XrdClReplayArgs.hh:144
bool truncate()
Definition XrdClReplayArgs.hh:192
std::vector< std::string > & regex()
Definition XrdClReplayArgs.hh:197
bool option_truncate
Definition XrdClReplayArgs.hh:205
bool option_verify
Definition XrdClReplayArgs.hh:208
bool option_suppress_error
Definition XrdClReplayArgs.hh:207
bool option_print
Definition XrdClReplayArgs.hh:203
std::vector< std::string > option_regex
Definition XrdClReplayArgs.hh:210
Definition XrdClAction.hh:34