Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 event->CompleteWithPreSerializedJSON(json); | 109 event->CompleteWithPreSerializedJSON(json); |
| 110 #endif | 110 #endif |
| 111 return Object::null(); | 111 return Object::null(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { | 114 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
| 115 #ifndef PRODUCT | 115 #ifndef PRODUCT |
| 116 if (!FLAG_support_timeline) { | 116 if (!FLAG_support_timeline) { |
| 117 return Object::null(); | 117 return Object::null(); |
| 118 } | 118 } |
| 119 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | |
| 120 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start_cpu, arguments->NativeArgAt(1)); | |
| 121 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); | |
| 122 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); | |
| 123 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); | |
| 124 | 119 |
| 125 TimelineEventRecorder* recorder = Timeline::recorder(); | 120 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 126 if (recorder == NULL) { | 121 if (recorder == NULL) { |
| 127 return Object::null(); | 122 return Object::null(); |
| 128 } | 123 } |
| 129 | 124 |
| 130 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); | 125 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
| 131 if (event == NULL) { | 126 if (event == NULL) { |
| 132 // Stream was turned off. | 127 // Stream was turned off. |
| 133 return Object::null(); | 128 return Object::null(); |
| 134 } | 129 } |
| 135 | 130 |
| 131 GET_NON_NULL_NATIVE_ARGUMENT(Integer, s, arguments->NativeArgAt(0)); | |
| 132 GET_NON_NULL_NATIVE_ARGUMENT(Integer, s_cpu, arguments->NativeArgAt(1)); | |
| 133 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); | |
| 134 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); | |
| 135 const int64_t start = s.AsInt64Value(); | |
| 136 const int64_t start_cpu = s_cpu.AsInt64Value(); | |
| 136 const int64_t end = OS::GetCurrentMonotonicMicros(); | 137 const int64_t end = OS::GetCurrentMonotonicMicros(); |
| 137 const int64_t end_cpu = OS::GetCurrentThreadCPUMicros(); | 138 const int64_t end_cpu = OS::GetCurrentThreadCPUMicros(); |
| 138 const int64_t duration = end - start.AsInt64Value(); | 139 #if defined(HOST_OS_FUCHSIA) |
| 139 const int64_t duration_cpu = end_cpu - start_cpu.AsInt64Value(); | 140 event->Duration(strdup(name.ToCString()), start, end, start_cpu, end_cpu); |
| 140 int64_t pid = OS::ProcessId(); | 141 event->set_owns_label(true); |
| 142 event->SetNumArguments(1); | |
| 143 event->CopyArgument(0, "args", args.ToCString()); | |
| 144 event->Complete(); | |
| 145 #else | |
|
siva
2017/07/20 16:36:31
Do you think we need a OS abstraction around this
zra
2017/07/20 16:57:04
There are probably going to be more pieces because
| |
| 146 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); | |
| 147 const int64_t duration = end - start; | |
| 148 const int64_t duration_cpu = end_cpu - start_cpu; | |
| 149 const int64_t pid = OS::ProcessId(); | |
| 141 OSThread* os_thread = thread->os_thread(); | 150 OSThread* os_thread = thread->os_thread(); |
| 142 ASSERT(os_thread != NULL); | 151 ASSERT(os_thread != NULL); |
| 143 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); | 152 const int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); |
| 144 | 153 |
| 145 char* json = NULL; | 154 char* json = NULL; |
| 146 | 155 |
| 147 if ((start_cpu.AsInt64Value() != -1) && (end_cpu != -1)) { | 156 if ((start_cpu != -1) && (end_cpu != -1)) { |
| 148 json = OS::SCreate( | 157 json = OS::SCreate( |
| 149 zone, | 158 zone, |
| 150 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 | 159 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 |
| 151 "," | 160 "," |
| 152 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 | 161 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 |
| 153 "," | 162 "," |
| 154 "\"tdur\":%" Pd64 ",\"args\":%s}", | 163 "\"tdur\":%" Pd64 ",\"args\":%s}", |
| 155 name.ToCString(), category.ToCString(), tid, pid, start.AsInt64Value(), | 164 name.ToCString(), category.ToCString(), tid, pid, start, |
| 156 duration, duration_cpu, args.ToCString()); | 165 duration, duration_cpu, args.ToCString()); |
| 157 } else { | 166 } else { |
| 158 json = OS::SCreate( | 167 json = OS::SCreate( |
| 159 zone, | 168 zone, |
| 160 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 | 169 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 |
| 161 "," | 170 "," |
| 162 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", | 171 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", |
| 163 name.ToCString(), category.ToCString(), tid, pid, start.AsInt64Value(), | 172 name.ToCString(), category.ToCString(), tid, pid, start, |
| 164 duration, args.ToCString()); | 173 duration, args.ToCString()); |
| 165 } | 174 } |
| 166 ASSERT(json != NULL); | 175 ASSERT(json != NULL); |
| 167 | 176 |
| 168 event->Duration("", start.AsInt64Value(), end, start_cpu.AsInt64Value(), | 177 event->Duration("", start, end, start_cpu, end_cpu); |
| 169 end_cpu); | |
| 170 // json was allocated in the zone and a copy will be stored in event. | 178 // json was allocated in the zone and a copy will be stored in event. |
| 171 event->CompleteWithPreSerializedJSON(json); | 179 event->CompleteWithPreSerializedJSON(json); |
| 172 #endif | 180 #endif // !defined(HOST_OS_FUCHSIA) |
| 181 #endif // !defined(PRODUCT) | |
| 173 return Object::null(); | 182 return Object::null(); |
| 174 } | 183 } |
| 175 | 184 |
| 176 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { | 185 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { |
| 177 #ifndef PRODUCT | 186 #ifndef PRODUCT |
| 178 if (!FLAG_support_timeline) { | 187 if (!FLAG_support_timeline) { |
| 179 return Object::null(); | 188 return Object::null(); |
| 180 } | 189 } |
| 181 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 190 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 182 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(1)); | 191 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(1)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 208 start.AsInt64Value(), args.ToCString()); | 217 start.AsInt64Value(), args.ToCString()); |
| 209 | 218 |
| 210 event->Instant("", start.AsInt64Value()); | 219 event->Instant("", start.AsInt64Value()); |
| 211 // json was allocated in the zone and a copy will be stored in event. | 220 // json was allocated in the zone and a copy will be stored in event. |
| 212 event->CompleteWithPreSerializedJSON(json); | 221 event->CompleteWithPreSerializedJSON(json); |
| 213 #endif | 222 #endif |
| 214 return Object::null(); | 223 return Object::null(); |
| 215 } | 224 } |
| 216 | 225 |
| 217 } // namespace dart | 226 } // namespace dart |
| OLD | NEW |