CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
21 namespace XrdAdaptor
22 {
23 
24 class ClientRequest;
25 class XrdReadStatistics;
26 class XrdSiteStatistics;
27 
28 
29 /* NOTE: All member information is kept in the XrdSiteStatisticsInformation singleton,
30  * _not_ within the service itself. This is because we need to be able to use the
31  * singleton on non-CMSSW-created threads. Services are only available to threads
32  * created by CMSSW.
33  */
35 {
36 public:
37 
39 
40  void postEndJob();
41 
43 
44 private:
45 
46 };
47 
49 {
50 friend class XrdStatisticsService;
51 
52 public:
54 
55  std::shared_ptr<XrdSiteStatistics> getStatisticsForSite(std::string const &site);
56 
57 private:
58  static void createInstance();
59 
60  static std::atomic<XrdSiteStatisticsInformation*> m_instance;
62  std::vector<edm::propagate_const<std::shared_ptr<XrdSiteStatistics>>> m_sites;
63 };
64 
66 {
67 friend class XrdReadStatistics;
68 
69 public:
71  XrdSiteStatistics(const XrdSiteStatistics&) = delete;
73 
74  std::string const &site() const {return m_site;}
75 
76  // Note that, while this function is thread-safe, the numbers are only consistent if no other
77  // thread is reading data.
78  void recomputeProperties(std::map<std::string, std::string> &props);
79 
80  static std::shared_ptr<XrdReadStatistics> startRead(std::shared_ptr<XrdSiteStatistics> parent, std::shared_ptr<ClientRequest> req);
81 
82  void finishRead(XrdReadStatistics const &);
83 
84 private:
85  const std::string m_site = "Unknown";
86 
87  std::atomic<unsigned> m_readvCount;
88  std::atomic<unsigned> m_chunkCount;
89  std::atomic<uint64_t> m_readvSize;
90  std::atomic<uint64_t> m_readvNS;
91  std::atomic<unsigned> m_readCount;
92  std::atomic<uint64_t> m_readSize;
93  std::atomic<uint64_t> m_readNS;
94 };
95 
97 {
98 friend class XrdSiteStatistics;
99 
100 public:
101  ~XrdReadStatistics() {m_parent->finishRead(*this);}
102  XrdReadStatistics(const XrdReadStatistics&) = delete;
104 
105 private:
106  XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count);
107 
108  float elapsedNS() const;
109  int readCount() const {return m_count;}
110  int size() const {return m_size;}
111 
112  size_t m_size;
115  std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
116 };
117 
118 }
119 
120 #endif
void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XrdReadStatistics(const XrdReadStatistics &)=delete
std::string const & site() const
Definition: XrdStatistics.h:74
std::atomic< unsigned > m_readCount
Definition: XrdStatistics.h:91
static boost::mutex mutex
Definition: LHEProxy.cc:11
std::shared_ptr< XrdSiteStatistics > getStatisticsForSite(std::string const &site)
parent
Definition: confdb.py:1052
XrdReadStatistics & operator=(const XrdReadStatistics &)=delete
std::vector< edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > > m_sites
Definition: XrdStatistics.h:62
void finishRead(XrdReadStatistics const &)
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:60
std::atomic< uint64_t > m_readvSize
Definition: XrdStatistics.h:89
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)
std::atomic< unsigned > m_readvCount
Definition: XrdStatistics.h:87
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:90
std::atomic< uint64_t > m_readNS
Definition: XrdStatistics.h:93
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
std::atomic< uint64_t > m_readSize
Definition: XrdStatistics.h:92
size_t IOSize
Definition: IOTypes.h:14
std::atomic< unsigned > m_chunkCount
Definition: XrdStatistics.h:88