aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java
diff options
context:
space:
mode:
authorGravatar Klaas Boesche <klaasb@google.com>2015-10-09 13:24:28 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-09 14:42:49 +0000
commit6133c3f93d2664f8923ec027443041e595eadead (patch)
tree377504d2d345d6aa9c43cd16f7694f265b9bc258 /src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java
parent3c74af02c9ab519fa9551bf518c834f77babd8a4 (diff)
Add combine option for multiple profile file stats
Add the --combine option to produce a single aggregated statistics output for multiple profile files. Outputs neither Skylark histograms nor the task chart. -- MOS_MIGRATED_REVID=105051164
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java b/src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java
new file mode 100644
index 0000000000..cbde62b4b4
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/profiler/output/MultiProfilePhaseHtml.java
@@ -0,0 +1,110 @@
+// Copyright 2015 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.lib.profiler.output;
+
+import com.google.devtools.build.lib.profiler.ProfilePhase;
+import com.google.devtools.build.lib.profiler.ProfilerTask;
+import com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics;
+import com.google.devtools.build.lib.profiler.statistics.PhaseStatistics;
+import com.google.devtools.build.lib.util.TimeUtilities;
+import com.google.devtools.build.lib.vfs.Path;
+
+import java.io.PrintStream;
+import java.util.EnumMap;
+
+/**
+ * Formats the per file phase statistics from {@link MultiProfileStatistics} into HTML tables.
+ */
+public final class MultiProfilePhaseHtml extends HtmlPrinter {
+
+ private final MultiProfileStatistics statistics;
+
+ public MultiProfilePhaseHtml(PrintStream out, MultiProfileStatistics statistics) {
+ super(out);
+ this.statistics = statistics;
+ }
+
+ /**
+ * Prints CSS definitions and JavaScript code.
+ */
+ void printHtmlHead() {
+ lnOpen("style", "type", "text/css", "<!--");
+ lnPrint("div.profiles-table {");
+ lnPrint(" width: 95%; margin: 0 auto; height: auto;");
+ lnPrint("}");
+ lnPrint("-->");
+ close(); // style
+ }
+
+ /**
+ * Prints the table data and JS for each phase and file.
+ *
+ * <p>Code must be added to the callback that is run when the Visualization library has loaded.
+ */
+ public void printVisualizationCallbackJs() {
+ lnPrint("var multiData;");
+ lnPrint("var statsDiv;");
+ lnPrint("var profileTable;");
+ for (ProfilePhase phase : statistics.getSummaryStatistics()) {
+ lnPrintf("statsDiv = document.getElementById('profile_file_stats_%s');", phase.nick);
+ lnPrint("multiData = new google.visualization.DataTable();");
+ lnPrint("multiData.addColumn('string', 'File');");
+ lnPrint("multiData.addColumn('number', 'total');");
+ PhaseStatistics summaryPhaseStatistics = statistics.getSummaryPhaseStatistics(phase);
+ for (ProfilerTask taskType : summaryPhaseStatistics) {
+ lnPrintf("multiData.addColumn('number', '%s %%');", taskType.name());
+ }
+ lnPrint("multiData.addRows([");
+ down();
+ for (Path file : statistics) {
+ EnumMap<ProfilePhase, PhaseStatistics> phases = statistics.getPhaseStatistics(file);
+ PhaseStatistics phaseStatistics = phases.get(phase);
+ lnPrintf("['%s', ", file);
+ long phaseDuration = phaseStatistics.getPhaseDurationNanos();
+ printf("{v:%d, f:'%s'}, ", phaseDuration, TimeUtilities.prettyTime(phaseDuration));
+ for (ProfilerTask taskType : summaryPhaseStatistics) {
+ if (phaseStatistics.wasExecuted(taskType)) {
+ double relative = phaseStatistics.getTotalRelativeDuration(taskType);
+ printf("{v:%.4f, f:'%.3f %%'}, ", relative, relative * 100);
+ } else {
+ print("0, ");
+ }
+ }
+ print("],");
+ }
+ lnPrint("]);");
+ up();
+ lnPrint("profileTable = new google.visualization.Table(statsDiv);");
+ lnPrint("profileTable.draw(multiData, {showRowNumber: true, width: '100%%'});");
+ }
+ }
+
+ /**
+ * Prints divs for the tables of statistics for profile files and their phases.
+ */
+ void printHtmlBody() {
+ lnPrint("<a name='profile_file_stats'/>");
+ lnElement("h3", "Profile File Statistics");
+ lnOpen("div", "class", "profiles-tables", "id", "profile_file_stats");
+ for (ProfilePhase phase : statistics.getSummaryStatistics()) {
+ lnOpen("div");
+ lnElement("h4", phase.nick);
+ lnElement("div", "class", "profiles-table", "id", "profile_file_stats_" + phase.nick);
+ lnClose();
+ }
+ lnClose(); // div
+ }
+}
+
+