CMS 3D CMS Logo

StorageAccount.cc
Go to the documentation of this file.
2 #include <cassert>
3 #include <mutex>
4 #include <sstream>
5 #include <unistd.h>
6 #include <sys/time.h>
7 
8 namespace {
9  char const* const kOperationNames[] = {
10  "check", "close", "construct", "destruct", "flush", "open",
11  "position", "prefetch", "read", "readActual", "readAsync", "readPrefetchToCache",
12  "readViaCache", "readv", "resize", "seek", "stagein", "stat",
13  "write", "writeActual", "writeViaCache", "writev"};
14 
15  //Storage class names to the value of the token to which they are assigned
16  tbb::concurrent_unordered_map<std::string, int> s_nameToToken;
17  std::atomic<int> s_nextTokenValue{0};
18 } // namespace
19 
21 
22 static std::string i2str(int i) {
23  std::ostringstream t;
24  t << i;
25  return t.str();
26 }
27 
28 static std::string d2str(double d) {
29  std::ostringstream t;
30  t << d;
31  return t.str();
32 }
33 
34 inline char const* StorageAccount::operationName(Operation operation) {
35  return kOperationNames[static_cast<int>(operation)];
36 }
37 
39  auto itFound = s_nameToToken.find(iName);
40  if (itFound != s_nameToToken.end()) {
41  return StorageClassToken(itFound->second);
42  }
43  int value = s_nextTokenValue++;
44 
45  s_nameToToken.insert(std::make_pair(iName, value));
46 
47  return StorageClassToken(value);
48 }
49 
51  for (auto it = s_nameToToken.begin(), itEnd = s_nameToToken.end(); it != itEnd; ++it) {
52  if (it->second == iToken.value()) {
53  return it->first;
54  }
55  }
56  assert(false);
57 }
58 
59 std::string StorageAccount::summaryText(bool banner /*=false*/) {
60  bool first = true;
61  std::ostringstream os;
62  if (banner)
63  os << "stats: class/operation/attempts/successes/amount/time-total/time-min/time-max\n";
64  for (auto i = s_nameToToken.begin(); i != s_nameToToken.end(); ++i) {
65  auto const& opStats = m_stats[i->second];
66  for (auto j = opStats.begin(); j != opStats.end(); ++j, first = false)
67  os << (first ? "" : "; ") << (i->first) << '/' << kOperationNames[j->first] << '=' << j->second.attempts << '/'
68  << j->second.successes << '/' << (static_cast<double>(j->second.amount) / 1024 / 1024) << "MB/"
69  << (static_cast<double>(j->second.timeTotal) / 1000 / 1000) << "ms/"
70  << (static_cast<double>(j->second.timeMin) / 1000 / 1000) << "ms/"
71  << (static_cast<double>(j->second.timeMax) / 1000 / 1000) << "ms";
72  }
73  return os.str();
74 }
75 
76 void StorageAccount::fillSummary(std::map<std::string, std::string>& summary) {
77  int const oneM = 1000 * 1000;
78  int const oneMeg = 1024 * 1024;
79  for (auto i = s_nameToToken.begin(); i != s_nameToToken.end(); ++i) {
80  auto const& opStats = m_stats[i->second];
81  for (auto j = opStats.begin(); j != opStats.end(); ++j) {
82  std::ostringstream os;
83  os << "Timing-" << i->first << "-" << kOperationNames[j->first] << "-";
84  summary.insert(std::make_pair(os.str() + "numOperations", i2str(j->second.attempts)));
85  summary.insert(std::make_pair(os.str() + "numSuccessfulOperations", i2str(j->second.successes)));
86  summary.insert(
87  std::make_pair(os.str() + "totalMegabytes", d2str(static_cast<double>(j->second.amount) / oneMeg)));
88  summary.insert(std::make_pair(os.str() + "totalMsecs", d2str(static_cast<double>(j->second.timeTotal) / oneM)));
89  summary.insert(std::make_pair(os.str() + "minMsecs", d2str(static_cast<double>(j->second.timeMin) / oneM)));
90  summary.insert(std::make_pair(os.str() + "maxMsecs", d2str(static_cast<double>(j->second.timeMax) / oneM)));
91  }
92  }
93 }
94 
96 
98  auto& opstats = m_stats[token.value()];
99 
100  return opstats[static_cast<int>(operation)];
101 }
102 
104  : m_counter(counter), m_start(std::chrono::high_resolution_clock::now()) {
106 }
107 
108 void StorageAccount::Stamp::tick(uint64_t amount, int64_t count) const {
110  uint64_t elapsed = elapsed_ns.count();
111  m_counter.successes++;
112 
113  m_counter.vector_count += count;
114  m_counter.vector_square += count * count;
115  m_counter.amount += amount;
116  Counter::addTo(m_counter.amount_square, amount * amount);
117 
118  Counter::addTo(m_counter.timeTotal, elapsed);
119  if (elapsed < m_counter.timeMin || m_counter.successes == 1)
120  m_counter.timeMin = elapsed;
121  if (elapsed > m_counter.timeMax)
122  m_counter.timeMax = elapsed;
123 }
counter
Definition: counter.py:1
StorageAccount::StorageStats
tbb::concurrent_unordered_map< int, OperationStats > StorageStats
Definition: StorageAccount.h:119
mps_fire.i
i
Definition: mps_fire.py:428
cond::time::nanoseconds
boost::date_time::subsecond_duration< boost::posix_time::time_duration, 1000000000 > nanoseconds
Definition: TimeConversions.h:16
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
cms::cuda::assert
assert(be >=bs)
StorageAccount::m_stats
static StorageStats m_stats
Definition: StorageAccount.h:131
StorageAccount::Counter
Definition: StorageAccount.h:39
dqmdumpme.first
first
Definition: dqmdumpme.py:55
StorageAccount::nameForToken
static const std::string & nameForToken(StorageClassToken)
Definition: StorageAccount.cc:50
StorageAccount::Operation
Operation
Definition: StorageAccount.h:14
StorageAccount.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
StorageAccount::StorageClassToken::value
int value() const
Definition: StorageAccount.h:107
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StorageAccount::Counter::attempts
std::atomic< uint64_t > attempts
Definition: StorageAccount.h:72
StorageAccount::operationName
static char const * operationName(Operation operation)
Definition: StorageAccount.cc:34
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
value
Definition: value.py:1
StorageAccount::tokenForStorageClassName
static StorageClassToken tokenForStorageClassName(std::string const &iName)
Definition: StorageAccount.cc:38
StorageAccount::summary
static const StorageStats & summary(void)
Definition: StorageAccount.cc:95
StorageAccount::Stamp::Stamp
Stamp(Counter &counter)
Definition: StorageAccount.cc:103
StorageAccount::Counter::addTo
static void addTo(std::atomic< double > &iAtomic, double iToAdd)
Definition: StorageAccount.h:84
StorageAccount::Stamp::tick
void tick(uint64_t amount=0, int64_t tick=0) const
Definition: StorageAccount.cc:108
i2str
static std::string i2str(int i)
Definition: StorageAccount.cc:22
std
Definition: JetResolutionObject.h:76
StorageAccount::summaryText
static std::string summaryText(bool banner=false)
Definition: StorageAccount.cc:59
StorageAccount::counter
static Counter & counter(StorageClassToken token, Operation operation)
Definition: StorageAccount.cc:97
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ztail.d
d
Definition: ztail.py:151
StorageAccount::fillSummary
static void fillSummary(std::map< std::string, std::string > &summary)
Definition: StorageAccount.cc:76
d2str
static std::string d2str(double d)
Definition: StorageAccount.cc:28
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
StorageAccount::Stamp::m_counter
Counter & m_counter
Definition: StorageAccount.h:100
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
StorageAccount::StorageClassToken
Definition: StorageAccount.h:104
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318