alamb commented on a change in pull request #901: URL: https://github.com/apache/arrow-datafusion/pull/901#discussion_r691444996
########## 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: This is a good point. 🤔 though now I think about it the more Rust-y way of doing this would be to do it in the type system... so perhaps I will collapse `MetricKind` 🤔 ########## File path: ballista/rust/core/src/execution_plans/shuffle_writer.rs ########## @@ -71,24 +74,30 @@ pub struct ShuffleWriterExec { work_dir: String, /// Optional shuffle output partitioning shuffle_output_partitioning: Option<Partitioning>, - /// Shuffle write metrics - metrics: ShuffleWriteMetrics, + /// Execution metrics + metrics: Arc<SharedMetricsSet>, Review comment: I think I was just copy/pasting the use from operators (like Parquet) that did need to `clone` their metrics. Upon further reflection, I think it is simpler to move the `Arc` inside and have the external interface simply be `SharedMetricsSet`. I have done so -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
