Search in sources :

Example 1 with PhaseStatistics

use of com.google.devtools.build.lib.profiler.statistics.PhaseStatistics in project bazel by bazelbuild.

the class PhaseText method printExecutionPhaseStatistics.

private void printExecutionPhaseStatistics() {
    PhaseStatistics prepPhase = phaseStatistics.get(ProfilePhase.PREPARE);
    PhaseStatistics execPhase = phaseStatistics.get(ProfilePhase.EXECUTE);
    PhaseStatistics finishPhase = phaseStatistics.get(ProfilePhase.FINISH);
    if (!execPhase.wasExecuted()) {
        return;
    }
    lnPrint("=== EXECUTION PHASE INFORMATION ===\n");
    long graphTime = execPhase.getTotalDurationNanos(ProfilerTask.ACTION_GRAPH);
    long execTime = execPhase.getPhaseDurationNanos() - graphTime;
    if (prepPhase.wasExecuted()) {
        lnPrintf(TWO_COLUMN_FORMAT, "Total preparation time", TimeUtilities.prettyTime(prepPhase.getPhaseDurationNanos()));
    }
    lnPrintf(TWO_COLUMN_FORMAT, "Total execution phase time", TimeUtilities.prettyTime(execPhase.getPhaseDurationNanos()));
    if (finishPhase.wasExecuted()) {
        lnPrintf(TWO_COLUMN_FORMAT, "Total time finalizing build", TimeUtilities.prettyTime(finishPhase.getPhaseDurationNanos()));
    }
    printLn();
    lnPrintf(TWO_COLUMN_FORMAT, "Action dependency map creation", TimeUtilities.prettyTime(graphTime));
    lnPrintf(TWO_COLUMN_FORMAT, "Actual execution time", TimeUtilities.prettyTime(execTime));
    CriticalPathText criticalPaths = null;
    if (criticalPathStatistics.isPresent()) {
        criticalPaths = new CriticalPathText(out, criticalPathStatistics.get(), execTime);
        criticalPaths.printTimingBreakdown();
        printLn();
    }
    printTimingDistribution(execPhase);
    printLn();
    if (criticalPathStatistics.isPresent()) {
        criticalPaths.printCriticalPaths();
        printLn();
    }
    if (missingActionsCount > 0) {
        lnPrint(missingActionsCount);
        print(" action(s) are present in the" + " action graph but missing instrumentation data. Most likely the profile file" + " has been created during a failed or aborted build.");
        printLn();
    }
    printVfsStatistics(execPhase.getVfsStatistics());
}
Also used : PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics)

Example 2 with PhaseStatistics

use of com.google.devtools.build.lib.profiler.statistics.PhaseStatistics 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();
}
Also used : ProfilePhase(com.google.devtools.build.lib.profiler.ProfilePhase) PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics)

Example 3 with PhaseStatistics

use of com.google.devtools.build.lib.profiler.statistics.PhaseStatistics 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;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PrintStream(java.io.PrintStream) PhaseText(com.google.devtools.build.lib.profiler.output.PhaseText) MultiProfileStatistics(com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics) IOException(java.io.IOException) ProfileInfo(com.google.devtools.build.lib.profiler.ProfileInfo) PhaseSummaryStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseSummaryStatistics) ProfilePhase(com.google.devtools.build.lib.profiler.ProfilePhase) PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics) BufferedOutputStream(java.io.BufferedOutputStream) EnumMap(java.util.EnumMap) CriticalPathStatistics(com.google.devtools.build.lib.profiler.statistics.CriticalPathStatistics)

Example 4 with PhaseStatistics

use of com.google.devtools.build.lib.profiler.statistics.PhaseStatistics in project bazel by bazelbuild.

the class MultiProfilePhaseHtml method printVisualizationCallbackJs.

/**
   * 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%%'});");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ProfilerTask(com.google.devtools.build.lib.profiler.ProfilerTask) ProfilePhase(com.google.devtools.build.lib.profiler.ProfilePhase) PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics)

Example 5 with PhaseStatistics

use of com.google.devtools.build.lib.profiler.statistics.PhaseStatistics in project bazel by bazelbuild.

the class PhaseHtml method printExecutionPhaseStatistics.

private void printExecutionPhaseStatistics() {
    PhaseStatistics execPhase = phaseStatistics.get(ProfilePhase.EXECUTE);
    if (execPhase == null || !execPhase.wasExecuted()) {
        return;
    }
    printPhaseHead(execPhase);
    for (PhaseStatistics phaseStat : Arrays.asList(phaseStatistics.get(ProfilePhase.PREPARE), execPhase, phaseStatistics.get(ProfilePhase.FINISH))) {
        if (phaseStat.wasExecuted()) {
            printTwoColumnStatistic(String.format("Total %s time", phaseStat.getProfilePhase().nick), phaseStat.getPhaseDurationNanos());
        }
    }
    long graphTime = execPhase.getTotalDurationNanos(ProfilerTask.ACTION_GRAPH);
    long execTime = execPhase.getPhaseDurationNanos() - graphTime;
    printTwoColumnStatistic("Action dependency map creation", graphTime);
    printTwoColumnStatistic("Actual execution time", execTime);
    CriticalPathHtml criticalPaths = null;
    if (criticalPathStatistics.isPresent()) {
        criticalPaths = new CriticalPathHtml(out, criticalPathStatistics.get(), execTime);
        criticalPaths.printTimingBreakdown();
    }
    printTimingDistribution(execPhase);
    // table opened by printPhaseHead
    lnClose();
    if (criticalPathStatistics.isPresent()) {
        criticalPaths.printCriticalPaths();
    }
    if (missingActionsCount.isPresent() && missingActionsCount.get() > 0) {
        lnOpen("p");
        lnPrint(missingActionsCount.get());
        print(" action(s) are present in the" + " action graph but missing instrumentation data. Most likely the profile file" + " has been created during a failed or aborted build.");
        lnClose();
    }
    printVfsStatistics(execPhase.getVfsStatistics());
    // div
    lnClose();
}
Also used : PhaseStatistics(com.google.devtools.build.lib.profiler.statistics.PhaseStatistics)

Aggregations

PhaseStatistics (com.google.devtools.build.lib.profiler.statistics.PhaseStatistics)6 ProfilePhase (com.google.devtools.build.lib.profiler.ProfilePhase)4 Path (com.google.devtools.build.lib.vfs.Path)2 ProfileInfo (com.google.devtools.build.lib.profiler.ProfileInfo)1 ProfilerTask (com.google.devtools.build.lib.profiler.ProfilerTask)1 PhaseText (com.google.devtools.build.lib.profiler.output.PhaseText)1 CriticalPathStatistics (com.google.devtools.build.lib.profiler.statistics.CriticalPathStatistics)1 MultiProfileStatistics (com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics)1 PhaseSummaryStatistics (com.google.devtools.build.lib.profiler.statistics.PhaseSummaryStatistics)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 EnumMap (java.util.EnumMap)1