MCPcopy Create free account
hub / github.com/3rdparty/libprocess / __snapshot

Method __snapshot

src/metrics/metrics.cpp:225–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223
224
225Future<map<string, double>> MetricsProcess::__snapshot(
226 const Option<Duration>& timeout,
227 vector<string>&& keys,
228 vector<Future<double>>&& metrics,
229 vector<Option<Statistics<double>>>&& statistics)
230{
231 map<string, double> snapshot;
232
233 for (size_t i = 0; i < metrics.size(); ++i) {
234 // TODO(dhamon): Maybe add the failure message for this metric to the
235 // response if value.isFailed().
236 const string& key = keys[i];
237 const Future<double>& value = metrics[i];
238
239 if (value.isPending()) {
240 CHECK_SOME(timeout);
241 VLOG(1) << "Exceeded timeout of " << timeout.get()
242 << " when attempting to get metric '" << key << "'";
243 } else if (value.isReady()) {
244 snapshot.emplace_hint(snapshot.end(), key, value.get());
245 }
246
247 if (statistics[i].isSome()) {
248 Statistics<double>& statistics_ = statistics[i].get();
249 snapshot.emplace_hint(
250 snapshot.end(),
251 key + "/count",
252 static_cast<double>(statistics_.count));
253 // TODO(alexr): Consider exposing p25 and p75 percentiles.
254 snapshot.emplace_hint(snapshot.end(), key + "/max", statistics_.max);
255 snapshot.emplace_hint(snapshot.end(), key + "/min", statistics_.min);
256 snapshot.emplace_hint(snapshot.end(), key + "/p50", statistics_.p50);
257 snapshot.emplace_hint(snapshot.end(), key + "/p90", statistics_.p90);
258 snapshot.emplace_hint(snapshot.end(), key + "/p95", statistics_.p95);
259 snapshot.emplace_hint(snapshot.end(), key + "/p99", statistics_.p99);
260 snapshot.emplace_hint(snapshot.end(), key + "/p999", statistics_.p999);
261 snapshot.emplace_hint(snapshot.end(), key + "/p9999", statistics_.p9999);
262 }
263 }
264
265 // NOTE: Newer compilers (clang-3.9 and gcc-5.1) can perform
266 // this move automatically when optimization is on. Once these
267 // are the minimum versions, remove this `std::move`.
268 return std::move(snapshot);
269}
270
271} // namespace internal {
272

Callers

nothing calls this directly

Calls 4

isPendingMethod · 0.80
isReadyMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected