optimize counter submission: avoid copy when converting counters to datapoints (#24802)

This commit is contained in:
HaoranYi 2022-04-29 21:21:57 -05:00 committed by GitHub
parent 428cf54c91
commit 591bfc3e0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -20,8 +20,8 @@ use {
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
impl From<CounterPoint> for DataPoint {
fn from(counter_point: CounterPoint) -> Self {
impl From<&CounterPoint> for DataPoint {
fn from(counter_point: &CounterPoint) -> Self {
let mut point = Self::new(counter_point.name);
point.timestamp = counter_point.timestamp;
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> {
let mut ret: Vec<DataPoint> = Vec::default();
std::mem::swap(&mut ret, points);
for (_, v) in counters.drain() {
ret.push(v.into());
}
ret.extend(counters.values().map(|v| v.into()));
counters.clear();
ret
}