From fe5c23b670c773145b87fecfaf9191536e9f1c51 Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Fri, 20 Mar 2015 17:03:03 -0700 Subject: [PATCH] HADOOP-11447. Add a more meaningful toString method to SampleStat and MutableStat. (kasha) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/metrics2/lib/MutableStat.java | 4 ++++ .../org/apache/hadoop/metrics2/util/SampleStat.java | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 823a36bad7..4cd21542a7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -455,6 +455,9 @@ Release 2.8.0 - UNRELEASED HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable (Ajith S via ozawa) + HADOOP-11447. Add a more meaningful toString method to SampleStat and + MutableStat. (kasha) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java index ba377570ef..d794e8eeed 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableStat.java @@ -151,4 +151,8 @@ public void resetMinMax() { minMax.reset(); } + @Override + public String toString() { + return lastStat().toString(); + } } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleStat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleStat.java index 589062a691..cd9aaa49e1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleStat.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleStat.java @@ -137,6 +137,19 @@ public double max() { return minmax.max(); } + @Override + public String toString() { + try { + return "Samples = " + numSamples() + + " Min = " + min() + + " Mean = " + mean() + + " Std Dev = " + stddev() + + " Max = " + max(); + } catch (Throwable t) { + return super.toString(); + } + } + /** * Helper to keep running min/max */