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

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

Issue 1377663002: Add Timeline to dart:developer (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart.developer;
6
7 typedef dynamic TimelineSyncFunction();
8
9 /// Add to the timeline.
10 class Timeline {
11 /// Open a synchronous block of time for |category| with |name|.
12 /// A |SyncBlock| should not be kept open across isolate messages.
13 static SyncBlock openSync(String category, String name) {
14 if (category is! String) {
15 throw new ArgumentError.value(category,
16 'category',
17 'Must be a String');
18 }
19 if (name is! String) {
20 throw new ArgumentError.value(name,
21 'name',
22 'Must be a String');
23 }
24 return new SyncBlock._(category, name, _getTraceClock());
25 }
26
27 /// A utility method to time a synchronous |function|. Opens a block
28 /// for |category| with |name|.
29 static dynamic timeSync(String category,
30 String name,
31 TimelineSyncFunction function,
32 {Map arguments}) {
33 final block = openSync(category, name);
34 final returnValue = function();
rmacnak 2015/09/29 22:36:41 try { return function(); } finally { if (argum
Cutch 2015/09/30 14:42:29 Done.
35 if (arguments is Map) {
36 block.arguments.addAll(arguments);
37 }
38 block.close();
39 return returnValue;
40 }
41 }
42
43 /// A synchronous block of time on the timeline. This block should not be
44 /// kept open across isolate messages.
45 class SyncBlock {
46 /// The category this block belongs to.
47 final String category;
48 /// The name of this block.
49 final String name;
50 /// An (optional) set of arguments which will be serialized to JSON and
51 /// associated with this block.
52 final Map arguments = {};
53 // The start time stamp.
54 final int _start;
55 // Has this block been closed?
56 bool _closed = false;
57
58 SyncBlock._(this.category,
59 this.name,
60 this._start);
61
62 /// Close this block of time. At this point, this block can no longer be
63 /// used.
64 void close() {
65 if (_closed) {
66 throw new StateError(
67 'It is illegal to call close twice on the same SyncBlock');
68 }
69 _closed = true;
70 var end = _getTraceClock();
71
72 // Encode arguments map as JSON before reporting.
73 var argumentsAsJson = JSON.encode(arguments);
74
75 // Report event to runtime.
76 _reportCompleteEvent(_start,
77 end,
78 category,
79 name,
80 argumentsAsJson);
81 }
82 }
83
84 /// Returns the current value from the trace clock.
85 external int _getTraceClock();
86
87 /// Reports a complete synchronous event.
88 external void _reportCompleteEvent(int start,
89 int end,
90 String category,
91 String name,
92 String argumentsAsJson);
OLDNEW
« runtime/vm/dart_api_impl_test.cc ('K') | « sdk/lib/developer/developer_sources.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698