Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: sdk/lib/developer/timeline.dart

Issue 1966833002: Dart Timeline improvements (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/developer/developer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.developer; 5 part of dart.developer;
6 6
7 const bool _isProduct = const bool.fromEnvironment("dart.vm.product");
8
7 typedef dynamic TimelineSyncFunction(); 9 typedef dynamic TimelineSyncFunction();
8 typedef Future TimelineAsyncFunction(); 10 typedef Future TimelineAsyncFunction();
9 11
10 /// Add to the timeline. 12 /// Add to the timeline.
11 class Timeline { 13 class Timeline {
12 /// Start a synchronous operation labeled [name]. Optionally takes 14 /// Start a synchronous operation labeled [name]. Optionally takes
13 /// a [Map] of [arguments]. This operation must be finished before 15 /// a [Map] of [arguments]. This operation must be finished before
14 /// returning to the event queue. 16 /// returning to the event queue.
15 static void startSync(String name, {Map arguments}) { 17 static void startSync(String name, {Map arguments}) {
18 if (_isProduct) {
19 return;
20 }
16 if (name is! String) { 21 if (name is! String) {
17 throw new ArgumentError.value(name, 22 throw new ArgumentError.value(name,
18 'name', 23 'name',
19 'Must be a String'); 24 'Must be a String');
20 } 25 }
21 var block = new _SyncBlock._(name, _getTraceClock()); 26 var block = new _SyncBlock._(name, _getTraceClock(), _getThreadCpuClock());
22 if (arguments is Map) { 27 if (arguments is Map) {
23 block._appendArguments(arguments); 28 block._appendArguments(arguments);
24 } 29 }
25 _stack.add(block); 30 _stack.add(block);
26 } 31 }
27 32
28 /// Finish the last synchronous operation that was started. 33 /// Finish the last synchronous operation that was started.
29 static void finishSync() { 34 static void finishSync() {
35 if (_isProduct) {
36 return;
37 }
30 if (_stack.length == 0) { 38 if (_stack.length == 0) {
31 throw new StateError( 39 throw new StateError(
32 'Uneven calls to startSync and finishSync'); 40 'Uneven calls to startSync and finishSync');
33 } 41 }
34 // Pop top item off of stack. 42 // Pop top item off of stack.
35 var block = _stack.removeLast(); 43 var block = _stack.removeLast();
36 // Finish it. 44 // Finish it.
37 block.finish(); 45 block.finish();
38 } 46 }
39 47
40 /// Emit an instant event. 48 /// Emit an instant event.
41 static void instantSync(String name, {Map arguments}) { 49 static void instantSync(String name, {Map arguments}) {
50 if (_isProduct) {
51 return;
52 }
42 if (name is! String) { 53 if (name is! String) {
43 throw new ArgumentError.value(name, 54 throw new ArgumentError.value(name,
44 'name', 55 'name',
45 'Must be a String'); 56 'Must be a String');
46 } 57 }
47 Map instantArguments; 58 Map instantArguments;
48 if (arguments is Map) { 59 if (arguments is Map) {
49 instantArguments = new Map.from(arguments); 60 instantArguments = new Map.from(arguments);
50 } 61 }
51 _reportInstantEvent(_getTraceClock(), 62 _reportInstantEvent(_getTraceClock(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (taskId is! int) { 105 if (taskId is! int) {
95 throw new ArgumentError.value(taskId, 106 throw new ArgumentError.value(taskId,
96 'taskId', 107 'taskId',
97 'Must be an int'); 108 'Must be an int');
98 } 109 }
99 } 110 }
100 111
101 /// Start a synchronous operation within this task named [name]. 112 /// Start a synchronous operation within this task named [name].
102 /// Optionally takes a [Map] of [arguments]. 113 /// Optionally takes a [Map] of [arguments].
103 void start(String name, {Map arguments}) { 114 void start(String name, {Map arguments}) {
115 if (_isProduct) {
116 return;
117 }
104 if (name is! String) { 118 if (name is! String) {
105 throw new ArgumentError.value(name, 119 throw new ArgumentError.value(name,
106 'name', 120 'name',
107 'Must be a String'); 121 'Must be a String');
108 } 122 }
109 var block = new _AsyncBlock._(name, _taskId); 123 var block = new _AsyncBlock._(name, _taskId);
110 if (arguments is Map) { 124 if (arguments is Map) {
111 block._appendArguments(arguments); 125 block._appendArguments(arguments);
112 } 126 }
113 _stack.add(block); 127 _stack.add(block);
114 block._start(); 128 block._start();
115 } 129 }
116 130
117 /// Emit an instant event for this task. 131 /// Emit an instant event for this task.
118 void instant(String name, {Map arguments}) { 132 void instant(String name, {Map arguments}) {
133 if (_isProduct) {
134 return;
135 }
119 if (name is! String) { 136 if (name is! String) {
120 throw new ArgumentError.value(name, 137 throw new ArgumentError.value(name,
121 'name', 138 'name',
122 'Must be a String'); 139 'Must be a String');
123 } 140 }
124 Map instantArguments; 141 Map instantArguments;
125 if (arguments is Map) { 142 if (arguments is Map) {
126 instantArguments = new Map.from(arguments); 143 instantArguments = new Map.from(arguments);
127 } 144 }
128 _reportTaskEvent(_getTraceClock(), 145 _reportTaskEvent(_getTraceClock(),
129 _taskId, 146 _taskId,
130 'n', 147 'n',
131 'Dart', 148 'Dart',
132 name, 149 name,
133 _argumentsAsJson(instantArguments)); 150 _argumentsAsJson(instantArguments));
134 } 151 }
135 152
136 /// Finish the last synchronous operation that was started. 153 /// Finish the last synchronous operation that was started.
137 void finish() { 154 void finish() {
155 if (_isProduct) {
156 return;
157 }
138 if (_stack.length == 0) { 158 if (_stack.length == 0) {
139 throw new StateError( 159 throw new StateError(
140 'Uneven calls to start and finish'); 160 'Uneven calls to start and finish');
141 } 161 }
142 // Pop top item off of stack. 162 // Pop top item off of stack.
143 var block = _stack.removeLast(); 163 var block = _stack.removeLast();
144 block._finish(); 164 block._finish();
145 } 165 }
146 166
147 /// Retrieve the [TimelineTask]'s task id. Will throw an exception if the 167 /// Retrieve the [TimelineTask]'s task id. Will throw an exception if the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 class _SyncBlock { 228 class _SyncBlock {
209 /// The category this block belongs to. 229 /// The category this block belongs to.
210 final String category = 'Dart'; 230 final String category = 'Dart';
211 /// The name of this block. 231 /// The name of this block.
212 final String name; 232 final String name;
213 /// An (optional) set of arguments which will be serialized to JSON and 233 /// An (optional) set of arguments which will be serialized to JSON and
214 /// associated with this block. 234 /// associated with this block.
215 Map _arguments; 235 Map _arguments;
216 // The start time stamp. 236 // The start time stamp.
217 final int _start; 237 final int _start;
238 // The start time stamp of the thread cpu clock.
239 final int _startCpu;
218 240
219 _SyncBlock._(this.name, 241 _SyncBlock._(this.name,
220 this._start); 242 this._start,
243 this._startCpu);
221 244
222 /// Finish this block of time. At this point, this block can no longer be 245 /// Finish this block of time. At this point, this block can no longer be
223 /// used. 246 /// used.
224 void finish() { 247 void finish() {
225 // Report event to runtime. 248 // Report event to runtime.
226 _reportCompleteEvent(_start, 249 _reportCompleteEvent(_start,
227 _getTraceClock(), 250 _startCpu,
228 category, 251 category,
229 name, 252 name,
230 _argumentsAsJson(_arguments)); 253 _argumentsAsJson(_arguments));
231 } 254 }
232 255
233 void _appendArguments(Map arguments) { 256 void _appendArguments(Map arguments) {
234 if (arguments == null) { 257 if (arguments == null) {
235 return; 258 return;
236 } 259 }
237 if (_arguments == null) { 260 if (_arguments == null) {
(...skipping 16 matching lines...) Expand all
254 arguments['isolateNumber'] = Timeline._isolateIdString; 277 arguments['isolateNumber'] = Timeline._isolateIdString;
255 return JSON.encode(arguments); 278 return JSON.encode(arguments);
256 } 279 }
257 280
258 /// Returns the next async task id. 281 /// Returns the next async task id.
259 external int _getNextAsyncId(); 282 external int _getNextAsyncId();
260 283
261 /// Returns the current value from the trace clock. 284 /// Returns the current value from the trace clock.
262 external int _getTraceClock(); 285 external int _getTraceClock();
263 286
287 /// Returns the current value from the thread CPU usage clock.
288 external int _getThreadCpuClock();
289
264 /// Returns the isolate's main port number. 290 /// Returns the isolate's main port number.
265 external int _getIsolateNum(); 291 external int _getIsolateNum();
266 292
267 /// Reports an event for a task. 293 /// Reports an event for a task.
268 external void _reportTaskEvent(int start, 294 external void _reportTaskEvent(int start,
269 int taskId, 295 int taskId,
270 String phase, 296 String phase,
271 String category, 297 String category,
272 String name, 298 String name,
273 String argumentsAsJson); 299 String argumentsAsJson);
274 300
275 /// Reports a complete synchronous event. 301 /// Reports a complete synchronous event.
276 external void _reportCompleteEvent(int start, 302 external void _reportCompleteEvent(int start,
277 int end, 303 int startCpu,
278 String category, 304 String category,
279 String name, 305 String name,
280 String argumentsAsJson); 306 String argumentsAsJson);
281 307
282 /// Reports an instant event. 308 /// Reports an instant event.
283 external void _reportInstantEvent(int start, 309 external void _reportInstantEvent(int start,
284 String category, 310 String category,
285 String name, 311 String name,
286 String argumentsAsJson); 312 String argumentsAsJson);
OLDNEW
« no previous file with comments | « sdk/lib/developer/developer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698