2 #include <boost/thread/mutex.hpp>
12 if (clock_gettime(CLOCK_REALTIME, &tm) == 0)
13 return tm.tv_sec * 1e9 + tm.tv_nsec;
16 if (gettimeofday(&tm, 0) == 0)
17 return tm.tv_sec * 1e9 + tm.tv_usec * 1e3;
28 static std::string
d2str(
double d) {
37 std::ostringstream os;
39 os <<
"stats: class/operation/attempts/successes/amount/time-total/time-min/time-max\n";
41 for (OperationStats::iterator
j =
i->second->begin ();
j !=
i->second->end (); ++
j, first =
false)
42 os << (first ?
"" :
"; ")
45 <<
j->second.attempts <<
'/'
46 <<
j->second.successes <<
'/'
47 << (
j->second.amount / 1024 / 1024) <<
"MB/"
48 << (
j->second.timeTotal / 1000 / 1000) <<
"ms/"
49 << (
j->second.timeMin / 1000 / 1000) <<
"ms/"
50 << (
j->second.timeMax / 1000 / 1000) <<
"ms";
58 std::ostringstream os;
59 os <<
"<storage-timing-summary>\n";
61 for (OperationStats::iterator
j =
i->second->begin ();
j !=
i->second->end (); ++
j, first =
false)
62 os <<
" <counter-value subsystem='" <<
i->first
63 <<
"' counter-name='" <<
j->first
64 <<
"' num-operations='" <<
j->second.attempts
65 <<
"' num-successful-operations='" <<
j->second.successes
66 <<
"' total-megabytes='" << (
j->second.amount / 1024 / 1024)
67 <<
"' total-msecs='" << (
j->second.timeTotal / 1000 / 1000)
68 <<
"' min-msecs='" << (
j->second.timeMin / 1000 / 1000)
69 <<
"' max-msecs='" << (
j->second.timeMax / 1000 / 1000) <<
"'/>\n";
70 os <<
"</storage-timing-summary>";
76 int const oneM = 1000 * 1000;
77 int const oneMeg = 1024 * 1024;
79 for (OperationStats::iterator
j =
i->second->begin();
j !=
i->second->end(); ++
j) {
80 std::ostringstream os;
81 os <<
"Timing-" <<
i->first <<
"-" <<
j->first <<
"-";
82 summary.insert(std::make_pair(os.str() +
"numOperations",
i2str(
j->second.attempts)));
83 summary.insert(std::make_pair(os.str() +
"numSuccessfulOperations",
i2str(
j->second.successes)));
84 summary.insert(std::make_pair(os.str() +
"totalMegabytes",
d2str(
j->second.amount / oneMeg)));
85 summary.insert(std::make_pair(os.str() +
"totalMsecs",
d2str(
j->second.timeTotal / oneM)));
86 summary.insert(std::make_pair(os.str() +
"minMsecs",
d2str(
j->second.timeMin / oneM)));
87 summary.insert(std::make_pair(os.str() +
"maxMsecs",
d2str(
j->second.timeMax / oneM)));
99 boost::shared_ptr<OperationStats> &opstats =
s_stats [storageClass];
102 OperationStats::iterator
pos = opstats->find (operation);
103 if (pos == opstats->end ()) {
112 : m_counter (counter),
124 m_counter.successes++;
125 m_counter.amount += amount;
126 m_counter.timeTotal += elapsed;
127 if (elapsed < m_counter.timeMin || m_counter.successes == 1)
128 m_counter.timeMin = elapsed;
129 if (elapsed > m_counter.timeMax)
130 m_counter.timeMax = elapsed;
static double timeRealNanoSecs(void)
static void fillSummary(std::map< std::string, std::string > &summary)
static boost::mutex mutex
std::map< std::string, Counter > OperationStats
static const StorageStats & summary(void)
Container::value_type value_type
StorageAccount::StorageStats s_stats
std::map< std::string, boost::shared_ptr< OperationStats > > StorageStats
static std::string d2str(double d)
static std::string i2str(int i)
static std::string summaryXML(void)
void tick(double amount=0.) const
static Counter & counter(const std::string &storageClass, const std::string &operation)
static std::string summaryText(bool banner=false)