optimize counter submission: avoid copy when converting counters to datapoints (#24802)
This commit is contained in:
parent
428cf54c91
commit
591bfc3e0c
|
@ -20,8 +20,8 @@ use {
|
||||||
|
|
||||||
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
|
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
|
||||||
|
|
||||||
impl From<CounterPoint> for DataPoint {
|
impl From<&CounterPoint> for DataPoint {
|
||||||
fn from(counter_point: CounterPoint) -> Self {
|
fn from(counter_point: &CounterPoint) -> Self {
|
||||||
let mut point = Self::new(counter_point.name);
|
let mut point = Self::new(counter_point.name);
|
||||||
point.timestamp = counter_point.timestamp;
|
point.timestamp = counter_point.timestamp;
|
||||||
point.add_field_i64("count", counter_point.count);
|
point.add_field_i64("count", counter_point.count);
|
||||||
|
@ -162,9 +162,8 @@ impl MetricsAgent {
|
||||||
fn collect_points(points: &mut Vec<DataPoint>, counters: &mut CounterMap) -> Vec<DataPoint> {
|
fn collect_points(points: &mut Vec<DataPoint>, counters: &mut CounterMap) -> Vec<DataPoint> {
|
||||||
let mut ret: Vec<DataPoint> = Vec::default();
|
let mut ret: Vec<DataPoint> = Vec::default();
|
||||||
std::mem::swap(&mut ret, points);
|
std::mem::swap(&mut ret, points);
|
||||||
for (_, v) in counters.drain() {
|
ret.extend(counters.values().map(|v| v.into()));
|
||||||
ret.push(v.into());
|
counters.clear();
|
||||||
}
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue