libdd_profiling/internal/
endpoint_stats.rs

1// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4use std::collections::HashMap;
5
6use serde::Serialize;
7
8#[derive(Default, PartialEq, Eq, Debug, Clone, Serialize)]
9#[serde(transparent)]
10pub struct ProfiledEndpointsStats {
11    count: HashMap<String, i64>,
12}
13
14impl From<HashMap<String, i64>> for ProfiledEndpointsStats {
15    fn from(count: HashMap<String, i64>) -> Self {
16        ProfiledEndpointsStats { count }
17    }
18}
19
20impl ProfiledEndpointsStats {
21    pub fn add_endpoint_count(&mut self, endpoint_name: String, value: i64) {
22        let entry = self.count.entry(endpoint_name).or_insert(0);
23        *entry = entry.saturating_add(value);
24    }
25
26    pub fn is_empty(&self) -> bool {
27        self.count.is_empty()
28    }
29}