CMS 3D CMS Logo

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 {
23 
24  if (iPS.getUntrackedParameter<bool>("reportToFJR", false))
25  {
27  }
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 (auto& stats : instance->m_sites)
41  {
42  stats->recomputeProperties(props);
43  reportSvc->reportPerformanceForModule(stats->site(), "XrdSiteStatistics", props);
44  }
45 }
46 
47 std::vector<std::pair<std::string, XrdStatisticsService::CondorIOStats>>
49 {
50  std::vector<std::pair<std::string, XrdStatisticsService::CondorIOStats>> result;
52  if (!instance) {return result;}
53 
54  std::lock_guard<std::mutex> lock(instance->m_mutex);
55  result.reserve(instance->m_sites.size());
56  for (auto& stats : instance->m_sites)
57  {
59  std::shared_ptr<XrdSiteStatistics> ss = get_underlying_safe(stats);
60  if (!ss) continue;
61  cs.bytesRead = ss->getTotalBytes();
62  cs.transferTime = ss->getTotalReadTime();
63  result.emplace_back(ss->site(), cs);
64  }
65  return result;
66 }
67 
68 
69 std::shared_ptr<XrdSiteStatistics>
71 {
72  std::lock_guard<std::mutex> lock(m_mutex);
73  for (auto& stats : m_sites)
74  {
75  if (stats->site() == site) {return get_underlying_safe(stats);}
76  }
77  m_sites.emplace_back(new XrdSiteStatistics(site));
78  return get_underlying_safe(m_sites.back());
79 }
80 
81 
82 void
84 {
85  if (!m_instance)
86  {
87  std::unique_ptr<XrdSiteStatisticsInformation> tmp { new XrdSiteStatisticsInformation() };
88  XrdSiteStatisticsInformation* expected = nullptr;
89  if (m_instance.compare_exchange_strong(expected,tmp.get()))
90  {
91  tmp.release();
92  }
93  }
94 }
95 
98 {
99  return m_instance.load(std::memory_order_relaxed);
100 }
101 
103 {
105  desc.setComment("Report Xrootd-related statistics centrally.");
106  desc.addUntracked<bool>("reportToFJR", true)
107  ->setComment("True: Add per-site Xrootd statistics to the framework job report.\n"
108  "False: Collect no site-specific statistics.\n");
109  descriptions.add("XrdAdaptor::XrdStatisticsService", desc);
110 }
111 
112 
114  m_site(site),
115  m_readvCount(0),
116  m_chunkCount(0),
117  m_readvSize(0),
118  m_readvNS(0.0),
119  m_readCount(0),
120  m_readSize(0),
121  m_readNS(0)
122 {
123 }
124 
125 std::shared_ptr<XrdReadStatistics>
126 XrdSiteStatistics::startRead(std::shared_ptr<XrdSiteStatistics> parent, std::shared_ptr<ClientRequest> req)
127 {
128  std::shared_ptr<XrdReadStatistics> readStats(new XrdReadStatistics(parent, req->getSize(), req->getCount()));
129  return readStats;
130 }
131 
132 
133 static std::string
135 {
136  std::ostringstream formatter;
137  formatter << input;
138  return formatter.str();
139 }
140 
141 
142 static std::string
143 d2str(double input)
144 {
145  std::ostringstream formatter;
146  formatter << std::setw(4) << input;
147  return formatter.str();
148 }
149 
150 
151 void
152 XrdSiteStatistics::recomputeProperties(std::map<std::string, std::string> &props)
153 {
154  props.clear();
155 
156  props["readv-numOperations"] = i2str(m_readvCount);
157  props["readv-numChunks"] = i2str(m_chunkCount);
158  props["readv-totalMegabytes"] = d2str(static_cast<float>(m_readvSize)/(1024.0*1024.0));
159  props["readv-totalMsecs"] = d2str(m_readvNS/1e6);
160 
161  props["read-numOperations"] = i2str(m_readCount);
162  props["read-totalMegabytes"] = d2str(static_cast<float>(m_readSize)/(1024.0*1024.0));
163  props["read-totalMsecs"] = d2str(static_cast<float>(m_readNS)/1e6);
164 }
165 
166 
167 void
169 {
170  if (readStats.readCount() > 1)
171  {
172  m_readvCount ++;
173  m_chunkCount += readStats.readCount();
174  m_readvSize += readStats.size();
175  m_readvNS += readStats.elapsedNS();
176  }
177  else
178  {
179  m_readCount ++;
180  m_readSize += readStats.size();
181  m_readNS += readStats.elapsedNS();
182  }
183 }
184 
185 
186 XrdReadStatistics::XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count) :
187  m_size(size),
188  m_count(count),
189  m_parent(parent),
190  m_start(std::chrono::high_resolution_clock::now())
191 {
192 }
193 
194 
195 uint64_t
197 {
198  std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
199  return std::chrono::duration_cast<std::chrono::nanoseconds>(end-m_start).count();
200 }
201 
size
Write out results.
T getUntrackedParameter(std::string const &, T const &) const
void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XrdReadStatistics(const XrdReadStatistics &)=delete
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::atomic< unsigned > m_readCount
static PFTauRenderPlugin instance
std::shared_ptr< XrdSiteStatistics > getStatisticsForSite(std::string const &site)
unique_ptr< ClusterSequence > cs
std::vector< edm::propagate_const< std::shared_ptr< XrdSiteStatistics > > > m_sites
Definition: XrdStatistics.h:75
void finishRead(XrdReadStatistics const &)
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:73
std::atomic< uint64_t > m_readvSize
static std::string d2str(double input)
std::vector< std::pair< std::string, CondorIOStats > > condorUpdate()
static std::string const input
Definition: EdmProvDump.cc:45
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:702
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
bool isAvailable() const
Definition: Service.h:46
XrdStatisticsService(const edm::ParameterSet &iPS, edm::ActivityRegistry &iRegistry)
#define end
Definition: vmac.h:39
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
static XrdSiteStatisticsInformation * getInstance()
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
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
size_t IOSize
Definition: IOTypes.h:14
boost::date_time::subsecond_duration< boost::posix_time::time_duration, 1000000000 > nanoseconds
std::atomic< unsigned > m_chunkCount