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 #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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (recorder == NULL) { | 66 if (recorder == NULL) { |
67 return Object::null(); | 67 return Object::null(); |
68 } | 68 } |
69 | 69 |
70 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); | 70 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
71 if (event == NULL) { | 71 if (event == NULL) { |
72 // Stream was turned off. | 72 // Stream was turned off. |
73 return Object::null(); | 73 return Object::null(); |
74 } | 74 } |
75 | 75 |
76 int64_t pid = OS::ProcessId(); | 76 DartTimelineEventHelpers::ReportTaskEvent( |
77 OSThread* os_thread = thread->os_thread(); | 77 thread, zone, event, start.AsInt64Value(), id.AsInt64Value(), |
78 ASSERT(os_thread != NULL); | 78 phase.ToCString(), category.ToCString(), name.ToCString(), |
79 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); | 79 args.ToCString()); |
80 // Convert phase to a C string and perform a sanity check. | |
81 const char* phase_string = phase.ToCString(); | |
82 ASSERT(phase_string != NULL); | |
83 ASSERT((phase_string[0] == 'n') || (phase_string[0] == 'b') || | |
84 (phase_string[0] == 'e')); | |
85 ASSERT(phase_string[1] == '\0'); | |
86 char* json = OS::SCreate( | |
87 zone, | |
88 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 | |
89 "," | |
90 "\"ts\":%" Pd64 ",\"ph\":\"%s\",\"id\":%" Pd64 ", \"args\":%s}", | |
91 name.ToCString(), category.ToCString(), tid, pid, start.AsInt64Value(), | |
92 phase_string, id.AsInt64Value(), args.ToCString()); | |
93 | |
94 switch (phase_string[0]) { | |
95 case 'n': | |
96 event->AsyncInstant("", id.AsInt64Value(), start.AsInt64Value()); | |
97 break; | |
98 case 'b': | |
99 event->AsyncBegin("", id.AsInt64Value(), start.AsInt64Value()); | |
100 break; | |
101 case 'e': | |
102 event->AsyncEnd("", id.AsInt64Value(), start.AsInt64Value()); | |
103 break; | |
104 default: | |
105 UNREACHABLE(); | |
106 } | |
107 | |
108 // json was allocated in the zone and a copy will be stored in event. | |
109 event->CompleteWithPreSerializedJSON(json); | |
110 #endif | 80 #endif |
111 return Object::null(); | 81 return Object::null(); |
112 } | 82 } |
113 | 83 |
114 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { | 84 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
115 #ifndef PRODUCT | 85 #ifndef PRODUCT |
116 if (!FLAG_support_timeline) { | 86 if (!FLAG_support_timeline) { |
117 return Object::null(); | 87 return Object::null(); |
118 } | 88 } |
119 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 89 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
120 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start_cpu, arguments->NativeArgAt(1)); | 90 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start_cpu, arguments->NativeArgAt(1)); |
121 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); | 91 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); |
122 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); | 92 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
123 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); | 93 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
124 | 94 |
125 TimelineEventRecorder* recorder = Timeline::recorder(); | 95 TimelineEventRecorder* recorder = Timeline::recorder(); |
126 if (recorder == NULL) { | 96 if (recorder == NULL) { |
127 return Object::null(); | 97 return Object::null(); |
128 } | 98 } |
129 | 99 |
130 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); | 100 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
131 if (event == NULL) { | 101 if (event == NULL) { |
132 // Stream was turned off. | 102 // Stream was turned off. |
133 return Object::null(); | 103 return Object::null(); |
134 } | 104 } |
135 | 105 |
136 const int64_t end = OS::GetCurrentMonotonicMicros(); | 106 DartTimelineEventHelpers::ReportCompleteEvent( |
137 const int64_t end_cpu = OS::GetCurrentThreadCPUMicros(); | 107 thread, zone, event, start.AsInt64Value(), start_cpu.AsInt64Value(), |
138 const int64_t duration = end - start.AsInt64Value(); | 108 category.ToCString(), name.ToCString(), args.ToCString()); |
139 const int64_t duration_cpu = end_cpu - start_cpu.AsInt64Value(); | 109 #endif // !defined(PRODUCT) |
140 int64_t pid = OS::ProcessId(); | |
141 OSThread* os_thread = thread->os_thread(); | |
142 ASSERT(os_thread != NULL); | |
143 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); | |
144 | |
145 char* json = NULL; | |
146 | |
147 if ((start_cpu.AsInt64Value() != -1) && (end_cpu != -1)) { | |
148 json = OS::SCreate( | |
149 zone, | |
150 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 | |
151 "," | |
152 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 | |
153 "," | |
154 "\"tdur\":%" Pd64 ",\"args\":%s}", | |
155 name.ToCString(), category.ToCString(), tid, pid, start.AsInt64Value(), | |
156 duration, duration_cpu, args.ToCString()); | |
157 } else { | |
158 json = OS::SCreate( | |
159 zone, | |
160 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 | |
161 "," | |
162 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", | |
163 name.ToCString(), category.ToCString(), tid, pid, start.AsInt64Value(), | |
164 duration, args.ToCString()); | |
165 } | |
166 ASSERT(json != NULL); | |
167 | |
168 event->Duration("", start.AsInt64Value(), end, start_cpu.AsInt64Value(), | |
169 end_cpu); | |
170 // json was allocated in the zone and a copy will be stored in event. | |
171 event->CompleteWithPreSerializedJSON(json); | |
172 #endif | |
173 return Object::null(); | 110 return Object::null(); |
174 } | 111 } |
175 | 112 |
176 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { | 113 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { |
177 #ifndef PRODUCT | 114 #ifndef PRODUCT |
178 if (!FLAG_support_timeline) { | 115 if (!FLAG_support_timeline) { |
179 return Object::null(); | 116 return Object::null(); |
180 } | 117 } |
181 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 118 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
182 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(1)); | 119 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(1)); |
183 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(2)); | 120 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(2)); |
184 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(3)); | 121 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(3)); |
185 | 122 |
186 TimelineEventRecorder* recorder = Timeline::recorder(); | 123 TimelineEventRecorder* recorder = Timeline::recorder(); |
187 if (recorder == NULL) { | 124 if (recorder == NULL) { |
188 return Object::null(); | 125 return Object::null(); |
189 } | 126 } |
190 | 127 |
191 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); | 128 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
192 if (event == NULL) { | 129 if (event == NULL) { |
193 // Stream was turned off. | 130 // Stream was turned off. |
194 return Object::null(); | 131 return Object::null(); |
195 } | 132 } |
196 | 133 |
197 int64_t pid = OS::ProcessId(); | 134 DartTimelineEventHelpers::ReportInstantEvent( |
198 OSThread* os_thread = thread->os_thread(); | 135 thread, zone, event, start.AsInt64Value(), category.ToCString(), |
199 ASSERT(os_thread != NULL); | 136 name.ToCString(), args.ToCString()); |
200 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); | |
201 | |
202 char* json = OS::SCreate(zone, | |
203 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 | |
204 ",\"pid\":%" Pd64 | |
205 "," | |
206 "\"ts\":%" Pd64 ",\"ph\":\"I\",\"args\":%s}", | |
207 name.ToCString(), category.ToCString(), tid, pid, | |
208 start.AsInt64Value(), args.ToCString()); | |
209 | |
210 event->Instant("", start.AsInt64Value()); | |
211 // json was allocated in the zone and a copy will be stored in event. | |
212 event->CompleteWithPreSerializedJSON(json); | |
213 #endif | 137 #endif |
214 return Object::null(); | 138 return Object::null(); |
215 } | 139 } |
216 | 140 |
217 } // namespace dart | 141 } // namespace dart |
OLD | NEW |