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