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

Side by Side Diff: runtime/lib/timeline.cc

Issue 1397823002: Add support for emitting asynchronous timeline events from Dart code (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
« no previous file with comments | « no previous file | runtime/lib/timeline.dart » ('j') | 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 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/os.h" 11 #include "vm/os.h"
12 #include "vm/timeline.h" 12 #include "vm/timeline.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 // Native implementations for the dart:developer library. 16 // Native implementations for the dart:developer library.
17 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { 17 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) {
18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); 18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true);
19 } 19 }
20 20
21 21
22 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { 22 DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) {
23 TimelineEventRecorder* recorder = Timeline::recorder();
24 if (recorder == NULL) {
25 return Integer::New(0);
26 }
27 return Integer::New(recorder->GetNextAsyncId());
28 }
29
30
31 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) {
32 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0));
33 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1));
34 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2));
35 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3));
36 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4));
37 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5));
38
23 TimelineEventRecorder* recorder = Timeline::recorder(); 39 TimelineEventRecorder* recorder = Timeline::recorder();
24 if (recorder == NULL) { 40 if (recorder == NULL) {
25 return Object::null(); 41 return Object::null();
26 } 42 }
27 43
28 if (!isolate->GetDartStream()->Enabled()) { 44 if (!isolate->GetDartStream()->Enabled()) {
29 // Dart stream is not enabled for this isolate, do nothing. 45 // Dart stream is not enabled for this isolate, do nothing.
30 return Object::null(); 46 return Object::null();
31 } 47 }
32 48
49
50 int64_t pid = OS::ProcessId();
51 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId());
52
53 char* event = OS::SCreate(zone,
54 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 ","
55 "\"ts\":%" Pd64 ",\"ph\":\"%s\",\"id\":%" Pd64 ", \"args\":%s}",
56 name.ToCString(),
57 category.ToCString(),
58 tid,
59 pid,
60 start.AsInt64Value(),
61 phase.ToCString(),
62 id.AsInt64Value(),
63 args.ToCString());
64
65 // event was allocated in the zone and will be copied by AppendDartEvent.
66 recorder->AppendDartEvent(isolate, event);
67
68 return Object::null();
69 }
70
71
72 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) {
33 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); 73 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0));
34 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1)); 74 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1));
35 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); 75 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2));
36 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); 76 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3));
37 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); 77 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4));
38 78
79 TimelineEventRecorder* recorder = Timeline::recorder();
80 if (recorder == NULL) {
81 return Object::null();
82 }
83
84 if (!isolate->GetDartStream()->Enabled()) {
85 // Dart stream is not enabled for this isolate, do nothing.
86 return Object::null();
87 }
88
39 int64_t duration = end.AsInt64Value() - start.AsInt64Value(); 89 int64_t duration = end.AsInt64Value() - start.AsInt64Value();
40 int64_t pid = OS::ProcessId(); 90 int64_t pid = OS::ProcessId();
41 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); 91 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId());
42 92
43 char* event = OS::SCreate(zone, 93 char* event = OS::SCreate(zone,
44 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," 94 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 ","
45 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", 95 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}",
46 name.ToCString(), 96 name.ToCString(),
47 category.ToCString(), 97 category.ToCString(),
48 tid, 98 tid,
49 pid, 99 pid,
50 start.AsInt64Value(), 100 start.AsInt64Value(),
51 duration, 101 duration,
52 args.ToCString()); 102 args.ToCString());
53 103
54 // event was allocated in the zone and will be copied by AppendDartEvent. 104 // event was allocated in the zone and will be copied by AppendDartEvent.
55 recorder->AppendDartEvent(isolate, event); 105 recorder->AppendDartEvent(isolate, event);
56 106
57 return Object::null(); 107 return Object::null();
58 } 108 }
59 109
60 } // namespace dart 110 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/timeline.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698