tustvold commented on a change in pull request #901: URL: https://github.com/apache/arrow-datafusion/pull/901#discussion_r690595405
########## File path: datafusion/src/physical_plan/metrics/wrappers.rs ########## @@ -0,0 +1,105 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! wrappers for `SQLMetrics` for more conveniently recording execution metrics + +use std::{sync::Arc, time::Instant}; + +use super::SQLMetric; + +// pub trait MetricSource { +// /// Return the underlying metric +// pub fn metric(&self) -> Arc<SQLMetric>; +// } + +/// a SQLMetric wrapper for a counter (number of input or output rows) +/// +/// Note `clone` counters update the same underlying metrics +#[derive(Debug, Clone)] +pub struct Count { + inner: Arc<SQLMetric>, +} + +impl Count { + /// create a new counter wrapper around this metric + pub fn new(inner: Arc<SQLMetric>) -> Self { + Self { inner } + } + + /// Add `n` to the counter's value + pub fn add(&self, n: usize) { + self.inner.add(n) + } +} + +/// a SQLMetric wrapper for CPU timing information +#[derive(Debug, Clone)] +pub struct Time { + inner: Arc<SQLMetric>, +} + +impl Time { + /// Create a new [`Time`] wrapper suitable for recording elapsed + /// times for operations. + pub fn new(inner: Arc<SQLMetric>) -> Self { Review comment: I wonder if these should be verifying the MetricKind of the SQLMetric? Or alternatively be private and have a member function on SQLMetric that does the verification -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org