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 | #include "vm/bootstrap_natives.h" |
6 | |
7 | #include "include/dart_api.h" |
8 | |
9 | #include "vm/native_entry.h" |
10 | #include "vm/object.h" |
11 | #include "vm/os.h" |
12 | #include "vm/timeline.h" |
13 | |
14 | namespace dart { |
15 | |
16 | // Native implementations for the dart:developer library. |
17 | |
18 | DEFINE_NATIVE_ENTRY(Timeline_isDartStreamEnabled, 0, 0) { |
19 | #if defined(SUPPORT_TIMELINE) |
20 | if (Timeline::GetDartStream()->enabled()) { |
21 | return Bool::True().raw(); |
22 | } |
23 | #endif |
24 | return Bool::False().raw(); |
25 | } |
26 | |
27 | DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0, 0) { |
28 | #if !defined(SUPPORT_TIMELINE) |
29 | return Integer::New(0); |
30 | #else |
31 | TimelineEventRecorder* recorder = Timeline::recorder(); |
32 | if (recorder == NULL) { |
33 | return Integer::New(0); |
34 | } |
35 | return Integer::New(recorder->GetNextAsyncId()); |
36 | #endif |
37 | } |
38 | |
39 | DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0, 0) { |
40 | return Integer::New(OS::GetCurrentMonotonicMicros(), Heap::kNew); |
41 | } |
42 | |
43 | DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 0, 5) { |
44 | #if defined(SUPPORT_TIMELINE) |
45 | GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(0)); |
46 | GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(1)); |
47 | GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); |
48 | GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
49 | GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
50 | |
51 | TimelineEventRecorder* recorder = Timeline::recorder(); |
52 | if (recorder == NULL) { |
53 | return Object::null(); |
54 | } |
55 | |
56 | TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
57 | if (event == NULL) { |
58 | // Stream was turned off. |
59 | return Object::null(); |
60 | } |
61 | |
62 | DartTimelineEventHelpers::ReportTaskEvent( |
63 | thread, event, id.AsInt64Value(), phase.ToCString(), category.ToCString(), |
64 | name.ToMallocCString(), args.ToMallocCString()); |
65 | #endif // SUPPORT_TIMELINE |
66 | return Object::null(); |
67 | } |
68 | |
69 | DEFINE_NATIVE_ENTRY(Timeline_reportFlowEvent, 0, 5) { |
70 | #if defined(SUPPORT_TIMELINE) |
71 | GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(0)); |
72 | GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); |
73 | GET_NON_NULL_NATIVE_ARGUMENT(Integer, type, arguments->NativeArgAt(2)); |
74 | GET_NON_NULL_NATIVE_ARGUMENT(Integer, flow_id, arguments->NativeArgAt(3)); |
75 | GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
76 | |
77 | TimelineEventRecorder* recorder = Timeline::recorder(); |
78 | if (recorder == NULL) { |
79 | return Object::null(); |
80 | } |
81 | |
82 | TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
83 | if (event == NULL) { |
84 | // Stream was turned off. |
85 | return Object::null(); |
86 | } |
87 | |
88 | DartTimelineEventHelpers::ReportFlowEvent( |
89 | thread, event, category.ToCString(), name.ToMallocCString(), |
90 | type.AsInt64Value(), flow_id.AsInt64Value(), args.ToMallocCString()); |
91 | #endif // SUPPORT_TIMELINE |
92 | return Object::null(); |
93 | } |
94 | |
95 | DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 0, 3) { |
96 | #if defined(SUPPORT_TIMELINE) |
97 | GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(0)); |
98 | GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(1)); |
99 | GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(2)); |
100 | |
101 | TimelineEventRecorder* recorder = Timeline::recorder(); |
102 | if (recorder == NULL) { |
103 | return Object::null(); |
104 | } |
105 | |
106 | TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
107 | if (event == NULL) { |
108 | // Stream was turned off. |
109 | return Object::null(); |
110 | } |
111 | |
112 | DartTimelineEventHelpers::ReportInstantEvent( |
113 | thread, event, category.ToCString(), name.ToMallocCString(), |
114 | args.ToMallocCString()); |
115 | #endif // SUPPORT_TIMELINE |
116 | return Object::null(); |
117 | } |
118 | |
119 | } // namespace dart |
120 | |