use of com.google.devtools.build.lib.profiler.ProfilePhase in project bazel by bazelbuild.
the class PhaseSummaryStatistics method addProfileInfo.
/**
* Add a summary of the {@link ProfilePhase}s durations from a {@link ProfileInfo}.
*/
public void addProfileInfo(ProfileInfo info) {
for (ProfilePhase phase : ProfilePhase.values()) {
ProfileInfo.Task phaseTask = info.getPhaseTask(phase);
if (phaseTask != null) {
long phaseDuration = info.getPhaseDuration(phaseTask);
totalDurationNanos += phaseDuration;
durations.put(phase, phaseDuration);
}
}
}
use of com.google.devtools.build.lib.profiler.ProfilePhase in project bazel by bazelbuild.
the class PhaseHtml method printPhaseSummaryStatistics.
/**
* Print a table for the phase overview with runtime and runtime percentage per phase and total.
*/
private void printPhaseSummaryStatistics() {
lnOpen("div", "class", "phase-statistics");
lnElement("h3", "Phase Summary Information");
lnOpen("table", "class", "phase-statistics");
for (ProfilePhase phase : phaseSummaryStats) {
lnOpen("tr");
lnOpen("td", "class", "left");
printf("Total %s phase time", phase.nick);
close();
element("td", TimeUtilities.prettyTime(phaseSummaryStats.getDurationNanos(phase)));
element("td", phaseSummaryStats.getPrettyPercentage(phase));
// tr
lnClose();
}
lnOpen("tr");
lnElement("td", "class", "left", "Total run time");
element("td", TimeUtilities.prettyTime(phaseSummaryStats.getTotalDuration()));
element("td", "100.00%");
// tr
lnClose();
// table
lnClose();
// div
lnClose();
}
use of com.google.devtools.build.lib.profiler.ProfilePhase in project bazel by bazelbuild.
the class PhaseText method print.
public void print() {
printPhaseSummaryStatistics();
for (ProfilePhase phase : Arrays.asList(ProfilePhase.INIT, ProfilePhase.LOAD, ProfilePhase.ANALYZE)) {
PhaseStatistics statistics = phaseStatistics.get(phase);
if (statistics.wasExecuted()) {
printPhaseStatistics(statistics);
}
}
printExecutionPhaseStatistics();
}
use of com.google.devtools.build.lib.profiler.ProfilePhase in project bazel by bazelbuild.
the class ProfileCommand method exec.
@Override
public ExitCode exec(final CommandEnvironment env, OptionsProvider options) {
ProfileOptions opts = options.getOptions(ProfileOptions.class);
if (!opts.vfsStats) {
opts.vfsStatsLimit = 0;
}
try (PrintStream out = new PrintStream(env.getReporter().getOutErr().getOutputStream())) {
env.getReporter().handle(Event.warn(null, "This information is intended for consumption by Blaze developers" + " only, and may change at any time. Script against it at your own risk"));
if (opts.combine != null && opts.dumpMode == null) {
MultiProfileStatistics statistics = new MultiProfileStatistics(env.getWorkingDirectory(), env.getWorkspaceName(), options.getResidue(), getInfoListener(env), opts.vfsStatsLimit > 0);
Path outputFile = env.getWorkingDirectory().getRelative(opts.combine);
try (PrintStream output = new PrintStream(new BufferedOutputStream(outputFile.getOutputStream()))) {
if (opts.html) {
env.getReporter().handle(Event.info("Creating HTML output in " + outputFile));
HtmlCreator.create(output, statistics, opts.htmlDetails, opts.htmlPixelsPerSecond, opts.vfsStatsLimit);
} else {
env.getReporter().handle(Event.info("Creating text output in " + outputFile));
new PhaseText(output, statistics.getSummaryStatistics(), statistics.getSummaryPhaseStatistics(), Optional.<CriticalPathStatistics>absent(), statistics.getMissingActionsCount(), opts.vfsStatsLimit).print();
}
} catch (IOException e) {
env.getReporter().handle(Event.error("Failed to write to output file " + outputFile + ":" + e.getMessage()));
}
} else {
for (String name : options.getResidue()) {
Path profileFile = env.getWorkingDirectory().getRelative(name);
try {
ProfileInfo info = ProfileInfo.loadProfileVerbosely(profileFile, getInfoListener(env));
if (opts.dumpMode == null || !opts.dumpMode.contains("unsorted")) {
ProfileInfo.aggregateProfile(info, getInfoListener(env));
}
if (opts.taskTree != null) {
printTaskTree(out, name, info, opts.taskTree, opts.taskTreeThreshold);
continue;
}
if (opts.dumpMode != null) {
dumpProfile(info, out, opts.dumpMode);
continue;
}
PhaseSummaryStatistics phaseSummaryStatistics = new PhaseSummaryStatistics(info);
EnumMap<ProfilePhase, PhaseStatistics> phaseStatistics = new EnumMap<>(ProfilePhase.class);
for (ProfilePhase phase : ProfilePhase.values()) {
phaseStatistics.put(phase, new PhaseStatistics(phase, info, env.getWorkspaceName(), opts.vfsStatsLimit > 0));
}
CriticalPathStatistics critPathStats = new CriticalPathStatistics(info);
if (opts.html) {
Path htmlFile = profileFile.getParentDirectory().getChild(profileFile.getBaseName() + ".html");
env.getReporter().handle(Event.info("Creating HTML output in " + htmlFile));
HtmlCreator.create(info, htmlFile, phaseSummaryStatistics, phaseStatistics, critPathStats, info.getMissingActionsCount(), opts.htmlDetails, opts.htmlPixelsPerSecond, opts.vfsStatsLimit, opts.chart, opts.htmlHistograms);
} else {
new PhaseText(out, phaseSummaryStatistics, phaseStatistics, Optional.of(critPathStats), info.getMissingActionsCount(), opts.vfsStatsLimit).print();
}
} catch (IOException e) {
System.out.println(e);
env.getReporter().handle(Event.error("Failed to analyze profile file(s): " + e.getMessage()));
}
}
}
}
return ExitCode.SUCCESS;
}
use of com.google.devtools.build.lib.profiler.ProfilePhase in project bazel by bazelbuild.
the class MultiProfileStatistics method loadProfileFile.
/**
* Loads a single profile file and adds the statistics to the previously collected ones.
*/
private void loadProfileFile(Path workingDirectory, String workSpaceName, String file, InfoListener listener) {
ProfileInfo info;
Path profileFile = workingDirectory.getRelative(file);
try {
info = ProfileInfo.loadProfileVerbosely(profileFile, listener);
ProfileInfo.aggregateProfile(info, listener);
} catch (IOException e) {
listener.warn("Ignoring file " + file + " - cannot load: " + e.getMessage());
return;
}
summaryStatistics.addProfileInfo(info);
EnumMap<ProfilePhase, PhaseStatistics> fileStatistics = new EnumMap<>(ProfilePhase.class);
filePhaseStatistics.put(profileFile, fileStatistics);
for (ProfilePhase phase : ProfilePhase.values()) {
PhaseStatistics filePhaseStat = new PhaseStatistics(phase, info, workSpaceName, generateVfsStatistics);
fileStatistics.put(phase, filePhaseStat);
PhaseStatistics summaryPhaseStats;
if (summaryPhaseStatistics.containsKey(phase)) {
summaryPhaseStats = summaryPhaseStatistics.get(phase);
} else {
summaryPhaseStats = new PhaseStatistics(phase, generateVfsStatistics);
summaryPhaseStatistics.put(phase, summaryPhaseStats);
}
summaryPhaseStats.add(filePhaseStat);
}
skylarkStatistics.addProfileInfo(info);
missingActionsCount += info.getMissingActionsCount();
}
Aggregations