Adding a tool to parse the execution logs.

For now, the tool simply displays the log as text.

TESTED=ran it
RELNOTES: A tool to parse the Bazel execution log.
PiperOrigin-RevId: 200718299
diff --git a/src/BUILD b/src/BUILD
index d243184..131eda9 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -334,6 +334,7 @@
         "//src/test/py/bazel:srcs",
         "//src/test/shell:srcs",
         "//src/tools/android/java/com/google/devtools/build/android:srcs",
+        "//src/tools/execlog:srcs",
         "//src/tools/launcher:srcs",
         "//src/tools/runfiles:srcs",
         "//src/tools/package_printer/java/com/google/devtools/build/packageprinter:srcs",
diff --git a/src/tools/execlog/BUILD b/src/tools/execlog/BUILD
new file mode 100644
index 0000000..d6ba1a2
--- /dev/null
+++ b/src/tools/execlog/BUILD
@@ -0,0 +1,12 @@
+filegroup(
+    name = "srcs",
+    srcs = glob(["**"]) + ["//src/tools/execlog/src/main/java/com/google/devtools/build/execlog:srcs"],
+    visibility = ["//src:__pkg__"],
+)
+
+java_binary(
+    name = "parser",
+    main_class = "com.google.devtools.build.execlog.ExecLogParser",
+    visibility = ["//visibility:public"],
+    runtime_deps = ["//src/tools/execlog/src/main/java/com/google/devtools/build/execlog:parser"],
+)
diff --git a/src/tools/execlog/README.md b/src/tools/execlog/README.md
new file mode 100644
index 0000000..a65c9ee
--- /dev/null
+++ b/src/tools/execlog/README.md
@@ -0,0 +1,14 @@
+# Execution Log Parser
+
+This tool is used to inspect and parse the Bazel execution logs.
+To generate the execution log, run e.g.:
+
+        bazel build \
+            --experimental_execution_log_file=/tmp/exec.log :hello_world
+
+Then build the parser and run it.
+
+        bazel build src/tools/execlog:all
+        bazel-bin/src/tools/execlog/parser --log_path=/tmp/exec.log
+
+This will simply print the log contents to stdout in text form.
diff --git a/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/BUILD b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/BUILD
new file mode 100644
index 0000000..8aa327a
--- /dev/null
+++ b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/BUILD
@@ -0,0 +1,15 @@
+filegroup(
+    name = "srcs",
+    srcs = glob(["**"]),
+    visibility = ["//src/tools/execlog:__pkg__"],
+)
+
+java_library(
+    name = "parser",
+    srcs = glob(["*.java"]),
+    visibility = ["//src/tools/execlog:__subpackages__"],
+    deps = [
+        "//src/main/java/com/google/devtools/common/options",
+        "//src/main/protobuf:spawn_java_proto",
+    ],
+)
diff --git a/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ExecLogParser.java b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ExecLogParser.java
new file mode 100644
index 0000000..238a30b
--- /dev/null
+++ b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ExecLogParser.java
@@ -0,0 +1,40 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.execlog;
+
+import com.google.devtools.build.lib.exec.Protos.SpawnExec;
+import com.google.devtools.common.options.OptionsParser;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * A tool to inspect and parse the Bazel execution log.
+ */
+final class ExecLogParser {
+
+  static final String DELIMITER = "\n---------------------------------------------------------\n";
+
+  public static void main(String[] args) throws Exception {
+    OptionsParser op = OptionsParser.newOptionsParser(ParserOptions.class);
+    op.parseAndExitUponError(args);
+    ParserOptions options = op.getOptions(ParserOptions.class);
+    InputStream in = new FileInputStream(options.logPath);
+    while (in.available() > 0) {
+      SpawnExec ex = SpawnExec.parseDelimitedFrom(in);
+      System.out.println(ex);
+      System.out.println(DELIMITER);
+    }
+  }
+}
diff --git a/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ParserOptions.java b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ParserOptions.java
new file mode 100644
index 0000000..326cb43
--- /dev/null
+++ b/src/tools/execlog/src/main/java/com/google/devtools/build/execlog/ParserOptions.java
@@ -0,0 +1,33 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.execlog;
+
+import com.google.devtools.common.options.Option;
+import com.google.devtools.common.options.OptionDocumentationCategory;
+import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.OptionsBase;
+
+/** Options for execution log parser. */
+public class ParserOptions extends OptionsBase {
+  @Option(
+    name = "log_path",
+    defaultValue = "null",
+    category = "logging",
+    documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+    effectTags = {OptionEffectTag.UNKNOWN},
+    help = "Location of the log file to parse."
+  )
+  public String logPath;
+}