From 090780c5bd78d2e76a8c4cfcef000724f9745b6a Mon Sep 17 00:00:00 2001 From: Karthik Palanisamy Date: Wed, 23 Oct 2019 15:14:01 -0700 Subject: [PATCH] HBASE-23208 Unit formatting in Master & RS UI Signed-off-by: binlijin Signed-off-by: Sean Busbey (cherry picked from commit 257ccad31c0886080814138aec92beb1970a54d6) (cherry picked from commit fe23e3fd5b14023402ea2b1884c265444bf81c75) --- .../hbase/procedure2/util/StringUtils.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/StringUtils.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/StringUtils.java index a2c4713ad45..2cd0a824c46 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/StringUtils.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/util/StringUtils.java @@ -28,7 +28,7 @@ public final class StringUtils { public static String humanTimeDiff(long timeDiff) { if (timeDiff < 1000) { - return String.format("%dmsec", timeDiff); + return String.format("%d msec", timeDiff); } StringBuilder buf = new StringBuilder(); @@ -40,26 +40,38 @@ public final class StringUtils { if (hours != 0){ buf.append(hours); - buf.append("hrs, "); + buf.append(" hrs, "); } if (minutes != 0){ buf.append(minutes); - buf.append("mins, "); + buf.append(" mins, "); } if (hours > 0 || minutes > 0) { buf.append(seconds); - buf.append("sec"); + buf.append(" sec"); } else { - buf.append(String.format("%.4fsec", seconds)); + buf.append(String.format("%.4f sec", seconds)); } return buf.toString(); } public static String humanSize(double size) { - if (size >= (1L << 40)) return String.format("%.1fT", size / (1L << 40)); - if (size >= (1L << 30)) return String.format("%.1fG", size / (1L << 30)); - if (size >= (1L << 20)) return String.format("%.1fM", size / (1L << 20)); - if (size >= (1L << 10)) return String.format("%.1fK", size / (1L << 10)); + if (size >= (1L << 40)) { + return String.format("%.1f T", size / (1L << 40)); + } + + if (size >= (1L << 30)) { + return String.format("%.1f G", size / (1L << 30)); + } + + if (size >= (1L << 20)) { + return String.format("%.1f M", size / (1L << 20)); + } + + if (size >= (1L << 10)) { + return String.format("%.1f K", size / (1L << 10)); + } + return String.format("%.0f", size); } @@ -81,4 +93,4 @@ public final class StringUtils { } return sb; } -} \ No newline at end of file +}