| 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().ptr(); |
| 22 | } |
| 23 | #endif |
| 24 | return Bool::False().ptr(); |
| 25 | } |
| 26 | |
| 27 | DEFINE_NATIVE_ENTRY(Timeline_getNextTaskId, 0, 0) { |
| 28 | #if !defined(SUPPORT_TIMELINE) |
| 29 | return Integer::New(0); |
| 30 | #else |
| 31 | return Integer::New(value: thread->GetNextTaskId()); |
| 32 | #endif |
| 33 | } |
| 34 | |
| 35 | DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0, 0) { |
| 36 | return Integer::New(value: OS::GetCurrentMonotonicMicros(), space: Heap::kNew); |
| 37 | } |
| 38 | |
| 39 | DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 0, 5) { |
| 40 | #if defined(SUPPORT_TIMELINE) |
| 41 | GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(0)); |
| 42 | GET_NON_NULL_NATIVE_ARGUMENT(Integer, flow_id, arguments->NativeArgAt(1)); |
| 43 | GET_NON_NULL_NATIVE_ARGUMENT(Smi, type, arguments->NativeArgAt(2)); |
| 44 | GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
| 45 | GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
| 46 | |
| 47 | TimelineEventRecorder* recorder = Timeline::recorder(); |
| 48 | if (recorder == nullptr) { |
| 49 | return Object::null(); |
| 50 | } |
| 51 | |
| 52 | TimelineEvent* event = Timeline::GetDartStream()->StartEvent(); |
| 53 | if (event == nullptr) { |
| 54 | // Stream was turned off. |
| 55 | return Object::null(); |
| 56 | } |
| 57 | |
| 58 | std::unique_ptr<const int64_t[]> flow_ids; |
| 59 | if (flow_id.AsInt64Value() != TimelineEvent::kNoFlowId) { |
| 60 | int64_t* flow_ids_internal = new int64_t[1]; |
| 61 | flow_ids_internal[0] = flow_id.AsInt64Value(); |
| 62 | flow_ids = std::unique_ptr<const int64_t[]>(flow_ids_internal); |
| 63 | } |
| 64 | intptr_t flow_id_count = |
| 65 | flow_id.AsInt64Value() == TimelineEvent::kNoFlowId ? 0 : 1; |
| 66 | DartTimelineEventHelpers::ReportTaskEvent( |
| 67 | event, id: id.AsInt64Value(), flow_id_count, flow_ids, type: type.Value(), |
| 68 | name: name.ToMallocCString(), args: args.ToMallocCString()); |
| 69 | #endif // SUPPORT_TIMELINE |
| 70 | return Object::null(); |
| 71 | } |
| 72 | |
| 73 | } // namespace dart |
| 74 | |