use of com.google.devtools.build.lib.profiler.ProfileInfo.Task 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);
}
}
use of com.google.devtools.build.lib.profiler.ProfileInfo.Task in project bazel by bazelbuild.
the class DetailedChartCreator method create.
@Override
public Chart create() {
Chart chart = new Chart();
CommonChartCreator.createCommonChartItems(chart, info);
createTypes(chart);
// calculate the critical path
EnumSet<ProfilerTask> typeFilter = EnumSet.noneOf(ProfilerTask.class);
CriticalPathEntry criticalPath = info.getCriticalPath(typeFilter);
info.analyzeCriticalPath(typeFilter, criticalPath);
for (Task task : info.allTasksById) {
String label = task.type.description + ": " + task.getDescription();
ChartBarType type = chart.lookUpType(task.type.description);
long stop = task.startTime + task.durationNanos;
CriticalPathEntry entry = null;
// for top level tasks, check if they are on the critical path
if (task.parentId == 0 && criticalPath != null) {
entry = info.getNextCriticalPathEntryForTask(criticalPath, task);
// find next top-level entry
if (entry != null) {
CriticalPathEntry nextEntry = entry.next;
while (nextEntry != null && nextEntry.task.parentId != 0) {
nextEntry = nextEntry.next;
}
if (nextEntry != null) {
// time is start and not stop as we traverse the critical back backwards
chart.addVerticalLine(task.threadId, nextEntry.task.threadId, task.startTime);
}
}
}
chart.addBar(task.threadId, task.startTime, stop, type, (entry != null), label);
}
return chart;
}
use of com.google.devtools.build.lib.profiler.ProfileInfo.Task in project bazel by bazelbuild.
the class SkylarkStatistics method addDurations.
/**
* Add all new durations to previously collected durations for all functions mapped to tasks.
* @return The sum of the execution times of all {@link Task} values in the map.
*/
private static long addDurations(Multimap<String, Task> functionTasks, Map<String, LongArrayList> durationsMap, Map<String, LongArrayList> selfDurationsMap) {
long totalTime = 0;
for (Entry<String, Collection<Task>> entry : functionTasks.asMap().entrySet()) {
String function = entry.getKey();
Collection<Task> tasks = entry.getValue();
LongArrayList durations;
LongArrayList selfDurations;
if (durationsMap.containsKey(function)) {
durations = durationsMap.get(function);
selfDurations = selfDurationsMap.get(function);
} else {
durations = new LongArrayList(tasks.size());
selfDurations = new LongArrayList(tasks.size());
durationsMap.put(function, durations);
selfDurationsMap.put(function, selfDurations);
}
totalTime += addDurations(tasks, durations, selfDurations);
}
return totalTime;
}
use of com.google.devtools.build.lib.profiler.ProfileInfo.Task in project bazel by bazelbuild.
the class ProfileCommand method printTaskTree.
/**
* Prints trees rooted at tasks with a description matching a pattern.
* @see Task#printTaskTree(PrintStream, long)
*/
private void printTaskTree(PrintStream out, String fileName, ProfileInfo info, Pattern taskPattern, long taskDurationThreshold) {
Iterable<Task> tasks = info.findTasksByDescription(taskPattern);
if (Iterables.isEmpty(tasks)) {
out.printf("No tasks matching %s found in profile file %s.", taskPattern, fileName);
out.println();
} else {
int skipped = 0;
for (Task task : tasks) {
if (!task.printTaskTree(out, taskDurationThreshold)) {
skipped++;
}
}
if (skipped > 0) {
out.printf("Skipped %d matching task(s) below the duration threshold.", skipped);
}
out.println();
}
}
Aggregations