in fb303/ServiceData.cpp [201:241]
std::shared_ptr<QuantileStat> ServiceData::getQuantileStat(
folly::StringPiece name,
folly::Range<const ExportType*> stats,
folly::Range<const double*> quantiles,
folly::Range<const size_t*> slidingWindowPeriods) {
auto stat = quantileMap_.get(name);
if (stat) {
return stat;
}
std::vector<QuantileStat::SlidingWindow> slidingWindowDefs;
slidingWindowDefs.reserve(slidingWindowPeriods.size());
for (const auto& slidingWindowLength : slidingWindowPeriods) {
if (slidingWindowLength >= 60) {
auto duration = std::chrono::seconds{slidingWindowLength};
CHECK_EQ(0, duration.count() % 60);
slidingWindowDefs.emplace_back(duration / 60, 60);
} else {
slidingWindowDefs.emplace_back(
std::chrono::seconds(1), slidingWindowLength);
}
}
stat = std::make_shared<QuantileStat>(std::move(slidingWindowDefs));
std::vector<detail::QuantileStatMap::StatDef> statDefs;
statDefs.reserve(stats.size() + quantiles.size());
for (auto statType : stats) {
detail::QuantileStatMap::StatDef statDef;
statDef.type = statType;
statDefs.push_back(statDef);
}
for (auto quantile : quantiles) {
detail::QuantileStatMap::StatDef statDef;
statDef.type = ExportType::PERCENT;
statDef.quantile = quantile;
statDefs.push_back(statDef);
}
return quantileMap_.registerQuantileStat(
name, std::move(stat), std::move(statDefs));
}