You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by xu...@apache.org on 2025/08/12 02:46:18 UTC
(datafusion) 01/03: save
This is an automated email from the ASF dual-hosted git repository.
xudong963 pushed a commit to branch metrics_serialize
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 9c584ac754ad670ff1b43e958b757f8b8538fcd2
Author: xudong963 <wx...@gmail.com>
AuthorDate: Sun Aug 10 21:19:52 2025 +0800
save
---
Cargo.lock | 1 +
datafusion/physical-plan/Cargo.toml | 1 +
datafusion/physical-plan/src/metrics/mod.rs | 8 +++++---
datafusion/physical-plan/src/metrics/value.rs | 11 ++++++-----
4 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 821a9dbfbf..a49c7b898a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2518,6 +2518,7 @@ dependencies = [
"rand 0.9.2",
"rstest",
"rstest_reuse",
+ "serde",
"tempfile",
"tokio",
]
diff --git a/datafusion/physical-plan/Cargo.toml b/datafusion/physical-plan/Cargo.toml
index 97b1cff777..ee9ef61204 100644
--- a/datafusion/physical-plan/Cargo.toml
+++ b/datafusion/physical-plan/Cargo.toml
@@ -65,6 +65,7 @@ log = { workspace = true }
parking_lot = { workspace = true }
pin-project-lite = "^0.2.7"
tokio = { workspace = true }
+serde = { version = "1.0", features = ["derive"] }
[dev-dependencies]
criterion = { workspace = true, features = ["async_futures"] }
diff --git a/datafusion/physical-plan/src/metrics/mod.rs b/datafusion/physical-plan/src/metrics/mod.rs
index 0b9b4bed85..74e85c882f 100644
--- a/datafusion/physical-plan/src/metrics/mod.rs
+++ b/datafusion/physical-plan/src/metrics/mod.rs
@@ -29,6 +29,8 @@ use std::{
sync::Arc,
};
+use serde::Serialize;
+
use datafusion_common::HashMap;
// public exports
@@ -67,7 +69,7 @@ pub use value::{Count, Gauge, MetricValue, ScopedTimerGuard, Time, Timestamp};
///
/// [`ExecutionPlan`]: super::ExecutionPlan
-#[derive(Debug)]
+#[derive(Debug, Serialize)]
pub struct Metric {
/// The value of the metric
value: MetricValue,
@@ -169,7 +171,7 @@ impl Metric {
/// A snapshot of the metrics for a particular ([`ExecutionPlan`]).
///
/// [`ExecutionPlan`]: super::ExecutionPlan
-#[derive(Default, Debug, Clone)]
+#[derive(Default, Debug, Clone, Serialize)]
pub struct MetricsSet {
metrics: Vec<Arc<Metric>>,
}
@@ -392,7 +394,7 @@ impl ExecutionPlanMetricsSet {
///
/// As the name and value are expected to mostly be constant strings,
/// use a [`Cow`] to avoid copying / allocations in this common case.
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct Label {
name: Cow<'static, str>,
value: Cow<'static, str>,
diff --git a/datafusion/physical-plan/src/metrics/value.rs b/datafusion/physical-plan/src/metrics/value.rs
index 3149fca95b..8252e81d8c 100644
--- a/datafusion/physical-plan/src/metrics/value.rs
+++ b/datafusion/physical-plan/src/metrics/value.rs
@@ -22,6 +22,7 @@ use chrono::{DateTime, Utc};
use datafusion_common::instant::Instant;
use datafusion_execution::memory_pool::human_readable_size;
use parking_lot::Mutex;
+use serde::Serialize;
use std::{
borrow::{Borrow, Cow},
fmt::{Debug, Display},
@@ -35,7 +36,7 @@ use std::{
/// A counter to record things such as number of input or output rows
///
/// Note `clone`ing counters update the same underlying metrics
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Serialize)]
pub struct Count {
/// value of the metric counter
value: Arc<AtomicUsize>,
@@ -84,7 +85,7 @@ impl Count {
/// For example, you can easily expose current memory consumption with a gauge.
///
/// Note `clone`ing gauge update the same underlying metrics
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Serialize)]
pub struct Gauge {
/// value of the metric gauge
value: Arc<AtomicUsize>,
@@ -149,7 +150,7 @@ impl Gauge {
}
/// Measure a potentially non contiguous duration of time
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Serialize)]
pub struct Time {
/// elapsed time, in nanoseconds
nanos: Arc<AtomicUsize>,
@@ -235,7 +236,7 @@ impl Time {
/// Stores a single timestamp, stored as the number of nanoseconds
/// elapsed from Jan 1, 1970 UTC
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Serialize)]
pub struct Timestamp {
/// Time thing started
timestamp: Arc<Mutex<Option<DateTime<Utc>>>>,
@@ -367,7 +368,7 @@ impl Drop for ScopedTimerGuard<'_> {
/// Among other differences, the metric types have different ways to
/// logically interpret their underlying values and some metrics are
/// so common they are given special treatment.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Serialize)]
pub enum MetricValue {
/// Number of output rows produced: "output_rows" metric
OutputRows(Count),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org