diff options
author | 2016-02-03 18:46:36 +0000 | |
---|---|---|
committer | 2016-02-03 22:06:53 +0000 | |
commit | e711f816880aa292bd452ae46ddf3d8b2c776681 (patch) | |
tree | 830d781e0002fec3ece7d79016ce5b768a96657c /src/main | |
parent | ce6a7b27eaebe111614592ba7d8a9965a9790f80 (diff) |
Fix NPE in vfs profile output
Also removed some unused code while I was here.
Fixes https://github.com/bazelbuild/bazel/issues/726.
--
MOS_MIGRATED_REVID=113758464
Diffstat (limited to 'src/main')
3 files changed, 17 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseHtml.java b/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseHtml.java index 0403768112..1184b221f8 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseHtml.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseHtml.java @@ -28,6 +28,8 @@ import java.io.PrintStream; import java.util.Arrays; import java.util.EnumMap; +import javax.annotation.Nullable; + /** * Output {@link PhaseSummaryStatistics}, {@link PhaseStatistics} and {@link PhaseVfsStatistics} * in HTML format. @@ -223,8 +225,8 @@ public final class PhaseHtml extends HtmlPrinter { * by descending duration. If multiple of the same VFS operation were logged for the same path, * print the total duration. */ - private void printVfsStatistics(PhaseVfsStatistics stats) { - if (vfsStatsLimit == 0 || stats.isEmpty()) { + private void printVfsStatistics(@Nullable PhaseVfsStatistics stats) { + if (vfsStatsLimit == 0 || stats == null || stats.isEmpty()) { return; } diff --git a/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseText.java b/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseText.java index f3b71098bf..71be9dca4c 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseText.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/output/PhaseText.java @@ -27,6 +27,8 @@ import java.io.PrintStream; import java.util.Arrays; import java.util.EnumMap; +import javax.annotation.Nullable; + /** * Output {@link PhaseSummaryStatistics}, {@link PhaseStatistics} and {@link PhaseVfsStatistics} * in text format. @@ -107,10 +109,7 @@ public final class PhaseText extends TextPrinter { if (!stats.isEmpty()) { printTimingDistribution(stats); printLn(); - if (vfsStatsLimit != 0) { - printVfsStatistics(stats.getVfsStatistics()); - printLn(); - } + printVfsStatistics(stats.getVfsStatistics()); } } @@ -171,10 +170,7 @@ public final class PhaseText extends TextPrinter { printLn(); } - if (vfsStatsLimit != 0) { - printVfsStatistics(execPhase.getVfsStatistics()); - printLn(); - } + printVfsStatistics(execPhase.getVfsStatistics()); } /** @@ -199,10 +195,13 @@ public final class PhaseText extends TextPrinter { * sorted by descending duration. If multiple of the same VFS operation were logged for the same * path, print the total duration. */ - private void printVfsStatistics(PhaseVfsStatistics stats) { + private void printVfsStatistics(@Nullable PhaseVfsStatistics stats) { + if (vfsStatsLimit == 0 || stats == null || stats.isEmpty()) { + return; + } + lnPrint("VFS path statistics:"); lnPrintf("%15s %10s %10s %s", "Type", "Frequency", "Duration", "Path"); - for (ProfilerTask type : stats) { int numPrinted = 0; for (Stat stat : stats.getSortedStatistics(type)) { @@ -218,6 +217,7 @@ public final class PhaseText extends TextPrinter { stat.path); } } + printLn(); } } diff --git a/src/main/java/com/google/devtools/build/lib/profiler/statistics/PhaseStatistics.java b/src/main/java/com/google/devtools/build/lib/profiler/statistics/PhaseStatistics.java index 55655576d9..b8e303b3f1 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/statistics/PhaseStatistics.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/statistics/PhaseStatistics.java @@ -26,6 +26,8 @@ import java.util.EnumMap; import java.util.Iterator; import java.util.List; +import javax.annotation.Nullable; + /** * Extracts and keeps statistics for one {@link ProfilePhase} for formatting to various outputs. */ @@ -38,7 +40,6 @@ public final class PhaseStatistics implements Iterable<ProfilerTask> { private final EnumMap<ProfilerTask, Long> taskCounts; private final PhaseVfsStatistics vfsStatistics; private boolean wasExecuted; - private int count; public PhaseStatistics(ProfilePhase phase, boolean generateVfsStatistics) { this.phase = phase; @@ -84,7 +85,6 @@ public final class PhaseStatistics implements Iterable<ProfilerTask> { add(taskCounts, type, count); add(taskDurations, type, totalTime); } - count++; } } @@ -107,21 +107,14 @@ public final class PhaseStatistics implements Iterable<ProfilerTask> { add(taskCounts, type, otherCount); add(taskDurations, type, otherDuration); } - count++; } } - /** - * @return how many executions of this phase were accumulated - */ - public int getPhaseCount() { - return count; - } - public ProfilePhase getProfilePhase() { return phase; } + @Nullable public PhaseVfsStatistics getVfsStatistics() { return vfsStatistics; } @@ -144,10 +137,6 @@ public final class PhaseStatistics implements Iterable<ProfilerTask> { return phaseDurationNanos; } - public long getTotalDurationNanos() { - return totalDurationNanos; - } - /** * @return true if a task of the given {@link ProfilerTask} type was executed in this phase */ |