| 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 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 return Integer::New(recorder->GetNextAsyncId()); | 31 return Integer::New(recorder->GetNextAsyncId()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { | 35 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { |
| 36 return Integer::New(OS::GetCurrentMonotonicMicros(), Heap::kNew); | 36 return Integer::New(OS::GetCurrentMonotonicMicros(), Heap::kNew); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 DEFINE_NATIVE_ENTRY(Timeline_getThreadCpuClock, 0) { |
| 41 return Integer::New(OS::GetCurrentThreadCPUMicros(), Heap::kNew); |
| 42 } |
| 43 |
| 44 |
| 40 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) { | 45 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) { |
| 41 if (!FLAG_support_timeline) { | 46 if (!FLAG_support_timeline) { |
| 42 return Object::null(); | 47 return Object::null(); |
| 43 } | 48 } |
| 44 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 49 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 45 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1)); | 50 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1)); |
| 46 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2)); | 51 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2)); |
| 47 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3)); | 52 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3)); |
| 48 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); | 53 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); |
| 49 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5)); | 54 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 106 |
| 102 return Object::null(); | 107 return Object::null(); |
| 103 } | 108 } |
| 104 | 109 |
| 105 | 110 |
| 106 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { | 111 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
| 107 if (!FLAG_support_timeline) { | 112 if (!FLAG_support_timeline) { |
| 108 return Object::null(); | 113 return Object::null(); |
| 109 } | 114 } |
| 110 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 115 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 111 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1)); | 116 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start_cpu, arguments->NativeArgAt(1)); |
| 112 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); | 117 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); |
| 113 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); | 118 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
| 114 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); | 119 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
| 115 | 120 |
| 116 TimelineEventRecorder* recorder = Timeline::recorder(); | 121 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 117 if (recorder == NULL) { | 122 if (recorder == NULL) { |
| 118 return Object::null(); | 123 return Object::null(); |
| 119 } | 124 } |
| 120 | 125 |
| 121 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); | 126 TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
| 122 if (event == NULL) { | 127 if (event == NULL) { |
| 123 // Stream was turned off. | 128 // Stream was turned off. |
| 124 return Object::null(); | 129 return Object::null(); |
| 125 } | 130 } |
| 126 | 131 |
| 127 int64_t duration = end.AsInt64Value() - start.AsInt64Value(); | 132 const int64_t end = OS::GetCurrentMonotonicMicros(); |
| 133 const int64_t end_cpu = OS::GetCurrentThreadCPUMicros(); |
| 134 const int64_t duration = end - start.AsInt64Value(); |
| 135 const int64_t duration_cpu = end_cpu - start_cpu.AsInt64Value(); |
| 128 int64_t pid = OS::ProcessId(); | 136 int64_t pid = OS::ProcessId(); |
| 129 OSThread* os_thread = thread->os_thread(); | 137 OSThread* os_thread = thread->os_thread(); |
| 130 ASSERT(os_thread != NULL); | 138 ASSERT(os_thread != NULL); |
| 131 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); | 139 int64_t tid = OSThread::ThreadIdToIntPtr(os_thread->trace_id()); |
| 132 | 140 |
| 133 char* json = OS::SCreate(zone, | 141 char* json = NULL; |
| 134 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," | |
| 135 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", | |
| 136 name.ToCString(), | |
| 137 category.ToCString(), | |
| 138 tid, | |
| 139 pid, | |
| 140 start.AsInt64Value(), | |
| 141 duration, | |
| 142 args.ToCString()); | |
| 143 | 142 |
| 144 event->Duration("", start.AsInt64Value(), end.AsInt64Value()); | 143 if ((start_cpu.AsInt64Value() != -1) && (end_cpu != -1)) { |
| 144 json = OS::SCreate(zone, |
| 145 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," |
| 146 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 "," |
| 147 "\"tdur\":%" Pd64 ",\"args\":%s}", |
| 148 name.ToCString(), |
| 149 category.ToCString(), |
| 150 tid, |
| 151 pid, |
| 152 start.AsInt64Value(), |
| 153 duration, |
| 154 duration_cpu, |
| 155 args.ToCString()); |
| 156 } else { |
| 157 json = OS::SCreate(zone, |
| 158 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," |
| 159 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", |
| 160 name.ToCString(), |
| 161 category.ToCString(), |
| 162 tid, |
| 163 pid, |
| 164 start.AsInt64Value(), |
| 165 duration, |
| 166 args.ToCString()); |
| 167 } |
| 168 ASSERT(json != NULL); |
| 169 |
| 170 event->Duration("", |
| 171 start.AsInt64Value(), |
| 172 end, |
| 173 start_cpu.AsInt64Value(), |
| 174 end_cpu); |
| 145 // json was allocated in the zone and a copy will be stored in event. | 175 // json was allocated in the zone and a copy will be stored in event. |
| 146 event->CompleteWithPreSerializedJSON(json); | 176 event->CompleteWithPreSerializedJSON(json); |
| 147 | 177 |
| 148 return Object::null(); | 178 return Object::null(); |
| 149 } | 179 } |
| 150 | 180 |
| 151 | 181 |
| 152 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { | 182 DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) { |
| 153 if (!FLAG_support_timeline) { | 183 if (!FLAG_support_timeline) { |
| 154 return Object::null(); | 184 return Object::null(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 185 args.ToCString()); | 215 args.ToCString()); |
| 186 | 216 |
| 187 event->Instant("", start.AsInt64Value()); | 217 event->Instant("", start.AsInt64Value()); |
| 188 // json was allocated in the zone and a copy will be stored in event. | 218 // json was allocated in the zone and a copy will be stored in event. |
| 189 event->CompleteWithPreSerializedJSON(json); | 219 event->CompleteWithPreSerializedJSON(json); |
| 190 | 220 |
| 191 return Object::null(); | 221 return Object::null(); |
| 192 } | 222 } |
| 193 | 223 |
| 194 } // namespace dart | 224 } // namespace dart |
| OLD | NEW |