Skip to content

Commit 020f3c0

Browse files
committed
Cloudup and bandwidth commands print iostats (through reflection)
1 parent ccef333 commit 020f3c0

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

src/main/java/org/apache/hadoop/fs/store/commands/Bandwidth.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.hadoop.fs.store.StoreDurationInfo;
4545
import org.apache.hadoop.fs.store.StoreEntryPoint;
4646
import org.apache.hadoop.fs.store.StoreUtils;
47+
import org.apache.hadoop.fs.store.logging.IOStatisticsIntegration;
4748
import org.apache.hadoop.fs.tools.csv.CsvWriterWithCRC;
4849
import org.apache.hadoop.util.Progressable;
4950
import org.apache.hadoop.util.ShutdownHookManager;
@@ -375,6 +376,15 @@ public int run(String[] args) throws Exception {
375376
}
376377
}
377378

379+
final IOStatisticsIntegration ios = new IOStatisticsIntegration();
380+
if (ios.available()) {
381+
final String prettyString = ios.ioStatisticsToPrettyString(fs);
382+
if (!prettyString.isEmpty()) {
383+
heading("Destination Filesystem IO Statistics");
384+
println(prettyString);
385+
}
386+
}
387+
378388
// now print summaries
379389
summarize("Upload", uploadDurationTracker, fileSizeBytes,
380390
"Blocks uploaded (ignoring close() overhead):", blockUploads);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.store.logging;
20+
21+
import org.apache.hadoop.fs.statistics.IOStatistics;
22+
import org.apache.hadoop.fs.store.shim.impl.Invocation;
23+
import org.apache.hadoop.fs.store.shim.impl.ShimReflectionSupport;
24+
25+
import static org.apache.hadoop.fs.store.shim.impl.Invocation.unavailable;
26+
import static org.apache.hadoop.fs.store.shim.impl.ShimReflectionSupport.loadClass;
27+
import static org.apache.hadoop.fs.store.shim.impl.ShimReflectionSupport.loadInvocation;
28+
29+
/**
30+
* Support for IO statistics (initially through reflection).
31+
*/
32+
public class IOStatisticsIntegration {
33+
34+
public static final String CLASSNAME_IOSTATISTICS = "org.apache.hadoop.fs.statistics.IOStatistics";
35+
36+
public static final String CLASSNAME_IOSTATISTICS_LOGGING = "org.apache.hadoop.fs.statistics.IOStatisticsLogging";
37+
public static final String CLASSNAME_IOSTATISTICS_SUPPORT = "org.apache.hadoop.fs.statistics.IOStatisticsSupport";
38+
39+
private final Class<?> ioStatisticsClass;
40+
41+
private final Class<?> ioStatisticsLogging;
42+
private final Class<?> ioStatisticsSupport;
43+
44+
private final Invocation<String> _ioStatisticsToPrettyString;
45+
46+
private final Invocation<?> _retrieveIOStatistics;
47+
48+
public IOStatisticsIntegration() {
49+
// try to load the class
50+
ioStatisticsClass = loadClass(CLASSNAME_IOSTATISTICS);
51+
if (ioStatisticsClass == null) {
52+
// if that class is missing, so is the rest.
53+
ioStatisticsSupport = null;
54+
ioStatisticsLogging = null;
55+
_ioStatisticsToPrettyString = unavailable("ioStatisticsToPrettyString");
56+
_retrieveIOStatistics = unavailable("retrieveIOStatistics");
57+
} else {
58+
ioStatisticsSupport = loadClass(CLASSNAME_IOSTATISTICS_SUPPORT);
59+
_retrieveIOStatistics = loadInvocation(ioStatisticsSupport,
60+
ioStatisticsClass, "retrieveIOStatistics", Object.class);
61+
62+
ioStatisticsLogging = loadClass(CLASSNAME_IOSTATISTICS_LOGGING);
63+
64+
_ioStatisticsToPrettyString = loadInvocation(ioStatisticsLogging,
65+
String.class, "ioStatisticsToPrettyString", ioStatisticsClass);
66+
}
67+
}
68+
69+
public boolean available() {
70+
return ioStatisticsClass != null;
71+
}
72+
73+
public String ioStatisticsToPrettyString(Object source) {
74+
if (!available()) {
75+
return "";
76+
}
77+
return _ioStatisticsToPrettyString.invokeUnchecked(null,
78+
_retrieveIOStatistics.invokeUnchecked(null, source));
79+
}
80+
}

src/main/java/org/apache/hadoop/fs/tools/cloudup/Cloudup.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.hadoop.fs.store.StoreDurationInfo;
6060
import org.apache.hadoop.fs.store.StoreEntryPoint;
6161
import org.apache.hadoop.fs.store.StoreUtils;
62+
import org.apache.hadoop.fs.store.logging.IOStatisticsIntegration;
6263
import org.apache.hadoop.util.Progressable;
6364
import org.apache.hadoop.util.ToolRunner;
6465

@@ -782,7 +783,16 @@ private void dumpStats(FileSystem fs, String header) {
782783
// Not supported on Hadoop 2.7
783784
println();
784785
println("%s: %s", header, fs.getUri());
786+
final IOStatisticsIntegration ios = new IOStatisticsIntegration();
787+
if (ios.available()) {
788+
final String prettyString = ios.ioStatisticsToPrettyString(fs);
789+
if (!prettyString.isEmpty()) {
790+
println(prettyString);
791+
return;
792+
}
793+
}
785794

795+
// only get here if there are no iostats
786796
if (verbose) {
787797
// hope to see FS IOStats
788798
println("Filesystem %s", fs);

0 commit comments

Comments
 (0)