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 std::atomic<XrdSiteStatisticsInformation *> XrdSiteStatisticsInformation::m_instance;
17 
20 
21  if (iPS.getUntrackedParameter<bool>("reportToFJR", false)) {
23  }
24 }
25 
28  if (!reportSvc.isAvailable()) {
29  return;
30  }
31 
33  if (!instance) {
34  return;
35  }
36 
37  std::map<std::string, std::string> props;
38  for (auto &stats : instance->m_sites) {
39  stats->recomputeProperties(props);
40  reportSvc->reportPerformanceForModule(stats->site(), "XrdSiteStatistics", props);
41  }
42 }
43 
44 std::vector<std::pair<std::string, XrdStatisticsService::CondorIOStats>> XrdStatisticsService::condorUpdate() {
45  std::vector<std::pair<std::string, XrdStatisticsService::CondorIOStats>> result;
47  if (!instance) {
48  return result;
49  }
50 
51  std::lock_guard<std::mutex> lock(instance->m_mutex);
52  result.reserve(instance->m_sites.size());
53  for (auto &stats : instance->m_sites) {
55  std::shared_ptr<XrdSiteStatistics> ss = get_underlying_safe(stats);
56  if (!ss)
57  continue;
58  cs.bytesRead = ss->getTotalBytes();
59  cs.transferTime = ss->getTotalReadTime();
60  result.emplace_back(ss->site(), cs);
61  }
62  return result;
63 }
64 
65 std::shared_ptr<XrdSiteStatistics> XrdSiteStatisticsInformation::getStatisticsForSite(std::string const &site) {
66  std::lock_guard<std::mutex> lock(m_mutex);
67  for (auto &stats : m_sites) {
68  if (stats->site() == site) {
69  return get_underlying_safe(stats);
70  }
71  }
72  m_sites.emplace_back(new XrdSiteStatistics(site));
73  return get_underlying_safe(m_sites.back());
74 }
75 
77  if (!m_instance) {
78  std::unique_ptr<XrdSiteStatisticsInformation> tmp{new XrdSiteStatisticsInformation()};
79  XrdSiteStatisticsInformation *expected = nullptr;
80  if (m_instance.compare_exchange_strong(expected, tmp.get())) {
81  tmp.release();
82  }
83  }
84 }
85 
87  return m_instance.load(std::memory_order_relaxed);
88 }
89 
92  desc.setComment("Report Xrootd-related statistics centrally.");
93  desc.addUntracked<bool>("reportToFJR", true)
94  ->setComment(
95  "True: Add per-site Xrootd statistics to the framework job report.\n"
96  "False: Collect no site-specific statistics.\n");
97  descriptions.add("XrdAdaptor::XrdStatisticsService", desc);
98 }
99 
101  : m_site(site),
102  m_readvCount(0),
103  m_chunkCount(0),
104  m_readvSize(0),
105  m_readvNS(0.0),
106  m_readCount(0),
107  m_readSize(0),
108  m_readNS(0) {}
109 
110 std::shared_ptr<XrdReadStatistics> XrdSiteStatistics::startRead(std::shared_ptr<XrdSiteStatistics> parent,
111  std::shared_ptr<ClientRequest> req) {
112  std::shared_ptr<XrdReadStatistics> readStats(new XrdReadStatistics(parent, req->getSize(), req->getCount()));
113  return readStats;
114 }
115 
116 static std::string i2str(int input) {
117  std::ostringstream formatter;
118  formatter << input;
119  return formatter.str();
120 }
121 
122 static std::string d2str(double input) {
123  std::ostringstream formatter;
124  formatter << std::setw(4) << input;
125  return formatter.str();
126 }
127 
128 void XrdSiteStatistics::recomputeProperties(std::map<std::string, std::string> &props) {
129  props.clear();
130 
131  props["readv-numOperations"] = i2str(m_readvCount);
132  props["readv-numChunks"] = i2str(m_chunkCount);
133  props["readv-totalMegabytes"] = d2str(static_cast<float>(m_readvSize) / (1024.0 * 1024.0));
134  props["readv-totalMsecs"] = d2str(m_readvNS / 1e6);
135 
136  props["read-numOperations"] = i2str(m_readCount);
137  props["read-totalMegabytes"] = d2str(static_cast<float>(m_readSize) / (1024.0 * 1024.0));
138  props["read-totalMsecs"] = d2str(static_cast<float>(m_readNS) / 1e6);
139 }
140 
142  if (readStats.readCount() > 1) {
143  m_readvCount++;
144  m_chunkCount += readStats.readCount();
145  m_readvSize += readStats.size();
146  m_readvNS += readStats.elapsedNS();
147  } else {
148  m_readCount++;
149  m_readSize += readStats.size();
150  m_readNS += readStats.elapsedNS();
151  }
152 }
153 
154 XrdReadStatistics::XrdReadStatistics(std::shared_ptr<XrdSiteStatistics> parent, IOSize size, size_t count)
155  : m_size(size), m_count(count), m_parent(parent), m_start(std::chrono::high_resolution_clock::now()) {}
156 
158  std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
159  return std::chrono::duration_cast<std::chrono::nanoseconds>(end - m_start).count();
160 }
size
Write out results.
T getUntrackedParameter(std::string const &, T const &) const
void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XrdReadStatistics(const XrdReadStatistics &)=delete
boost::date_time::subsecond_duration< boost::posix_time::time_duration, 1000000000 > nanoseconds
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:68
void finishRead(XrdReadStatistics const &)
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:66
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:48
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:672
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:98
bool isAvailable() const
Definition: Service.h:40
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:13
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static std::string i2str(int input)
std::atomic< uint64_t > m_readSize
size_t IOSize
Definition: IOTypes.h:14
tmp
align.sh
Definition: createJobs.py:716
std::atomic< unsigned > m_chunkCount
Definition: XrdStatistics.h:99