XRootD
Loading...
Searching...
No Matches
BufferUtils.hh
Go to the documentation of this file.
1#ifndef __CEPH_BUFFER_UTILS_HH__
2#define __CEPH_BUFFER_UTILS_HH__
3
4// holder of various small utility classes for debugging, profiling, logging, and general stuff
5
6#include <list>
7#include <vector>
8#include <atomic>
9#include <chrono>
10#include <sys/types.h>
11#include <memory>
12#include <mutex>
13#include <sstream>
14#include <iomanip>
15#include <ctime>
16
17
18// basic logging
19// #TODO; merge this into the xrootd logging, when xrootd is available
20#define CEPHBUFDEBUG 1
21#ifdef CEPHBUFDEBUG
22extern std::mutex cephbuf_iolock;
23#define BUFLOG(x) {std::unique_lock<std::mutex>cephbuf_iolock; std::stringstream _bs; _bs << x; std::clog << _bs.str() << std::endl;}
24#else
25#define BUFLOG(x)
26#endif
27
29{
30
31
33 {
41 public:
42 explicit Timer_ns(long &output_ns);
43 ~Timer_ns();
44
45 private:
46 std::chrono::steady_clock::time_point m_start;
47 long &m_output_val;
48
49 }; //Timer_ns
50
51
52
53 class Extent
54 {
63 public:
64 Extent(off_t offset, size_t len) : m_offset(offset), m_len(len){}
65 inline off_t offset() const { return m_offset; }
66 inline size_t len() const { return m_len; }
67 inline off_t begin() const { return m_offset; }
68 inline off_t end() const { return m_offset + m_len; }
69 inline bool empty() const {return m_len == 0;}
70
75 bool isContiguous(const Extent& rhs) const;
76
77 inline off_t last_pos() const { return m_offset + m_len - 1; }
78
79 bool in_extent(off_t pos) const;
80 bool allInExtent(off_t pos, size_t len) const;
81 bool someInExtent(off_t pos, size_t len) const;
82
83 Extent containedExtent(off_t pos, size_t len) const;
84 Extent containedExtent(const Extent &in) const;
85
86 bool operator<(const Extent &rhs) const;
87 bool operator==(const Extent &rhs) const;
88
89
90 private:
91 off_t m_offset;
92 size_t m_len;
93 };
94
99 typedef std::vector<Extent> ExtentContainer;
100
110 // holder of a list of extent objects
111 public:
112 ExtentHolder();
113 explicit ExtentHolder(size_t elements);
114 explicit ExtentHolder(const ExtentContainer& extents);
116
117 off_t begin() const {return m_begin;}
118 off_t end() const {return m_end;}
119 size_t len() const {return m_end - m_begin;}
120
121 bool empty() const {return m_extents.empty();}
122 size_t size() const {return m_extents.size();}
123
124 Extent asExtent() const; // return an extent covering the whole range
125
126
127 size_t bytesContained() const; // number of bytes across the extent not considering overlaps!
128 size_t bytesMissing() const; // number of bytes missing across the extent, not considering overlaps!
129
130 void push_back(const Extent & in);
131 void sort();
132
133 const ExtentContainer & extents() const {return m_extents;}
134 //ExtentContainer & extents() {return m_extents;}
135
138
139
140
141 protected:
143
144 off_t m_begin{0}; //lowest offset value
145 off_t m_end{0}; // one past end of last byte used.
146
147 };
148
149
150}
151
152#endif
std::mutex cephbuf_iolock
Definition BufferUtils.cc:9
Designed to hold individual extents, but itself provide Extent-like capabilities Useful in cases of c...
const ExtentContainer & extents() const
bool empty() const
Total range in bytes of the extents.
ExtentContainer getExtents() const
size_t size() const
number of extent elements
ExtentContainer getSortedExtents() const
void push_back(const Extent &in)
void sort()
inplace sort by offset of contained extents
off_t end() const
similar to stl vector end.
Extent containedExtent(off_t pos, size_t len) const
return the subset of range that is in this extent
off_t begin() const
Same as offset, but a bit more stl container like.
bool isContiguous(const Extent &rhs) const
off_t offset() const
bool operator==(const Extent &rhs) const
size_t len() const
off_t last_pos() const
last real position
bool operator<(const Extent &rhs) const
bool allInExtent(off_t pos, size_t len) const
is all the range in this extent
bool in_extent(off_t pos) const
is this position within the range of this extent
Extent(off_t offset, size_t len)
Ecapsulates an offsets and length, with added functionaliyu Class that represents an offset possition...
bool someInExtent(off_t pos, size_t len) const
is some of the range in this extent
is a simple implementation of IXrdCephBufferData using std::vector<char> representation for the buffe...
std::vector< Extent > ExtentContainer
Container defintion for Extents Typedef to provide a container of extents as a simple stl vector cont...