CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XrdStatistics.cc
Go to the documentation of this file.
1 
8 
9 #include "XrdRequest.h"
10 #include "XrdStatistics.h"
11 
12 #include <chrono>
13 
14 using namespace XrdAdaptor;
15 
16 
17 std::atomic<XrdSiteStatisticsInformation*> XrdSiteStatisticsInformation::m_instance;
18 
19 
21 {
22  if (iPS.getUntrackedParameter<bool>("reportToFJR", false))
23  {
25  }
26 
28 }
29 
30 
32 {
34  if (!reportSvc.isAvailable()) {return;}
35 
37  if (!instance) {return;}
38 
39  std::map<std::string, std::string> props;
40  for (std::shared_ptr<XrdSiteStatistics> const &stats : instance->m_sites)
41  {
42  stats->recomputeProperties(props);
43  reportSvc->reportPerformanceForModule(stats->site(), "XrdSiteStatistics", props);
44  }
45 }
46 
47 
48 std::shared_ptr<XrdSiteStatistics>
50 {
51  std::lock_guard<std::mutex> lock(m_mutex);
52  for (std::shared_ptr<XrdSiteStatistics> &stats : m_sites)
53  {
54  if (stats->site() == site) {return stats;}
55  }
56  m_sites.emplace_back(new XrdSiteStatistics(site));
57  return m_sites.back();
58 }
59 
60 
61 void
63 {
64  if (!m_instance)
65  {
66  std::unique_ptr<XrdSiteStatisticsInformation> tmp { new XrdSiteStatisticsInformation() };
67  XrdSiteStatisticsInformation* expected = nullptr;
68  if (m_instance.compare_exchange_strong(expected,tmp.get()))
69  {
70  tmp.release();
71  }
72  }
73 }
74 
77 {
78  return m_instance.load(std::memory_order_relaxed);
79 }
80 
82 {
84  desc.setComment("Report Xrootd-related statistics centrally.");
85  desc.addUntracked<bool>("reportToFJR", true)
86  ->setComment("True: Add per-site Xrootd statistics to the framework job report.\n"
87  "False: Collect no site-specific statistics.\n");
88  descriptions.add("XrdAdaptor::XrdStatisticsService", desc);
89 }
90 
91 
93  m_site(site),
94  m_readvCount(0),
95  m_chunkCount(0),
96  m_readvSize(0),
97  m_readvNS(0.0),
98  m_readCount(0),
99  m_readSize(0),
100  m_readNS(0)
101 {
102 }
103 
104 std::shared_ptr<XrdReadStatistics>
105 XrdSiteStatistics::startRead(std::shared_ptr<XrdSiteStatistics> parent, std::shared_ptr<ClientRequest> req)
106 {
107  std::shared_ptr<XrdReadStatistics> readStats(new XrdReadStatistics(parent, req->getSize(), req->getCount()));
108  return readStats;
109 }
110 
111 
112 static std::string
114 {
115  std::ostringstream formatter;
116  formatter << input;
117  return formatter.str();
118 }
119 
120 
121 static std::string
122 d2str(double input)
123 {
124  std::ostringstream formatter;
125  formatter << std::setw(4) << input;
126  return formatter.str();
127 }
128 
129 
130 void
131 XrdSiteStatistics::recomputeProperties(std::map<std::string, std::string> &props)
132 {
133  props.clear();
134 
135  props["readv-numOperations"] = i2str(m_readvCount);
136  props["readv-numChunks"] = i2str(m_chunkCount);
137  props["readv-totalMegabytes"] = d2str(static_cast<float>(m_readvSize)/(1024.0*1024.0));
138  props["readv-totalMsecs"] = d2str(m_readvNS/1e6);
139 
140  props["read-numOperations"] = i2str(m_readCount);
141  props["read-totalMegabytes"] = d2str(static_cast<float>(m_readSize)/(1024.0*1024.0));
142  props["read-totalMsecs"] = d2str(static_cast<float>(m_readNS)/1e6);
143 }
144 
145 
146 void
148 {
149  if (readStats.readCount() > 1)
150  {
151  m_readvCount ++;
152  m_chunkCount += readStats.readCount();
153  m_readvSize += readStats.size();
154  m_readvNS += readStats.elapsedNS();
155  }
156  else
157  {
158  m_readCount ++;
159  m_readSize += readStats.size();
160  m_readNS += readStats.elapsedNS();
161  }
162 }
163 
164 
165 XrdReadStatistics::XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count) :
166  m_size(size),
167  m_count(count),
168  m_parent(parent),
169  m_start(std::chrono::high_resolution_clock::now())
170 {
171 }
172 
173 
174 float
176 {
177  std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
178  return static_cast<int>(std::chrono::duration_cast<std::chrono::nanoseconds>(end-m_start).count());
179 }
180 
T getUntrackedParameter(std::string const &, T const &) const
void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XrdReadStatistics(const XrdReadStatistics &)=delete
list parent
Definition: dbtoconf.py:74
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::atomic< unsigned > m_readCount
Definition: XrdStatistics.h:87
static PFTauRenderPlugin instance
std::shared_ptr< XrdSiteStatistics > getStatisticsForSite(std::string const &site)
std::vector< std::shared_ptr< XrdSiteStatistics > > m_sites
Definition: XrdStatistics.h:58
void finishRead(XrdReadStatistics const &)
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:56
std::atomic< uint64_t > m_readvSize
Definition: XrdStatistics.h:85
static std::string d2str(double input)
static std::string const input
Definition: EdmProvDump.cc:43
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:754
XrdSiteStatistics(std::string const &site)
void recomputeProperties(std::map< std::string, std::string > &props)
void setComment(std::string const &value)
static std::shared_ptr< XrdReadStatistics > startRead(std::shared_ptr< XrdSiteStatistics > parent, std::shared_ptr< ClientRequest > req)
std::atomic< unsigned > m_readvCount
Definition: XrdStatistics.h:83
bool isAvailable() const
Definition: Service.h:46
XrdStatisticsService(const edm::ParameterSet &iPS, edm::ActivityRegistry &iRegistry)
#define end
Definition: vmac.h:37
static XrdSiteStatisticsInformation * getInstance()
std::atomic< uint64_t > m_readvNS
Definition: XrdStatistics.h:86
std::atomic< uint64_t > m_readNS
Definition: XrdStatistics.h:89
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static std::string i2str(int input)
std::atomic< uint64_t > m_readSize
Definition: XrdStatistics.h:88
size_t IOSize
Definition: IOTypes.h:14
boost::date_time::subsecond_duration< boost::posix_time::time_duration, 1000000000 > nanoseconds
tuple size
Write out results.
std::atomic< unsigned > m_chunkCount
Definition: XrdStatistics.h:84