CMS 3D CMS Logo

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