| 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" |
| 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 |
| 18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); | 18 DEFINE_NATIVE_ENTRY(Timeline_getIsolateNum, 0) { |
| 19 return Integer::New(static_cast<int64_t>(isolate->main_port()), |
| 20 Heap::kOld, |
| 21 true); |
| 19 } | 22 } |
| 20 | 23 |
| 21 | 24 |
| 22 DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) { | 25 DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) { |
| 23 TimelineEventRecorder* recorder = Timeline::recorder(); | 26 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 24 if (recorder == NULL) { | 27 if (recorder == NULL) { |
| 25 return Integer::New(0); | 28 return Integer::New(0); |
| 26 } | 29 } |
| 27 return Integer::New(recorder->GetNextAsyncId()); | 30 return Integer::New(recorder->GetNextAsyncId()); |
| 28 } | 31 } |
| 29 | 32 |
| 30 | 33 |
| 34 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { |
| 35 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); |
| 36 } |
| 37 |
| 38 |
| 31 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) { | 39 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) { |
| 32 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 40 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 33 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1)); | 41 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1)); |
| 34 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2)); | 42 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2)); |
| 35 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3)); | 43 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3)); |
| 36 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); | 44 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); |
| 37 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5)); | 45 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5)); |
| 38 | 46 |
| 39 TimelineEventRecorder* recorder = Timeline::recorder(); | 47 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 40 if (recorder == NULL) { | 48 if (recorder == NULL) { |
| 41 return Object::null(); | 49 return Object::null(); |
| 42 } | 50 } |
| 43 | 51 |
| 44 if (!isolate->GetDartStream()->Enabled()) { | 52 if (!isolate->GetDartStream()->Enabled()) { |
| 45 // Dart stream is not enabled for this isolate, do nothing. | 53 // Dart stream is not enabled for this isolate, do nothing. |
| 46 return Object::null(); | 54 return Object::null(); |
| 47 } | 55 } |
| 48 | 56 |
| 49 | |
| 50 int64_t pid = OS::ProcessId(); | 57 int64_t pid = OS::ProcessId(); |
| 51 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); | 58 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); |
| 52 | 59 |
| 53 char* event = OS::SCreate(zone, | 60 char* json = OS::SCreate(zone, |
| 54 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," | 61 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," |
| 55 "\"ts\":%" Pd64 ",\"ph\":\"%s\",\"id\":%" Pd64 ", \"args\":%s}", | 62 "\"ts\":%" Pd64 ",\"ph\":\"%s\",\"id\":%" Pd64 ", \"args\":%s}", |
| 56 name.ToCString(), | 63 name.ToCString(), |
| 57 category.ToCString(), | 64 category.ToCString(), |
| 58 tid, | 65 tid, |
| 59 pid, | 66 pid, |
| 60 start.AsInt64Value(), | 67 start.AsInt64Value(), |
| 61 phase.ToCString(), | 68 phase.ToCString(), |
| 62 id.AsInt64Value(), | 69 id.AsInt64Value(), |
| 63 args.ToCString()); | 70 args.ToCString()); |
| 64 | 71 |
| 65 // event was allocated in the zone and will be copied by AppendDartEvent. | 72 TimelineEvent* event = isolate->GetDartStream()->StartEvent(); |
| 66 recorder->AppendDartEvent(isolate, event); | 73 if (event == NULL) { |
| 74 // Stream was turned off. |
| 75 return Object::null(); |
| 76 } |
| 77 // json was allocated in the zone and a copy will be stored in event. |
| 78 event->SerializedJSON(json); |
| 79 event->Complete(); |
| 67 | 80 |
| 68 return Object::null(); | 81 return Object::null(); |
| 69 } | 82 } |
| 70 | 83 |
| 71 | 84 |
| 72 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { | 85 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
| 73 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | 86 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 74 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1)); | 87 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1)); |
| 75 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); | 88 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); |
| 76 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); | 89 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
| 77 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); | 90 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
| 78 | 91 |
| 79 TimelineEventRecorder* recorder = Timeline::recorder(); | 92 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 80 if (recorder == NULL) { | 93 if (recorder == NULL) { |
| 81 return Object::null(); | 94 return Object::null(); |
| 82 } | 95 } |
| 83 | 96 |
| 84 if (!isolate->GetDartStream()->Enabled()) { | 97 if (!isolate->GetDartStream()->Enabled()) { |
| 85 // Dart stream is not enabled for this isolate, do nothing. | 98 // Dart stream is not enabled for this isolate, do nothing. |
| 86 return Object::null(); | 99 return Object::null(); |
| 87 } | 100 } |
| 88 | 101 |
| 89 int64_t duration = end.AsInt64Value() - start.AsInt64Value(); | 102 int64_t duration = end.AsInt64Value() - start.AsInt64Value(); |
| 90 int64_t pid = OS::ProcessId(); | 103 int64_t pid = OS::ProcessId(); |
| 91 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); | 104 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); |
| 92 | 105 |
| 93 char* event = OS::SCreate(zone, | 106 char* json = OS::SCreate(zone, |
| 94 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," | 107 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," |
| 95 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", | 108 "\"ts\":%" Pd64 ",\"ph\":\"X\",\"dur\":%" Pd64 ",\"args\":%s}", |
| 96 name.ToCString(), | 109 name.ToCString(), |
| 97 category.ToCString(), | 110 category.ToCString(), |
| 98 tid, | 111 tid, |
| 99 pid, | 112 pid, |
| 100 start.AsInt64Value(), | 113 start.AsInt64Value(), |
| 101 duration, | 114 duration, |
| 102 args.ToCString()); | 115 args.ToCString()); |
| 103 | 116 |
| 104 // event was allocated in the zone and will be copied by AppendDartEvent. | 117 TimelineEvent* event = isolate->GetDartStream()->StartEvent(); |
| 105 recorder->AppendDartEvent(isolate, event); | 118 if (event == NULL) { |
| 119 // Stream was turned off. |
| 120 return Object::null(); |
| 121 } |
| 122 // json was allocated in the zone and a copy will be stored in event. |
| 123 event->SerializedJSON(json); |
| 124 event->Complete(); |
| 106 | 125 |
| 107 return Object::null(); | 126 return Object::null(); |
| 108 } | 127 } |
| 109 | 128 |
| 110 } // namespace dart | 129 } // namespace dart |
| OLD | NEW |