CMS 3D CMS Logo

XrdStatistics.h
Go to the documentation of this file.
1 #ifndef __XRD_STATISTICS_SERVICE_H_
2 #define __XRD_STATISTICS_SERVICE_H_
3 
6 
7 #include <atomic>
8 #include <chrono>
9 #include <map>
10 #include <memory>
11 #include <mutex>
12 #include <vector>
13 
14 namespace edm
15 {
16  class ParameterSet;
17  class ActivityRegistry;
19 
20  namespace service
21  {
22  class CondorStatusService;
23  }
24 }
25 
26 namespace XrdAdaptor
27 {
28 
29 class ClientRequest;
30 class XrdReadStatistics;
31 class XrdSiteStatistics;
32 
33 
34 /* NOTE: All member information is kept in the XrdSiteStatisticsInformation singleton,
35  * _not_ within the service itself. This is because we need to be able to use the
36  * singleton on non-CMSSW-created threads. Services are only available to threads
37  * created by CMSSW.
38  */
40 {
41 public:
42 
44 
45  void postEndJob();
46 
47  void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
48 
49  struct CondorIOStats {
50  uint64_t bytesRead{0};
51  std::chrono::nanoseconds transferTime{0};
52  };
53 
54  // Provide an update of per-site transfer statistics to the CondorStatusService.
55  // Returns a mapping of "site name" to transfer statistics. The "site name" is
56  // as self-identified by the Xrootd host; may not necessarily match up with the
57  // "CMS site name".
58  std::vector<std::pair<std::string, CondorIOStats>> condorUpdate();
59 };
60 
62 {
63 friend class XrdStatisticsService;
64 
65 public:
66  static XrdSiteStatisticsInformation *getInstance();
67 
68  std::shared_ptr<XrdSiteStatistics> getStatisticsForSite(std::string const &site);
69 
70 private:
71  static void createInstance();
72 
73  static std::atomic<XrdSiteStatisticsInformation*> m_instance;
75  std::vector<edm::propagate_const<std::shared_ptr<XrdSiteStatistics>>> m_sites;
76 };
77 
79 {
80 friend class XrdReadStatistics;
81 
82 public:
83  XrdSiteStatistics(std::string const &site);
84  XrdSiteStatistics(const XrdSiteStatistics&) = delete;
85  XrdSiteStatistics &operator=(const XrdSiteStatistics&) = delete;
86 
87  std::string const &site() const {return m_site;}
88 
89  // Note that, while this function is thread-safe, the numbers are only consistent if no other
90  // thread is reading data.
91  void recomputeProperties(std::map<std::string, std::string> &props);
92 
93  static std::shared_ptr<XrdReadStatistics> startRead(std::shared_ptr<XrdSiteStatistics> parent, std::shared_ptr<ClientRequest> req);
94 
95  void finishRead(XrdReadStatistics const &);
96 
97  uint64_t getTotalBytes() const {return m_readvSize + m_readSize;}
99 
100 private:
101  const std::string m_site = "Unknown";
102 
103  std::atomic<unsigned> m_readvCount;
104  std::atomic<unsigned> m_chunkCount;
105  std::atomic<uint64_t> m_readvSize;
106  std::atomic<uint64_t> m_readvNS;
107  std::atomic<unsigned> m_readCount;
108  std::atomic<uint64_t> m_readSize;
109  std::atomic<uint64_t> m_readNS;
110 };
111 
113 {
114 friend class XrdSiteStatistics;
115 
116 public:
117  ~XrdReadStatistics() {m_parent->finishRead(*this);}
118  XrdReadStatistics(const XrdReadStatistics&) = delete;
119  XrdReadStatistics &operator=(const XrdReadStatistics&) = delete;
120 
121 private:
122  XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count);
123 
124  uint64_t elapsedNS() const;
125  int readCount() const {return m_count;}
126  int size() const {return m_size;}
127 
128  size_t m_size;
131  std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
132 };
133 
134 }
135 
136 #endif
size
Write out results.
std::chrono::nanoseconds getTotalReadTime()
Definition: XrdStatistics.h:98
std::string const & site() const
Definition: XrdStatistics.h:87
std::atomic< unsigned > m_readCount
static boost::mutex mutex
Definition: LHEProxy.cc:11
std::vector< edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > > m_sites
Definition: XrdStatistics.h:75
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:73
std::atomic< uint64_t > m_readvSize
uint64_t getTotalBytes() const
Definition: XrdStatistics.h:97
std::atomic< unsigned > m_readvCount
edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > m_parent
std::atomic< uint64_t > m_readvNS
std::atomic< uint64_t > m_readNS
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
unsigned long long uint64_t
Definition: Time.h:15
HLT enums.
std::atomic< uint64_t > m_readSize
size_t IOSize
Definition: IOTypes.h:14
boost::date_time::subsecond_duration< boost::posix_time::time_duration, 1000000000 > nanoseconds
std::atomic< unsigned > m_chunkCount