blob: 00e2557351766f42a4c5845cf411113f6f80b3bf [file] [log] [blame]
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01001// Copyright 2014 Google Inc. All rights reserved.
2//
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),
57 VFS_STAT("VFS stat", 10000000, 0x9999FF, 30),
58 VFS_DIR("VFS readdir", 10000000, 0x0066CC, 30),
Han-Wen Nienhuys14c542c2015-03-12 15:09:42 +000059 VFS_READLINK("VFS readlink", 10000000, 0x99CCCC, 30),
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060 VFS_MD5("VFS md5", 10000000, 0x999999, 30),
61 VFS_XATTR("VFS xattr", 10000000, 0x9999DD, 30),
62 VFS_DELETE("VFS delete", 10000000, 0xFFCC00, 0),
63 VFS_OPEN("VFS open", 10000000, 0x009999, 30),
64 VFS_READ("VFS read", 10000000, 0x99CC33, 30),
65 VFS_WRITE("VFS write", 10000000, 0xFF9900, 30),
66 VFS_GLOB("globbing", -1, 0x999966, 30),
67 VFS_VMFS_STAT("VMFS stat", 10000000, 0x9999FF, 0),
68 VFS_VMFS_DIR("VMFS readdir", 10000000, 0x0066CC, 0),
69 VFS_VMFS_READ("VMFS read", 10000000, 0x99CC33, 0),
70 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),
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010092 UNKNOWN("Unknown event", -1, 0x339966, 0);
93
94 // Size of the ProfilerTask value space.
95 public static final int TASK_COUNT = ProfilerTask.values().length;
96
97 /** Human readable description for the task. */
98 public final String description;
99 /** Threshold for skipping tasks in the profile in nanoseconds, unless --record_full_profiler_data
100 * is used */
101 public final long minDuration;
102 /** Default color of the task, when rendered in a chart. */
103 public final int color;
104 /** How many of the slowest instances to keep. If 0, no slowest instance calculation is done. */
105 public final int slowestInstancesCount;
106
107 ProfilerTask(String description, long minDuration, int color, int slowestInstanceCount) {
108 this.description = description;
109 this.minDuration = minDuration;
110 this.color = color;
111 this.slowestInstancesCount = slowestInstanceCount;
112 }
113
Janak Ramakrishnan42a68302015-06-18 19:55:31 +0000114 ProfilerTask(String description) {
115 this(description, -1, 0x000000, 0);
116 }
117
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100118 /** Whether the Profiler collects the slowest instances of this task. */
119 public boolean collectsSlowestInstances() {
120 return slowestInstancesCount > 0;
121 }
Klaas Boesche6bd4f2d2015-09-22 11:29:47 +0000122
123 /**
124 * Build a set containing all ProfilerTasks for which the given predicate is true.
125 */
126 public static EnumSet<ProfilerTask> allSatisfying(Predicate<ProfilerTask> predicate) {
127 EnumSet<ProfilerTask> set = EnumSet.noneOf(ProfilerTask.class);
128 for (ProfilerTask taskType : values()) {
129 if (predicate.apply(taskType)) {
130 set.add(taskType);
131 }
132 }
133 return set;
134 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100135}