use of com.google.devtools.build.lib.profiler.ProfilerTask in project bazel by bazelbuild.
the class PhaseStatistics method addProfileInfo.
/**
* Add statistics from {@link ProfileInfo} to the ones already accumulated for this phase.
*/
public void addProfileInfo(String workSpaceName, ProfileInfo info) {
Task phaseTask = info.getPhaseTask(phase);
if (phaseTask != null) {
if (vfsStatistics != null) {
vfsStatistics.addProfileInfo(workSpaceName, info);
}
wasExecuted = true;
long infoPhaseDuration = info.getPhaseDuration(phaseTask);
phaseDurationNanos += infoPhaseDuration;
List<Task> taskList = info.getTasksForPhase(phaseTask);
long duration = infoPhaseDuration;
for (Task task : taskList) {
// Tasks on the phaseTask thread already accounted for in the phaseDuration.
if (task.threadId != phaseTask.threadId) {
duration += task.durationNanos;
}
}
totalDurationNanos += duration;
for (ProfilerTask type : ProfilerTask.values()) {
AggregateAttr attr = info.getStatsForType(type, taskList);
long totalTime = Math.max(0, attr.totalTime);
long count = Math.max(0, attr.count);
add(taskCounts, type, count);
add(taskDurations, type, totalTime);
}
}
}
use of com.google.devtools.build.lib.profiler.ProfilerTask in project bazel by bazelbuild.
the class PhaseStatistics method add.
/**
* Add statistics accumulated in another PhaseStatistics object to this one.
*/
public void add(PhaseStatistics other) {
Preconditions.checkArgument(phase == other.phase, "Should not combine statistics from different phases");
if (other.wasExecuted) {
if (vfsStatistics != null && other.vfsStatistics != null) {
vfsStatistics.add(other.vfsStatistics);
}
wasExecuted = true;
phaseDurationNanos += other.phaseDurationNanos;
totalDurationNanos += other.totalDurationNanos;
for (ProfilerTask type : other) {
long otherCount = other.getCount(type);
long otherDuration = other.getTotalDurationNanos(type);
add(taskCounts, type, otherCount);
add(taskDurations, type, otherDuration);
}
}
}
use of com.google.devtools.build.lib.profiler.ProfilerTask in project bazel by bazelbuild.
the class PhaseHtml method printVfsStatistics.
/**
* Print the time spent on VFS operations on each path. Output is grouped by operation and sorted
* by descending duration. If multiple of the same VFS operation were logged for the same path,
* print the total duration.
*/
private void printVfsStatistics(@Nullable PhaseVfsStatistics stats) {
if (vfsStatsLimit == 0 || stats == null || stats.isEmpty()) {
return;
}
lnElement("h4", "VFS path statistics:");
lnOpen("table", "class", "phase-statistics");
lnOpen("tr");
element("td", "Type");
element("td", "Frequency");
element("td", "Duration");
element("td", "class", "left", "Path");
// tr
close();
for (ProfilerTask type : stats) {
int numPrinted = 0;
for (Stat stat : stats.getSortedStatistics(type)) {
lnOpen("tr");
if (vfsStatsLimit != -1 && numPrinted++ == vfsStatsLimit) {
open("td", "class", "center", "colspan", "4");
printf("... %d more ...", stats.getStatisticsCount(type) - vfsStatsLimit);
close();
// tr
close();
break;
}
element("td", type.name());
element("td", stat.getCount());
element("td", TimeUtilities.prettyTime(stat.getDuration()));
element("td", "class", "left", stat.path);
// tr
close();
}
}
// table
lnClose();
}
use of com.google.devtools.build.lib.profiler.ProfilerTask in project bazel by bazelbuild.
the class PhaseText method printVfsStatistics.
/**
* Print the time spent on VFS operations on each path. Output is grouped by operation and
* sorted by descending duration. If multiple of the same VFS operation were logged for the same
* path, print the total duration.
*/
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)) {
if (vfsStatsLimit != -1 && numPrinted++ == vfsStatsLimit) {
lnPrintf("... %d more ...", stats.getStatisticsCount(type) - vfsStatsLimit);
break;
}
lnPrintf("%15s %10d %10s %s", type.name(), stat.getCount(), TimeUtilities.prettyTime(stat.getDuration()), stat.path);
}
}
printLn();
}
use of com.google.devtools.build.lib.profiler.ProfilerTask in project bazel by bazelbuild.
the class ProfileCommand method dumpTask.
/**
* Dumps the task information and all subtasks.
*/
private void dumpTask(ProfileInfo.Task task, PrintStream out, int indent) {
StringBuilder builder = new StringBuilder(String.format(Joiner.on('\n').join("", "%s %s", "Thread: %-6d Id: %-6d Parent: %d", "Start time: %-12s Duration: %s"), task.type, task.getDescription(), task.threadId, task.id, task.parentId, TimeUtilities.prettyTime(task.startTime), TimeUtilities.prettyTime(task.durationNanos)));
if (task.hasStats()) {
builder.append("\n");
ProfileInfo.AggregateAttr[] stats = task.getStatAttrArray();
for (ProfilerTask type : ProfilerTask.values()) {
ProfileInfo.AggregateAttr attr = stats[type.ordinal()];
if (attr != null) {
builder.append(type.toString().toLowerCase()).append("=(").append(attr.count).append(", ").append(TimeUtilities.prettyTime(attr.totalTime)).append(") ");
}
}
}
out.println(StringUtil.indent(builder.toString(), indent));
for (ProfileInfo.Task subtask : task.subtasks) {
dumpTask(subtask, out, indent + 1);
}
}
Aggregations