blob: 6fe3f7344697b32db9e527116036bf3ec06f3d96 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.profiler;
15
Klaas Boesche6bd4f2d2015-09-22 11:29:47 +000016import com.google.common.base.Predicate;
17
18import java.util.EnumSet;
19
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010020/**
21 * All possible types of profiler tasks. Each type also defines description and
22 * minimum duration in nanoseconds for it to be recorded as separate event and
23 * not just be aggregated into the parent event.
24 */
25public enum ProfilerTask {
26 /* WARNING:
27 * Add new Tasks at the end (before Unknown) to not break the profiles that people have created!
28 * The profile file format uses the ordinal() of this enumeration to identify the task.
29 */
30 PHASE("build phase marker", -1, 0x336699, 0),
31 ACTION("action processing", -1, 0x666699, 0),
32 ACTION_BUILDER("parallel builder completion queue", -1, 0xCC3399, 0),
33 ACTION_SUBMIT("execution queue submission", -1, 0xCC3399, 0),
34 ACTION_CHECK("action dependency checking", 10000000, 0x999933, 0),
35 ACTION_EXECUTE("action execution", -1, 0x99CCFF, 0),
36 ACTION_LOCK("action resource lock", 10000000, 0xCC9933, 0),
37 ACTION_RELEASE("action resource release", 10000000, 0x006666, 0),
38 ACTION_GRAPH("action graph dependency", -1, 0x3399FF, 0),
39 ACTION_UPDATE("update action information", 10000000, 0x993300, 0),
40 ACTION_COMPLETE("complete action execution", -1, 0xCCCC99, 0),
41 INFO("general information", -1, 0x000066, 0),
42 EXCEPTION("exception", -1, 0xFFCC66, 0),
43 CREATE_PACKAGE("package creation", -1, 0x6699CC, 0),
44 PACKAGE_VALIDITY_CHECK("package validity check", -1, 0x336699, 0),
45 SPAWN("local process spawn", -1, 0x663366, 0),
46 REMOTE_EXECUTION("remote action execution", -1, 0x9999CC, 0),
47 LOCAL_EXECUTION("local action execution", -1, 0xCCCCCC, 0),
48 SCANNER("include scanner", -1, 0x669999, 0),
49 // 30 is a good number because the slowest items are stored in a heap, with temporarily
50 // one more element, and with 31 items, a heap becomes a complete binary tree
51 LOCAL_PARSE("Local parse to prepare for remote execution", 50000000, 0x6699CC, 30),
52 UPLOAD_TIME("Remote execution upload time", 50000000, 0x6699CC, 0),
53 PROCESS_TIME("Remote execution process wall time", 50000000, 0xF999CC, 0),
54 REMOTE_QUEUE("Remote execution queuing time", 50000000, 0xCC6600, 0),
55 REMOTE_SETUP("Remote execution setup", 50000000, 0xA999CC, 0),
56 FETCH("Remote execution file fetching", 50000000, 0xBB99CC, 0),
Miguel Alcon Pinto5f048972015-11-19 13:43:09 +000057 VFS_STAT("VFS stat", 10000000, 0x9999FF, 30, true),
58 VFS_DIR("VFS readdir", 10000000, 0x0066CC, 30, true),
59 VFS_READLINK("VFS readlink", 10000000, 0x99CCCC, 30, true),
60 VFS_MD5("VFS md5", 10000000, 0x999999, 30, true),
61 VFS_XATTR("VFS xattr", 10000000, 0x9999DD, 30, true),
62 VFS_DELETE("VFS delete", 10000000, 0xFFCC00, 0, true),
63 VFS_OPEN("VFS open", 10000000, 0x009999, 30, true),
64 VFS_READ("VFS read", 10000000, 0x99CC33, 30, true),
65 VFS_WRITE("VFS write", 10000000, 0xFF9900, 30, true),
66 VFS_GLOB("globbing", -1, 0x999966, 30, true),
67 VFS_VMFS_STAT("VMFS stat", 10000000, 0x9999FF, 0, true),
68 VFS_VMFS_DIR("VMFS readdir", 10000000, 0x0066CC, 0, true),
69 VFS_VMFS_READ("VMFS read", 10000000, 0x99CC33, 0, true),
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010070 WAIT("thread wait", 5000000, 0x66CCCC, 0),
71 CONFIGURED_TARGET("configured target creation", -1, 0x663300, 0),
72 TRANSITIVE_CLOSURE("transitive closure creation", -1, 0x996600, 0),
73 TEST("for testing only", -1, 0x000000, 0),
74 SKYFRAME_EVAL("skyframe evaluator", -1, 0xCC9900, 0),
75 SKYFUNCTION("skyfunction", -1, 0xCC6600, 0),
76 CRITICAL_PATH("critical path", -1, 0x666699, 0),
77 CRITICAL_PATH_COMPONENT("critical path component", -1, 0x666699, 0),
78 IDE_BUILD_INFO("ide_build_info", -1, 0xCC6633, 0),
Googler27efc622015-05-28 16:28:01 +000079 HANDLE_GC_NOTIFICATION("gc notification", -1, 0x996633, 0),
Janak Ramakrishnan42a68302015-06-18 19:55:31 +000080 INCLUSION_LOOKUP("inclusion lookup", -1, 0x000000, 0),
81 INCLUSION_PARSE("inclusion parse", -1, 0x000000, 0),
82 PROCESS_SCAN("process scan", -1, 0x000000, 0),
83 LOOP_OUTPUT_ARTIFACTS("loop output artifacts"),
84 LOCATE_RELATIVE("locate relative"),
85 CONSTRUCT_INCLUDE_PATHS("construct include paths"),
86 PARSE_AND_HINTS_RESULTS("parse and hints results"),
87 PROCESS_RESULTS_AND_ENQUEUE("process results and enqueue"),
Googler768cbc42015-08-28 12:52:14 +000088 SKYLARK_LEXER("Skylark Lexer"),
89 SKYLARK_PARSER("Skylark Parser"),
90 SKYLARK_USER_FN("Skylark user function call", -1, 0xCC0033, 0),
91 SKYLARK_BUILTIN_FN("Skylark builtin function call", -1, 0x990033, 0),
Florian Weikert6edbf3b2015-11-09 21:33:26 +000092 SKYLARK_USER_COMPILED_FN("Skylark compiled user function call", -1, 0xCC0033, 0),
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010093 UNKNOWN("Unknown event", -1, 0x339966, 0);
94
95 // Size of the ProfilerTask value space.
96 public static final int TASK_COUNT = ProfilerTask.values().length;
97
98 /** Human readable description for the task. */
99 public final String description;
100 /** Threshold for skipping tasks in the profile in nanoseconds, unless --record_full_profiler_data
101 * is used */
102 public final long minDuration;
103 /** Default color of the task, when rendered in a chart. */
104 public final int color;
105 /** How many of the slowest instances to keep. If 0, no slowest instance calculation is done. */
106 public final int slowestInstancesCount;
Miguel Alcon Pinto5f048972015-11-19 13:43:09 +0000107 /** True if the metric records VFS operations */
108 private boolean vfs;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100109
110 ProfilerTask(String description, long minDuration, int color, int slowestInstanceCount) {
Miguel Alcon Pinto5f048972015-11-19 13:43:09 +0000111 this(description, minDuration, color, slowestInstanceCount, /*vfs=*/ false);
112 }
113
114 ProfilerTask(String description, long minDuration, int color, int slowestInstanceCount,
115 boolean vfs) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100116 this.description = description;
117 this.minDuration = minDuration;
118 this.color = color;
119 this.slowestInstancesCount = slowestInstanceCount;
Miguel Alcon Pinto5f048972015-11-19 13:43:09 +0000120 this.vfs = vfs;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100121 }
122
Janak Ramakrishnan42a68302015-06-18 19:55:31 +0000123 ProfilerTask(String description) {
124 this(description, -1, 0x000000, 0);
125 }
126
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100127 /** Whether the Profiler collects the slowest instances of this task. */
128 public boolean collectsSlowestInstances() {
129 return slowestInstancesCount > 0;
130 }
Klaas Boesche6bd4f2d2015-09-22 11:29:47 +0000131
132 /**
133 * Build a set containing all ProfilerTasks for which the given predicate is true.
134 */
135 public static EnumSet<ProfilerTask> allSatisfying(Predicate<ProfilerTask> predicate) {
136 EnumSet<ProfilerTask> set = EnumSet.noneOf(ProfilerTask.class);
137 for (ProfilerTask taskType : values()) {
138 if (predicate.apply(taskType)) {
139 set.add(taskType);
140 }
141 }
142 return set;
143 }
Miguel Alcon Pinto5f048972015-11-19 13:43:09 +0000144
145 public boolean isVfs() {
146 return vfs;
147 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100148}