| Index: tools/binary_size/java/src/org/chromium/tools/binary_size/NmDumper.java
|
| diff --git a/tools/binary_size/java/src/org/chromium/tools/binary_size/NmDumper.java b/tools/binary_size/java/src/org/chromium/tools/binary_size/NmDumper.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c4803f83737e46a88b15de1a7e369625e26fa4bf
|
| --- /dev/null
|
| +++ b/tools/binary_size/java/src/org/chromium/tools/binary_size/NmDumper.java
|
| @@ -0,0 +1,126 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +package org.chromium.tools.binary_size;
|
| +
|
| +import java.io.FileNotFoundException;
|
| +import java.io.IOException;
|
| +import java.io.PrintWriter;
|
| +
|
| +
|
| +class NmDumper {
|
| + private final String outPath;
|
| + private final String skipPath;
|
| + private final String failPath;
|
| + private final Output output;
|
| +
|
| + NmDumper(final String outPath, final String failPath, final String skipPath) {
|
| + this.outPath = outPath;
|
| + this.failPath = failPath;
|
| + this.skipPath = skipPath;
|
| + output = new Output();
|
| + }
|
| +
|
| + void close() {
|
| + output.closeAll();
|
| + }
|
| +
|
| + void skipped(String line) {
|
| + output.printSkip(line);
|
| + }
|
| +
|
| + void failed(Record record) {
|
| + output.printFail(simulateNmOutput(record));
|
| + }
|
| +
|
| + void succeeded(Record record) {
|
| + output.print(simulateNmOutput(record));
|
| + }
|
| +
|
| + private static final String simulateNmOutput(final Record record) {
|
| + StringBuilder builder = new StringBuilder(record.address);
|
| + builder.append(' ');
|
| + builder.append(record.size);
|
| + builder.append(' ');
|
| + builder.append(record.symbolType);
|
| + builder.append(' ');
|
| + builder.append(record.symbolName != null ? record.symbolName : "unknown");
|
| + if (record.location != null) {
|
| + builder.append('\t');
|
| + builder.append(record.location);
|
| + }
|
| + return builder.toString();
|
| + }
|
| +
|
| + private class Output {
|
| + private final PrintWriter skipWriter;
|
| + private final PrintWriter failWriter;
|
| + private final PrintWriter outWriter;
|
| +
|
| + private Output() {
|
| + try {
|
| + outWriter = new PrintWriter(outPath);
|
| + } catch (FileNotFoundException e) {
|
| + throw new RuntimeException("Can't open output file: " + outPath, e);
|
| + }
|
| +
|
| + if (failPath != null) {
|
| + try {
|
| + failWriter = new PrintWriter(failPath);
|
| + } catch (FileNotFoundException e) {
|
| + throw new RuntimeException("Can't open fail file: " + failPath, e);
|
| + }
|
| + } else {
|
| + failWriter = null;
|
| + }
|
| +
|
| + if (skipPath != null) {
|
| + try {
|
| + skipWriter = new PrintWriter(skipPath);
|
| + } catch (IOException e) {
|
| + throw new RuntimeException("Can't open skip file: " + skipPath, e);
|
| + }
|
| + } else {
|
| + skipWriter = null;
|
| + }
|
| + }
|
| +
|
| + private synchronized void println(PrintWriter writer, String string) {
|
| + if (writer != null) {
|
| + writer.println(string);
|
| + writer.flush();
|
| + }
|
| + }
|
| +
|
| + synchronized void print(String string) {
|
| + println(outWriter, string);
|
| + }
|
| +
|
| + synchronized void printSkip(String string) {
|
| + println(skipWriter, string);
|
| + println(outWriter, string);
|
| + }
|
| +
|
| + synchronized void printFail(String string) {
|
| + println(failWriter, string);
|
| + println(outWriter, string);
|
| + }
|
| +
|
| + private void closeAll() {
|
| + for (PrintWriter writer : new PrintWriter[]{outWriter, failWriter, skipWriter}) {
|
| + if (writer != null) {
|
| + try {
|
| + writer.flush(); }
|
| + catch (Exception ignored) {
|
| + // Nothing to be done.
|
| + }
|
| + try {
|
| + writer.close(); }
|
| + catch (Exception ignored) {
|
| + // Nothing to be done.
|
| + }
|
| + }
|
| + }
|
| + }
|
| + }
|
| +}
|
|
|