OLD | NEW |
(Empty) | |
| 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 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { |
| 18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); |
| 19 } |
| 20 |
| 21 |
| 22 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
| 23 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 24 if (recorder == NULL) { |
| 25 return Object::null(); |
| 26 } |
| 27 |
| 28 if (!isolate->GetDartStream()->Enabled()) { |
| 29 // Dart stream is not enabled for this isolate, do nothing. |
| 30 return Object::null(); |
| 31 } |
| 32 |
| 33 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); |
| 34 GET_NON_NULL_NATIVE_ARGUMENT(Integer, end, arguments->NativeArgAt(1)); |
| 35 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(2)); |
| 36 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(3)); |
| 37 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(4)); |
| 38 |
| 39 int64_t duration = end.AsInt64Value() - start.AsInt64Value(); |
| 40 int64_t pid = OS::ProcessId(); |
| 41 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); |
| 42 |
| 43 char* event = OS::SCreate(zone, |
| 44 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%"Pd64",\"pid\":%"Pd64"," |
| 45 "\"ts\":%"Pd64",\"ph\":\"X\",\"dur\":%"Pd64",\"args\":%s}", |
| 46 name.ToCString(), |
| 47 category.ToCString(), |
| 48 tid, |
| 49 pid, |
| 50 start.AsInt64Value(), |
| 51 duration, |
| 52 args.ToCString()); |
| 53 |
| 54 // event was allocated in the zone and will be copied by AppendDartEvent. |
| 55 recorder->AppendDartEvent(isolate, event); |
| 56 |
| 57 return Object::null(); |
| 58 } |
| 59 |
| 60 } // namespace dart |
OLD | NEW |