in fb303/ServiceData.cpp [113:157]
void ServiceData::addStatExports(
StringPiece key,
StringPiece stats,
int64_t bucketSize,
int64_t min,
int64_t max,
const ExportedStat* statPrototype) {
if (histMap_.contains(key)) {
return; // already exists
}
bool addedHist = false;
vector<string> statsSplit;
folly::split(",", stats, statsSplit);
for (const string& stat : statsSplit) {
if (stat == "AVG") {
statsMap_.exportStat(key, AVG, statPrototype);
} else if (stat == "RATE") {
statsMap_.exportStat(key, RATE, statPrototype);
} else if (stat == "SUM") {
statsMap_.exportStat(key, SUM, statPrototype);
} else if (stat == "COUNT") {
statsMap_.exportStat(key, COUNT, statPrototype);
} else { // No match on stat type - assume it's a histogram percentile
if (!addedHist) {
if (bucketSize <= 0) {
throw std::runtime_error(folly::to<string>(
"bucketSize for ",
key,
" must be greater than zero (",
bucketSize,
")"));
}
ExportedHistogram hist(
bucketSize,
min,
max,
statPrototype != nullptr ? *statPrototype
: histMap_.getDefaultStat());
histMap_.addHistogram(key, &hist);
addedHist = true;
}
exportHistogramPercentile(key, folly::to<int32_t>(stat));
}
}
}