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 if (!info)
205 return;
206 std::stringstream ss;
207 ss << std::to_string(info->GetSize()) << ';';
208 ss << std::to_string(info->GetFlags()) << ';';
209 ss << info->GetModTime() << ';';
210 ss << info->GetChangeTime() << ';';
211 ss << info->GetAccessTime() << ';';
212 ss << info->GetModeAsOctString() << ';';
213 ss << info->GetOwner() << ';';
214 ss << info->GetGroup() << ';';
215 ss << info->GetChecksum();
216 serialrsp = ss.str();
217 }
218
219 bool force;
220};
221
222//----------------------------------------------------------------------------
224//----------------------------------------------------------------------------
225struct ReadAction : public Action
226{
227 ReadAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
228 : Action(file, timeout)
229 , offset(offset)
230 , size(size)
231 {
232 }
233
234 std::string Name() { return "Read"; }
235
236 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
237
238 void Serialize(AnyObject* response)
239 {
240 if (!response)
241 return;
242 ChunkInfo* ptr = nullptr;
243 response->Get(ptr);
244 serialrsp = std::to_string(ptr ? ptr->length : 0);
245 }
246
247 uint64_t offset;
248 uint32_t size;
249};
250
251struct PgReadAction : public Action
252{
253 PgReadAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
254 : Action(file, timeout)
255 , offset(offset)
256 , size(size)
257 {
258 }
259
260 std::string Name() { return "PgRead"; }
261
262 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
263
264 void Serialize(AnyObject* response)
265 {
266 if (!response)
267 return;
268 PageInfo* ptr = nullptr;
269 response->Get(ptr);
270 if (ptr)
271 serialrsp = std::to_string(ptr->GetLength()) + ';' + std::to_string(ptr->GetNbRepair());
272 else
273 serialrsp = "0;0";
274 }
275
276 uint64_t offset;
277 uint32_t size;
278};
279
280//----------------------------------------------------------------------------
282//----------------------------------------------------------------------------
283struct WriteAction : public Action
284{
285 WriteAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
286 : Action(file, timeout)
287 , offset(offset)
288 , size(size)
289 {
290 }
291
292 std::string Name() { return "Write"; }
293
294 std::string ArgStr() { return std::to_string(offset) + ';' + std::to_string(size); }
295
296 uint64_t offset;
297 uint32_t size;
298};
299
300struct PgWriteAction : public Action
301{
302 PgWriteAction(void* file, uint64_t offset, uint32_t size, uint16_t timeout)
303 : Action(file, timeout)
304 , offset(offset)
305 , size(size)
306 {
307 }
308
309 std::string Name() { return "PgWrite"; }
310
311 std::string ArgStr()
312 {
313 std::stringstream ss;
314 ss << std::to_string(offset) << ';' << std::to_string(size);
315 return ss.str();
316 }
317
318 uint64_t offset;
319 uint32_t size;
320};
321
322//----------------------------------------------------------------------------
324//----------------------------------------------------------------------------
325struct SyncAction : public Action
326{
327 SyncAction(void* file, uint16_t timeout)
328 : Action(file, timeout)
329 {
330 }
331
332 std::string Name() { return "Sync"; }
333
334 std::string ArgStr() { return {}; }
335};
336
337//----------------------------------------------------------------------------
339//----------------------------------------------------------------------------
340struct TruncateAction : public Action
341{
342 TruncateAction(void* file, uint64_t size, uint16_t timeout)
343 : Action(file, timeout)
344 , size(size)
345 {
346 }
347
348 std::string Name() { return "Truncate"; }
349
350 std::string ArgStr() { return std::to_string(size); }
351
352 uint32_t size;
353};
354
355//----------------------------------------------------------------------------
357//----------------------------------------------------------------------------
359{
360 VectorReadAction(void* file, const ChunkList& chunks, uint16_t timeout)
361 : Action(file, timeout)
362 , req(chunks)
363 {
364 }
365
366 std::string Name() { return "VectorRead"; }
367
368 std::string ArgStr()
369 {
370 if (req.empty())
371 return {};
372 std::stringstream ss;
373 ss << req[0].offset << ";" << req[0].length;
374 for (size_t i = 1; i < req.size(); ++i)
375 ss << ";" << req[i].offset << ";" << req[i].length;
376 return ss.str();
377 }
378
379 void Serialize(AnyObject* response)
380 {
381 if (!response)
382 return;
383 VectorReadInfo* ptr = nullptr;
384 response->Get(ptr);
385 if (!ptr)
386 return;
387 std::stringstream ss;
388 ss << ptr->GetSize();
389 auto& chunks = ptr->GetChunks();
390 for (auto& ch : chunks)
391 ss << ';' << ch.offset << ';' << ch.length;
392 serialrsp = ss.str();
393 }
394
396};
397
398//----------------------------------------------------------------------------
400//----------------------------------------------------------------------------
402{
403 VectorWriteAction(void* file, const ChunkList& chunks, uint16_t timeout)
404 : Action(file, timeout)
405 , req(chunks)
406 {
407 }
408
409 std::string Name() { return "VectorWrite"; }
410
411 std::string ArgStr()
412 {
413 if (req.empty())
414 return {};
415 std::stringstream ss;
416 ss << req[0].offset << ";" << req[0].length;
417 for (size_t i = 1; i < req.size(); ++i)
418 ss << ";" << req[i].offset << ";" << req[i].length;
419 return ss.str();
420 }
421
423};
424
425//----------------------------------------------------------------------------
427//----------------------------------------------------------------------------
429{
430 FcntlAction(void* file, const Buffer& arg, uint16_t timeout)
431 : Action(file, timeout)
432 , req(arg.GetSize())
433 {
434 }
435
436 std::string Name() { return "Fcntl"; }
437
438 std::string ArgStr() { return std::to_string(req); }
439
440 void Serialize(AnyObject* response)
441 {
442 if (!response)
443 return;
444 Buffer* ptr = nullptr;
445 response->Get(ptr);
446 serialrsp = std::to_string(ptr ? ptr->GetSize() : 0);
447 }
448
449 uint32_t req;
450};
451
452} /* namespace XrdCl */
453
454#endif /* SRC_XRDAPPS_RECORDPLUGIN_XRDCLACTION_HH_ */
void Get(Type &object)
Retrieve the object being held.
Binary blob representation.
uint32_t GetSize() const
Get the size of the message.
Object stat info.
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.
uint32_t GetSize() const
Get Size.
ChunkList & GetChunks()
Get chunks.
std::vector< ChunkInfo > ChunkList
List of chunks.
std::string serialrsp
virtual std::string Name()=0
Action name.
uint16_t timeout
virtual std::string ArgStr()=0
Convert operation arguments into a string.
std::chrono::system_clock::time_point start
XRootDStatus status
static double time(std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > tp)
Convert timpoint to unix timestamp with ns.
std::chrono::system_clock::time_point stop
virtual ~Action()
Destructor.
static double timeNow()
Get curretn unix time in ns precision as a double.
virtual void Serialize(AnyObject *response)
Serialize server response.
void RecordResult(XRootDStatus *st, AnyObject *rsp)
Record the server response / error / timeout.
std::string ToString()
Convert the action / response data into csv row.
Action(void *file, uint16_t timeout)
Describe a data chunk for vector read.
uint32_t length
offset in the file
Close action.
std::string Name()
Action name.
std::string ArgStr()
Convert operation arguments into a string.
CloseAction(void *file, uint16_t timeout)
Fcntl action.
FcntlAction(void *file, const Buffer &arg, uint16_t timeout)
std::string Name()
Action name.
void Serialize(AnyObject *response)
Serialize server response.
std::string ArgStr()
Convert operation arguments into a string.
const std::string url
OpenFlags::Flags flags
OpenAction(void *file, const std::string &url, OpenFlags::Flags flags, Access::Mode mode, uint16_t timeout)
Access::Mode mode
std::string Name()
Action name.
std::string ArgStr()
Convert operation arguments into a string.
Flags
Open flags, may be or'd when appropriate.
size_t GetNbRepair()
Get number of repaired pages.
uint32_t GetLength() const
Get the data length.
std::string ArgStr()
Convert operation arguments into a string.
void Serialize(AnyObject *response)
Serialize server response.
std::string Name()
Action name.
PgReadAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
PgWriteAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
std::string Name()
Action name.
std::string ArgStr()
Convert operation arguments into a string.
ReadAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)
std::string Name()
Action name.
void Serialize(AnyObject *response)
Serialize server response.
std::string ArgStr()
Convert operation arguments into a string.
std::string Name()
Action name.
void Serialize(AnyObject *response)
Serialize server response.
std::string ArgStr()
Convert operation arguments into a string.
StatAction(void *file, bool force, uint16_t timeout)
std::string ToString() const
Create a string representation.
std::string Name()
Action name.
std::string ArgStr()
Convert operation arguments into a string.
SyncAction(void *file, uint16_t timeout)
Truncate action.
std::string ArgStr()
Convert operation arguments into a string.
TruncateAction(void *file, uint64_t size, uint16_t timeout)
std::string Name()
Action name.
VectorRead action.
std::string Name()
Action name.
VectorReadAction(void *file, const ChunkList &chunks, uint16_t timeout)
std::string ArgStr()
Convert operation arguments into a string.
void Serialize(AnyObject *response)
Serialize server response.
Vector Write action.
std::string ArgStr()
Convert operation arguments into a string.
std::string Name()
Action name.
VectorWriteAction(void *file, const ChunkList &chunks, uint16_t timeout)
Write action.
std::string ArgStr()
Convert operation arguments into a string.
std::string Name()
Action name.
WriteAction(void *file, uint64_t offset, uint32_t size, uint16_t timeout)