OLD | NEW |
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"); | 7 const bool _isProduct = const bool.fromEnvironment("dart.vm.product"); |
8 | 8 |
9 typedef dynamic TimelineSyncFunction(); | 9 typedef dynamic TimelineSyncFunction(); |
10 typedef Future TimelineAsyncFunction(); | 10 typedef Future TimelineAsyncFunction(); |
11 | 11 |
12 /// Add to the timeline. | 12 /// Add to the timeline. |
13 class Timeline { | 13 class Timeline { |
14 /// Start a synchronous operation labeled [name]. Optionally takes | 14 /// Start a synchronous operation labeled [name]. Optionally takes |
15 /// a [Map] of [arguments]. This operation must be finished before | 15 /// a [Map] of [arguments]. This operation must be finished before |
16 /// returning to the event queue. | 16 /// returning to the event queue. |
17 static void startSync(String name, {Map arguments}) { | 17 static void startSync(String name, {Map arguments}) { |
18 if (_isProduct) { | 18 if (_isProduct) { |
19 return; | 19 return; |
20 } | 20 } |
21 if (name is! String) { | 21 if (name is! String) { |
22 throw new ArgumentError.value(name, | 22 throw new ArgumentError.value(name, |
23 'name', | 23 'name', |
24 'Must be a String'); | 24 'Must be a String'); |
25 } | 25 } |
| 26 if (!_isDartStreamEnabled()) { |
| 27 // Push a null onto the stack and return. |
| 28 _stack.add(null); |
| 29 return; |
| 30 } |
26 var block = new _SyncBlock._(name, _getTraceClock(), _getThreadCpuClock()); | 31 var block = new _SyncBlock._(name, _getTraceClock(), _getThreadCpuClock()); |
27 if (arguments is Map) { | 32 if (arguments is Map) { |
28 block._appendArguments(arguments); | 33 block._appendArguments(arguments); |
29 } | 34 } |
30 _stack.add(block); | 35 _stack.add(block); |
31 } | 36 } |
32 | 37 |
33 /// Finish the last synchronous operation that was started. | 38 /// Finish the last synchronous operation that was started. |
34 static void finishSync() { | 39 static void finishSync() { |
35 if (_isProduct) { | 40 if (_isProduct) { |
36 return; | 41 return; |
37 } | 42 } |
38 if (_stack.length == 0) { | 43 if (_stack.length == 0) { |
39 throw new StateError( | 44 throw new StateError( |
40 'Uneven calls to startSync and finishSync'); | 45 'Uneven calls to startSync and finishSync'); |
41 } | 46 } |
42 // Pop top item off of stack. | 47 // Pop top item off of stack. |
43 var block = _stack.removeLast(); | 48 var block = _stack.removeLast(); |
| 49 if (block == null) { |
| 50 // Dart stream was disabled when startSync was called. |
| 51 return; |
| 52 } |
44 // Finish it. | 53 // Finish it. |
45 block.finish(); | 54 block.finish(); |
46 } | 55 } |
47 | 56 |
48 /// Emit an instant event. | 57 /// Emit an instant event. |
49 static void instantSync(String name, {Map arguments}) { | 58 static void instantSync(String name, {Map arguments}) { |
50 if (_isProduct) { | 59 if (_isProduct) { |
51 return; | 60 return; |
52 } | 61 } |
53 if (name is! String) { | 62 if (name is! String) { |
54 throw new ArgumentError.value(name, | 63 throw new ArgumentError.value(name, |
55 'name', | 64 'name', |
56 'Must be a String'); | 65 'Must be a String'); |
57 } | 66 } |
| 67 if (!_isDartStreamEnabled()) { |
| 68 // Stream is disabled. |
| 69 return; |
| 70 } |
58 Map instantArguments; | 71 Map instantArguments; |
59 if (arguments is Map) { | 72 if (arguments is Map) { |
60 instantArguments = new Map.from(arguments); | 73 instantArguments = new Map.from(arguments); |
61 } | 74 } |
62 _reportInstantEvent(_getTraceClock(), | 75 _reportInstantEvent(_getTraceClock(), |
63 'Dart', | 76 'Dart', |
64 name, | 77 name, |
65 _argumentsAsJson(instantArguments)); | 78 _argumentsAsJson(instantArguments)); |
66 } | 79 } |
67 | 80 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (_fastPathArguments == null) { | 284 if (_fastPathArguments == null) { |
272 _fastPathArguments = '{"isolateNumber":"${Timeline._isolateId}"}'; | 285 _fastPathArguments = '{"isolateNumber":"${Timeline._isolateId}"}'; |
273 } | 286 } |
274 return _fastPathArguments; | 287 return _fastPathArguments; |
275 } | 288 } |
276 // Add isolateNumber to arguments map. | 289 // Add isolateNumber to arguments map. |
277 arguments['isolateNumber'] = Timeline._isolateIdString; | 290 arguments['isolateNumber'] = Timeline._isolateIdString; |
278 return JSON.encode(arguments); | 291 return JSON.encode(arguments); |
279 } | 292 } |
280 | 293 |
| 294 /// Returns true if the Dart Timeline stream is enabled. |
| 295 external bool _isDartStreamEnabled(); |
| 296 |
281 /// Returns the next async task id. | 297 /// Returns the next async task id. |
282 external int _getNextAsyncId(); | 298 external int _getNextAsyncId(); |
283 | 299 |
284 /// Returns the current value from the trace clock. | 300 /// Returns the current value from the trace clock. |
285 external int _getTraceClock(); | 301 external int _getTraceClock(); |
286 | 302 |
287 /// Returns the current value from the thread CPU usage clock. | 303 /// Returns the current value from the thread CPU usage clock. |
288 external int _getThreadCpuClock(); | 304 external int _getThreadCpuClock(); |
289 | 305 |
290 /// Returns the isolate's main port number. | 306 /// Returns the isolate's main port number. |
(...skipping 12 matching lines...) Expand all Loading... |
303 int startCpu, | 319 int startCpu, |
304 String category, | 320 String category, |
305 String name, | 321 String name, |
306 String argumentsAsJson); | 322 String argumentsAsJson); |
307 | 323 |
308 /// Reports an instant event. | 324 /// Reports an instant event. |
309 external void _reportInstantEvent(int start, | 325 external void _reportInstantEvent(int start, |
310 String category, | 326 String category, |
311 String name, | 327 String name, |
312 String argumentsAsJson); | 328 String argumentsAsJson); |
OLD | NEW |