From b8832fcf1e2ae1e43d5e4523016731af40ab58d7 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Wed, 8 Jul 2015 20:07:21 -0700 Subject: [PATCH] HADOOP-12201. Add tracing to FileSystem#createFileSystem and Globber#glob (cmccabe) --- .../hadoop-common/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/fs/FileSystem.java | 20 +++++++++++++++---- .../java/org/apache/hadoop/fs/Globber.java | 17 ++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index eb18e6c9ec2..c99fb5e6f80 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -687,6 +687,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12195. Add annotation to package-info.java file to workaround MCOMPILER-205. (wang) + HADOOP-12201. Add tracing to FileSystem#createFileSystem and Globber#glob + (cmccabe) + OPTIMIZATIONS HADOOP-11785. Reduce the number of listStatus operation in distcp diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index c73caf74835..5e03e88f2c9 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -67,6 +67,9 @@ import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ShutdownHookManager; import org.apache.hadoop.util.StringUtils; +import org.apache.htrace.Span; +import org.apache.htrace.Trace; +import org.apache.htrace.TraceScope; import com.google.common.annotations.VisibleForTesting; @@ -2675,10 +2678,19 @@ public static Class getFileSystemClass(String scheme, private static FileSystem createFileSystem(URI uri, Configuration conf ) throws IOException { - Class clazz = getFileSystemClass(uri.getScheme(), conf); - FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf); - fs.initialize(uri, conf); - return fs; + TraceScope scope = Trace.startSpan("FileSystem#createFileSystem"); + Span span = scope.getSpan(); + if (span != null) { + span.addKVAnnotation("scheme", uri.getScheme()); + } + try { + Class clazz = getFileSystemClass(uri.getScheme(), conf); + FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf); + fs.initialize(uri, conf); + return fs; + } finally { + scope.close(); + } } /** Caching FileSystem objects */ diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java index 9cb810fc5cf..48639b4e5e3 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java @@ -28,6 +28,10 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; +import org.apache.htrace.Span; +import org.apache.htrace.Trace; +import org.apache.htrace.TraceScope; + @InterfaceAudience.Private @InterfaceStability.Unstable class Globber { @@ -136,6 +140,19 @@ private String authorityFromPath(Path path) throws IOException { } public FileStatus[] glob() throws IOException { + TraceScope scope = Trace.startSpan("Globber#glob"); + Span span = scope.getSpan(); + if (span != null) { + span.addKVAnnotation("pattern", pathPattern.toUri().getPath()); + } + try { + return doGlob(); + } finally { + scope.close(); + } + } + + private FileStatus[] doGlob() throws IOException { // First we get the scheme and authority of the pattern that was passed // in. String scheme = schemeFromPath(pathPattern);