xrootd
Loading...
Searching...
No Matches
XrdClAction.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN)
3// Author: Michal Simon <michal.simon@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#ifndef SRC_XRDAPPS_RECORDPLUGIN_XRDCLACTION_HH_
25#define SRC_XRDAPPS_RECORDPLUGIN_XRDCLACTION_HH_
26
27#include <sstream>
28#include <chrono>
29#include <ctime>
30#include <iomanip>
32
33namespace XrdCl
34{
35//----------------------------------------------------------------------------
37//----------------------------------------------------------------------------
38struct Action
39{
40 //--------------------------------------------------------------------------
41 // Constructor
42 // @param file : pointer to the file plug-in that recorded the action
43 // (to be used as an ID)
44 // @param timeout : operation timeout (common for every operation)
45 //--------------------------------------------------------------------------
46 Action(void* file, uint16_t timeout)
47 : id(reinterpret_cast<uint64_t>(file))
49 , start(std::chrono::system_clock::now()) // register the action start time
50 {
51 }
52
53 //--------------------------------------------------------------------------
55 //--------------------------------------------------------------------------
56 inline void RecordResult(XRootDStatus* st, AnyObject* rsp)
57 {
58 stop = std::chrono::system_clock::now(); // register the response time
59 status = *st;
60 Serialize(rsp);
61 }
62
63 //--------------------------------------------------------------------------
65 //--------------------------------------------------------------------------
66 static inline double time(
67 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp)
68 {
69 auto secs = std::chrono::time_point_cast<std::chrono::seconds>(tp);
70 auto ns = std::chrono::time_point_cast<std::chrono::nanoseconds>(tp)
71 - std::chrono::time_point_cast<std::chrono::nanoseconds>(secs);
72 return secs.time_since_epoch().count() + ns.count() / 1000000000.0;
73 }
74
75 //--------------------------------------------------------------------------
77 //--------------------------------------------------------------------------
78 static inline double timeNow()
79 {
80 auto now = std::chrono::system_clock::now();
81 return time(now);
82 }
83
84
85 //--------------------------------------------------------------------------
87 //--------------------------------------------------------------------------
88 inline std::string ToString()
89 {
90 std::stringstream ss;
91 ss << "\"" << id << "\"" << ',';
92 ss << "\"" << Name() << "\"" << ',';
93
94 double tstart = time(start);
95 double tstop = time(stop);
96 ss << "\"" << std::fixed << std::setprecision(9) << tstart << "\"" << ",";
97 std::string argstr = ArgStr();
98 if (!argstr.empty())
99 argstr += ';';
100 ss << "\"" << argstr << timeout << "\"" << ',';
101 ss << "\"" << std::fixed << std::setprecision(9) << tstop << "\"" << ",";
102 auto ststr = status.ToString();
103 while (ststr.back() == ' ')
104 ststr.pop_back();
105 ss << "\"" << ststr << "\"" << ',';
106 ss << "\"" << serialrsp << "\"" << '\n';
107 return ss.str();
108 }
109
110 //--------------------------------------------------------------------------
112 //--------------------------------------------------------------------------
113 virtual ~Action() {}
114
115 //--------------------------------------------------------------------------
117 //--------------------------------------------------------------------------
118 virtual std::string Name() = 0;
119
120 //--------------------------------------------------------------------------
122 //--------------------------------------------------------------------------
123 virtual std::string ArgStr() = 0;
124
125 //--------------------------------------------------------------------------
127 //--------------------------------------------------------------------------
128 virtual void Serialize(AnyObject* response) {}
129
130 uint64_t id; //> File object ID
131 uint16_t timeout; //> operation timeout
132 std::chrono::system_clock::time_point start; //> start time
133 XRootDStatus status; //> operation status
134 std::string serialrsp; //> serialized response
135 std::chrono::system_clock::time_point stop; //> response time
136};
137
138//----------------------------------------------------------------------------
140//----------------------------------------------------------------------------
141struct OpenAction : public Action
142{
144 void* file, const std::string& url, OpenFlags::Flags flags, Access::Mode mode, uint16_t timeout)
145 : Action(file, timeout)
146 , url(url)
147 , flags(flags)
148 , mode(mode)
149 {
150 }
151
152 std::string Name() { return "Open"; }
153
154 std::string ArgStr()
155 {
156 std::stringstream ss;
157 ss << url << ';';
158 ss << flags << ';';
159 ss << mode;
160 return ss.str();
161 }
162
163 const std::string url;
166};
167
168//----------------------------------------------------------------------------
170//----------------------------------------------------------------------------
171struct CloseAction : public Action
172{
173 CloseAction(void* file, uint16_t timeout)
174 : Action(file, timeout)
175 {
176 }
177
178 std::string Name() { return "Close"; }
179
180 std::string ArgStr() { return {}; }
181};
182
183//----------------------------------------------------------------------------
185//----------------------------------------------------------------------------
186struct StatAction : public Action
187{
188 StatAction(void* file, bool force, uint16_t timeout)
189 : Action(file, timeout)
190 , force(force)
191 {
192 }
193
194 std::string Name() { return "Stat"; }
195
196 std::string ArgStr() { return force ? "true" : "false"; }
197
198 void Serialize(AnyObject* response)
199 {
200 if (!response)
201 return;
202 StatInfo* info = nullptr;
203 response->Get(info);
204 std::stringstream ss;
205 ss << std::to_string(info->GetSize()) << ';';
206 ss << std::to_string(info->GetFlags()) << ';';
207 ss << info->GetModTime() << ';';
208 ss << info->GetChangeTime() << ';';
209 ss << info->GetAccessTime() << ';';
210 ss << info->GetModeAsOctString() << ';';
211 ss << info->GetOwner() << ';';
212 ss << info->GetGroup() << ';';
213 ss << info->GetChecksum();
214 serialrsp = ss.str();
215 }
216
217 bool force;
218};
219
220//----------------------------------------------------------------------------
222//----------------------------------------------------------------------------
223struct ReadAction : public Action
224{
225 ReadAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
226 : Action(file, timeout)
227 , offset(offset)
228 , size(size)
229 {
230 }
231
232 std::string Name() { return "Read"; }
233
234 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
235
236 void Serialize(AnyObject* response)
237 {
238 if (!response)
239 return;
240 ChunkInfo* ptr = nullptr;
241 response->Get(ptr);
242 serialrsp = std::to_string(ptr->length);
243 }
244
245 uint64_t offset;
246 uint32_t size;
247};
248
249struct PgReadAction : public Action
250{
251 PgReadAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
252 : Action(file, timeout)
253 , offset(offset)
254 , size(size)
255 {
256 }
257
258 std::string Name() { return "PgRead"; }
259
260 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
261
262 void Serialize(AnyObject* response)
263 {
264 if (!response)
265 return;
266 PageInfo* ptr = nullptr;
267 response->Get(ptr);
268 serialrsp = std::to_string(ptr->GetLength()) + ';' + std::to_string(ptr->GetNbRepair());
269 }
270
271 uint64_t offset;
272 uint32_t size;
273};
274
275//----------------------------------------------------------------------------
277//----------------------------------------------------------------------------
278struct WriteAction : public Action
279{
280 WriteAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
281 : Action(file, timeout)
282 , offset(offset)
283 , size(size)
284 {
285 }
286
287 std::string Name() { return "Write"; }
288
289 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
290
291 uint64_t offset;
292 uint32_t size;
293};
294
295struct PgWriteAction : public Action
296{
297 PgWriteAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
298 : Action(file, timeout)
299 , offset(offset)
300 , size(size)
301 {
302 }
303
304 std::string Name() { return "PgWrite"; }
305
306 std::string ArgStr()
307 {
308 std::stringstream ss;
309 ss << std::to_string(offset) << ';' << std::to_string(size);
310 return ss.str();
311 }
312
313 uint64_t offset;
314 uint32_t size;
315};
316
317//----------------------------------------------------------------------------
319//----------------------------------------------------------------------------
320struct SyncAction : public Action
321{
322 SyncAction(void* file, uint16_t timeout)
323 : Action(file, timeout)
324 {
325 }
326
327 std::string Name() { return "Sync"; }
328
329 std::string ArgStr() { return {}; }
330};
331
332//----------------------------------------------------------------------------
334//----------------------------------------------------------------------------
335struct TruncateAction : public Action
336{
337 TruncateAction(void* file, uint64_t size, uint16_t timeout)
338 : Action(file, timeout)
339 , size(size)
340 {
341 }
342
343 std::string Name() { return "Truncate"; }
344
345 std::string ArgStr() { return std::to_string(size); }
346
347 uint32_t size;
348};
349
350//----------------------------------------------------------------------------
352//----------------------------------------------------------------------------
354{
355 VectorReadAction(void* file, const ChunkList& chunks, uint16_t timeout)
356 : Action(file, timeout)
357 , req(chunks)
358 {
359 }
360
361 std::string Name() { return "VectorRead"; }
362
363 std::string ArgStr()
364 {
365 if (req.empty())
366 return {};
367 std::stringstream ss;
368 ss << req[0].offset << ";" << req[0].length;
369 for (size_t i = 1; i < req.size(); ++i)
370 ss << ";" << req[i].offset << ";" << req[i].length;
371 return ss.str();
372 }
373
374 void Serialize(AnyObject* response)
375 {
376 if (!response)
377 return;
378 VectorReadInfo* ptr = nullptr;
379 response->Get(ptr);
380 std::stringstream ss;
381 ss << ptr->GetSize();
382 auto& chunks = ptr->GetChunks();
383 for (auto& ch : chunks)
384 ss << ';' << ch.offset << ';' << ch.length;
385 serialrsp = ss.str();
386 }
387
389};
390
391//----------------------------------------------------------------------------
393//----------------------------------------------------------------------------
395{
396 VectorWriteAction(void* file, const ChunkList& chunks, uint16_t timeout)
397 : Action(file, timeout)
398 , req(chunks)
399 {
400 }
401
402 std::string Name() { return "VectorWrite"; }
403
404 std::string ArgStr()
405 {
406 if (req.empty())
407 return {};
408 std::stringstream ss;
409 ss << req[0].offset << ";" << req[0].length;
410 for (size_t i = 1; i < req.size(); ++i)
411 ss << ";" << req[i].offset << ";" << req[i].length;
412 return ss.str();
413 }
414
416};
417
418//----------------------------------------------------------------------------
420//----------------------------------------------------------------------------
422{
423 FcntlAction(void* file, const Buffer& arg, uint16_t timeout)
424 : Action(file, timeout)
425 , req(arg.GetSize())
426 {
427 }
428
429 std::string Name() { return "Fcntl"; }
430
431 std::string ArgStr() { return std::to_string(req); }
432
433 void Serialize(AnyObject* response)
434 {
435 if (!response)
436 return;
437 Buffer* ptr = nullptr;
438 response->Get(ptr);
439 serialrsp = std::to_string(ptr->GetSize());
440 }
441
442 uint32_t req;
443};
444
445} /* namespace XrdCl */
446
447#endif /* SRC_XRDAPPS_RECORDPLUGIN_XRDCLACTION_HH_ */
Definition XrdClAnyObject.hh:33
void Get(Type &object)
Retrieve the object being held.
Definition XrdClAnyObject.hh:78
Binary blob representation.
Definition XrdClBuffer.hh:34
uint32_t GetSize() const
Get the size of the message.
Definition XrdClBuffer.hh:132
Object stat info.
Definition XrdClXRootDResponses.hh:400
uint64_t GetChangeTime() const
Get change time (in seconds since epoch)
uint64_t GetSize() const
Get size (in bytes)
const std::string GetModeAsOctString() const
Get mode.
const std::string & GetOwner() const
Get owner.
uint32_t GetFlags() const
Get flags.
const std::string & GetGroup() const
Get group.
uint64_t GetModTime() const
Get modification time (in seconds since epoch)
uint64_t GetAccessTime() const
Get change time (in seconds since epoch)
const std::string & GetChecksum() const
Get checksum.
Vector read info.
Definition XrdClXRootDResponses.hh:1061
uint32_t GetSize() const
Get Size.
Definition XrdClXRootDResponses.hh:1071
ChunkList & GetChunks()
Get chunks.
Definition XrdClXRootDResponses.hh:1087
Request status.
Definition XrdClXRootDResponses.hh:219
Definition XrdClAction.hh:34
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition XrdClXRootDResponses.hh:1055
Definition XrdOucJson.hh:4517
Mode
Access mode.
Definition XrdClFileSystem.hh:122
Action.
Definition XrdClAction.hh:39
std::string serialrsp
Definition XrdClAction.hh:134
virtual std::string Name()=0
Action name.
uint16_t timeout
Definition XrdClAction.hh:131
virtual std::string ArgStr()=0
Convert operation arguments into a string.
std::chrono::system_clock::time_point start
Definition XrdClAction.hh:132
XRootDStatus status
Definition XrdClAction.hh:133
static double time(std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > tp)
Convert timpoint to unix timestamp with ns.
Definition XrdClAction.hh:66
std::chrono::system_clock::time_point stop
Definition XrdClAction.hh:135
virtual ~Action()
Destructor.
Definition XrdClAction.hh:113
static double timeNow()
Get curretn unix time in ns precision as a double.
Definition XrdClAction.hh:78
uint64_t id
Definition XrdClAction.hh:130
virtual void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:128
void RecordResult(XRootDStatus *st, AnyObject *rsp)
Record the server response / error / timeout.
Definition XrdClAction.hh:56
std::string ToString()
Convert the action / response data into csv row.
Definition XrdClAction.hh:88
Action(void *file, uint16_t timeout)
Definition XrdClAction.hh:46
Describe a data chunk for vector read.
Definition XrdClXRootDResponses.hh:917
uint32_t length
offset in the file
Definition XrdClXRootDResponses.hh:949
Close action.
Definition XrdClAction.hh:172
std::string Name()
Action name.
Definition XrdClAction.hh:178
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:180
CloseAction(void *file, uint16_t timeout)
Definition XrdClAction.hh:173
Fcntl action.
Definition XrdClAction.hh:422
uint32_t req
Definition XrdClAction.hh:442
FcntlAction(void *file, const Buffer &arg, uint16_t timeout)
Definition XrdClAction.hh:423
std::string Name()
Action name.
Definition XrdClAction.hh:429
void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:433
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:431
Open action.
Definition XrdClAction.hh:142
const std::string url
Definition XrdClAction.hh:163
OpenFlags::Flags flags
Definition XrdClAction.hh:164
OpenAction(void *file, const std::string &url, OpenFlags::Flags flags, Access::Mode mode, uint16_t timeout)
Definition XrdClAction.hh:143
Access::Mode mode
Definition XrdClAction.hh:165
std::string Name()
Action name.
Definition XrdClAction.hh:152
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:154
Flags
Open flags, may be or'd when appropriate.
Definition XrdClFileSystem.hh:76
Definition XrdClXRootDResponses.hh:956
size_t GetNbRepair()
Get number of repaired pages.
uint32_t GetLength() const
Get the data length.
Definition XrdClAction.hh:250
uint64_t offset
Definition XrdClAction.hh:271
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:260
void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:262
std::string Name()
Action name.
Definition XrdClAction.hh:258
PgReadAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
Definition XrdClAction.hh:251
uint32_t size
Definition XrdClAction.hh:272
Definition XrdClAction.hh:296
uint32_t size
Definition XrdClAction.hh:314
uint64_t offset
Definition XrdClAction.hh:313
PgWriteAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
Definition XrdClAction.hh:297
std::string Name()
Action name.
Definition XrdClAction.hh:304
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:306
Read action.
Definition XrdClAction.hh:224
ReadAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
Definition XrdClAction.hh:225
uint32_t size
Definition XrdClAction.hh:246
std::string Name()
Action name.
Definition XrdClAction.hh:232
uint64_t offset
Definition XrdClAction.hh:245
void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:236
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:234
Stat action.
Definition XrdClAction.hh:187
bool force
Definition XrdClAction.hh:217
std::string Name()
Action name.
Definition XrdClAction.hh:194
void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:198
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:196
StatAction(void *file, bool force, uint16_t timeout)
Definition XrdClAction.hh:188
std::string ToString() const
Create a string representation.
Sync action.
Definition XrdClAction.hh:321
std::string Name()
Action name.
Definition XrdClAction.hh:327
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:329
SyncAction(void *file, uint16_t timeout)
Definition XrdClAction.hh:322
Truncate action.
Definition XrdClAction.hh:336
uint32_t size
Definition XrdClAction.hh:347
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:345
TruncateAction(void *file, uint64_t size, uint16_t timeout)
Definition XrdClAction.hh:337
std::string Name()
Action name.
Definition XrdClAction.hh:343
VectorRead action.
Definition XrdClAction.hh:354
std::string Name()
Action name.
Definition XrdClAction.hh:361
VectorReadAction(void *file, const ChunkList &chunks, uint16_t timeout)
Definition XrdClAction.hh:355
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:363
ChunkList req
Definition XrdClAction.hh:388
void Serialize(AnyObject *response)
Serialize server response.
Definition XrdClAction.hh:374
Vector Write action.
Definition XrdClAction.hh:395
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:404
ChunkList req
Definition XrdClAction.hh:415
std::string Name()
Action name.
Definition XrdClAction.hh:402
VectorWriteAction(void *file, const ChunkList &chunks, uint16_t timeout)
Definition XrdClAction.hh:396
Write action.
Definition XrdClAction.hh:279
uint32_t size
Definition XrdClAction.hh:292
std::string ArgStr()
Convert operation arguments into a string.
Definition XrdClAction.hh:289
std::string Name()
Action name.
Definition XrdClAction.hh:287
WriteAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
Definition XrdClAction.hh:280
uint64_t offset
Definition XrdClAction.hh:291