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 }
ConfigurationDescriptions.h
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
d2str
static std::string d2str(double input)
Definition: XrdStatistics.cc:122
XrdAdaptor::XrdSiteStatistics
Definition: XrdStatistics.h:71
input
static const std::string input
Definition: EdmProvDump.cc:48
XrdStatistics.h
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
XrdAdaptor::XrdReadStatistics::readCount
int readCount() const
Definition: XrdStatistics.h:119
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
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
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::get_underlying_safe
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:41
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
XrdAdaptor::XrdReadStatistics::size
int size() const
Definition: XrdStatistics.h:120
ActivityRegistry.h
XrdAdaptor::XrdStatisticsService::XrdStatisticsService
XrdStatisticsService(const edm::ParameterSet &iPS, edm::ActivityRegistry &iRegistry)
Definition: XrdStatistics.cc:18
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
XrdAdaptor::XrdReadStatistics
Definition: XrdStatistics.h:107
XrdAdaptor::XrdSiteStatistics::m_readvCount
std::atomic< unsigned > m_readvCount
Definition: XrdStatistics.h:98
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:170
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
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
Service.h
mps_fire.end
end
Definition: mps_fire.py:242
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
XrdAdaptor::XrdSiteStatistics::XrdReadStatistics
friend class XrdReadStatistics
Definition: XrdStatistics.h:72
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
ParameterSetDescription.h
XrdAdaptor::XrdSiteStatistics::m_readNS
std::atomic< uint64_t > m_readNS
Definition: XrdStatistics.h:104
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
XrdAdaptor::XrdStatisticsService::postEndJob
void postEndJob()
Definition: XrdStatistics.cc:26
edm::ParameterSet
Definition: ParameterSet.h:47
XrdRequest.h
XrdAdaptor::XrdReadStatistics::XrdReadStatistics
XrdReadStatistics(const XrdReadStatistics &)=delete
CommonMethods.lock
def lock()
Definition: CommonMethods.py:81
XrdAdaptor::XrdSiteStatisticsInformation::m_instance
static std::atomic< XrdSiteStatisticsInformation * > m_instance
Definition: XrdStatistics.h:66
XrdAdaptor::XrdSiteStatisticsInformation::getStatisticsForSite
std::shared_ptr< XrdSiteStatistics > getStatisticsForSite(std::string const &site)
Definition: XrdStatistics.cc:65
postprocess-scan-build.formatter
formatter
Definition: postprocess-scan-build.py:49
edm::Service
Definition: Service.h:30
XrdAdaptor::XrdSiteStatistics::recomputeProperties
void recomputeProperties(std::map< std::string, std::string > &props)
Definition: XrdStatistics.cc:128
dqmMemoryStats.stats
stats
Definition: dqmMemoryStats.py:134
i2str
static std::string i2str(int input)
Definition: XrdStatistics.cc:116
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
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
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
XrdAdaptor::XrdStatisticsService::condorUpdate
std::vector< std::pair< std::string, CondorIOStats > > condorUpdate()
Definition: XrdStatistics.cc:44
XrdAdaptor::XrdSiteStatisticsInformation::createInstance
static void createInstance()
Definition: XrdStatistics.cc:76
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
mps_fire.result
result
Definition: mps_fire.py:311
JobReport.h
edm::JobReport::reportPerformanceForModule
void reportPerformanceForModule(std::string const &metricClass, std::string const &moduleName, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:671
ParameterSet.h
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
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
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