summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/extras/chrome/chrome_user_friendly_category_driver.html
blob: 6c046e34b182d5a52b036e48c888b050820b1f1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/event.html">
<link rel="import" href="/tracing/base/sinebow_color_generator.html">
<link rel="import" href="/tracing/base/utils.html">

<script>
'use strict';

tr.exportTo('tr.e.chrome', function() {
  const SAME_AS_PARENT = 'same-as-parent';

  const TITLES_FOR_USER_FRIENDLY_CATEGORY = {
    composite: [
      'CompositingInputsUpdater::update',
      'ThreadProxy::SetNeedsUpdateLayers',
      'LayerTreeHost::DoUpdateLayers',
      'LayerTreeHost::UpdateLayers::BuildPropertyTrees',
      'LocalFrameView::pushPaintArtifactToCompositor',
      'LocalFrameView::updateCompositedSelectionIfNeeded',
      'LocalFrameView::RunCompositingLifecyclePhase',
      'UpdateLayerTree',
    ],

    gc: [
      'minorGC',
      'majorGC',
      'MajorGC',
      'MinorGC',
      'V8.GCScavenger',
      'V8.GCIncrementalMarking',
      'V8.GCIdleNotification',
      'V8.GCContext',
      'V8.GCCompactor',
      'V8GCController::traceDOMWrappers',
    ],

    iframe_creation: [
      'WebLocalFrameImpl::createChildframe',
    ],

    imageDecode: [
      'Decode Image',
      'ImageFrameGenerator::decode',
      'ImageFrameGenerator::decodeAndScale',
      'ImageFrameGenerator::decodeToYUV',
      'ImageResourceContent::updateImage',
    ],

    input: [
      'HitTest',
      'ScrollableArea::scrollPositionChanged',
      'EventHandler::handleMouseMoveEvent',
    ],

    layout: [
      'IntersectionObserverController::computeTrackedIntersectionObservations',
      'LocalFrameView::invalidateTree',
      'LocalFrameView::layout',
      'LocalFrameView::performLayout',
      'LocalFrameView::performPostLayoutTasks',
      'LocalFrameView::performPreLayoutTasks',
      'LocalFrameView::RunStyleAndLayoutCompositingPhases',
      'Layout',
      'PaintLayer::updateLayerPositionsAfterLayout',
      'ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities',
      'WebViewImpl::updateAllLifecyclePhases',
      'WebViewImpl::beginFrame',
    ],

    parseHTML: [
      'BackgroundHTMLParser::pumpTokenizer',
      'BackgroundHTMLParser::sendTokensToMainThread',
      'HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser',
      'HTMLDocumentParser::documentElementAvailable',
      'HTMLDocumentParser::notifyPendingTokenizedChunks',
      'HTMLDocumentParser::processParsedChunkFromBackgroundParser',
      'HTMLDocumentParser::processTokenizedChunkFromBackgroundParser',
      'ParseHTML',
    ],

    raster: [
      'DisplayListRasterSource::PerformSolidColorAnalysis',
      'Picture::Raster',
      'RasterBufferImpl::Playback',
      'RasterTask',
      'RasterizerTaskImpl::RunOnWorkerThread',
      'SkCanvas::drawImageRect()',
      'SkCanvas::drawPicture()',
      'SkCanvas::drawTextBlob()',
      'TileTaskWorkerPool::PlaybackToMemory',
    ],

    record: [
      'Canvas2DLayerBridge::flushRecordingOnly',
      'CompositingInputsUpdater::update',
      'CompositingRequirementsUpdater::updateRecursive',
      'ContentLayerDelegate::paintContents',
      'DisplayItemList::Finalize',
      'LocalFrameView::RunPaintLifecyclePhase',
      'LocalFrameView::RunPrePaintLifecyclePhase',
      'Paint',
      'PaintController::commitNewDisplayItems',
      'PaintLayerCompositor::updateIfNeededRecursive',
      'Picture::Record',
      'PictureLayer::Update',
    ],

    style: [
      'CSSParserImpl::parseStyleSheet.parse',
      'CSSParserImpl::parseStyleSheet.tokenize',
      'Document::rebuildLayoutTree',
      'Document::recalcStyle',
      'Document::updateActiveStyle',
      'Document::updateStyle',
      'Document::updateStyleInvalidationIfNeeded',
      'LocalFrameView::updateStyleAndLayoutIfNeededRecursive',
      'ParseAuthorStyleSheet',
      'RuleSet::addRulesFromSheet',
      'StyleElement::processStyleSheet',
      'StyleEngine::createResolver',
      'StyleEngine::updateActiveStyleSheets',
      'StyleSheetContents::parseAuthorStyleSheet',
      'UpdateLayoutTree',
    ],

    script_parse_and_compile: [
      'V8.CompileFullCode',
      'V8.NewContext',
      'V8.Parse',
      'V8.ParseLazy',
      'V8.RecompileSynchronous',
      'V8.ScriptCompiler',
      'v8.compile',
      'v8.parseOnBackground',
    ],

    script_execute: [
      'EvaluateScript',
      'FunctionCall',
      'HTMLParserScriptRunner ExecuteScript',
      'V8.Execute',
      'V8.RunMicrotasks',
      'V8.Task',
      'WindowProxy::initialize',
      'v8.callFunction',
      'v8.run',
    ],

    resource_loading: [
      'RenderFrameImpl::didFinishDocumentLoad',
      'RenderFrameImpl::didFinishLoad',
      'Resource::appendData',
      'ResourceDispatcher::OnReceivedData',
      'ResourceDispatcher::OnReceivedResponse',
      'ResourceDispatcher::OnRequestComplete',
      'ResourceFetcher::requestResource',
      'WebURLLoaderImpl::Context::Cancel',
      'WebURLLoaderImpl::Context::OnCompletedRequest',
      'WebURLLoaderImpl::Context::OnReceivedData',
      'WebURLLoaderImpl::Context::OnReceivedRedirect',
      'WebURLLoaderImpl::Context::OnReceivedResponse',
      'WebURLLoaderImpl::Context::Start',
      'WebURLLoaderImpl::loadAsynchronously',
      'WebURLLoaderImpl::loadSynchronously',
      'content::mojom::URLLoaderClient',
    ],

    // Where do these go?
    renderer_misc: [
      'DecodeFont',
      'ThreadState::completeSweep',  // blink_gc
    ],

    // TODO(fmeawad): https://github.com/catapult-project/catapult/issues/2572
    v8_runtime: [
      // Dynamically populated.
    ],

    [SAME_AS_PARENT]: [
      'SyncChannel::Send',
    ]
  };

  const COLOR_FOR_USER_FRIENDLY_CATEGORY = new tr.b.SinebowColorGenerator();
  const USER_FRIENDLY_CATEGORY_FOR_TITLE = new Map();

  for (const category in TITLES_FOR_USER_FRIENDLY_CATEGORY) {
    TITLES_FOR_USER_FRIENDLY_CATEGORY[category].forEach(function(title) {
      USER_FRIENDLY_CATEGORY_FOR_TITLE.set(title, category);
    });
  }

  // keys: event.category part
  // values: user friendly category
  const USER_FRIENDLY_CATEGORY_FOR_EVENT_CATEGORY = {
    netlog: 'net',
    overhead: 'overhead',
    startup: 'startup',
    gpu: 'gpu',
  };

  function ChromeUserFriendlyCategoryDriver() {
  }

  ChromeUserFriendlyCategoryDriver.fromEvent = function(event) {
    let userFriendlyCategory =
        USER_FRIENDLY_CATEGORY_FOR_TITLE.get(event.title);
    if (userFriendlyCategory) {
      if (userFriendlyCategory === SAME_AS_PARENT) {
        if (event.parentSlice) {
          return ChromeUserFriendlyCategoryDriver.fromEvent(event.parentSlice);
        }
      } else {
        return userFriendlyCategory;
      }
    }

    const eventCategoryParts = tr.b.getCategoryParts(event.category);
    for (let i = 0; i < eventCategoryParts.length; ++i) {
      const eventCategory = eventCategoryParts[i];
      userFriendlyCategory = USER_FRIENDLY_CATEGORY_FOR_EVENT_CATEGORY[
          eventCategory];
      if (userFriendlyCategory) {
        return userFriendlyCategory;
      }
    }

    return 'other';
  };

  ChromeUserFriendlyCategoryDriver.getColor = function(ufc) {
    return COLOR_FOR_USER_FRIENDLY_CATEGORY.colorForKey(ufc);
  };

  ChromeUserFriendlyCategoryDriver.ALL_TITLES = ['other'];
  for (const category in TITLES_FOR_USER_FRIENDLY_CATEGORY) {
    if (category === SAME_AS_PARENT) continue;
    ChromeUserFriendlyCategoryDriver.ALL_TITLES.push(category);
  }
  for (const category of Object.values(
      USER_FRIENDLY_CATEGORY_FOR_EVENT_CATEGORY)) {
    ChromeUserFriendlyCategoryDriver.ALL_TITLES.push(category);
  }
  ChromeUserFriendlyCategoryDriver.ALL_TITLES.sort();

  // Prime the color generator by iterating through all UFCs in alphabetical
  // order.
  for (const category of ChromeUserFriendlyCategoryDriver.ALL_TITLES) {
    ChromeUserFriendlyCategoryDriver.getColor(category);
  }

  return {
    ChromeUserFriendlyCategoryDriver,
  };
});
</script>