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 DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) { |
18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); | 18 return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true); |
19 } | 19 } |
20 | 20 |
21 | 21 |
22 DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) { | |
23 TimelineEventRecorder* recorder = Timeline::recorder(); | |
24 if (recorder == NULL) { | |
25 return Integer::New(0); | |
26 } | |
27 return Integer::New(recorder->GetNextAsyncId()); | |
28 } | |
29 | |
30 | |
31 DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) { | |
32 TimelineEventRecorder* recorder = Timeline::recorder(); | |
33 if (recorder == NULL) { | |
34 return Object::null(); | |
rmacnak
2015/10/09 17:15:42
I think argument checking should go before the bai
Cutch
2015/10/09 17:19:26
Done here and elsewhere.
| |
35 } | |
36 | |
37 if (!isolate->GetDartStream()->Enabled()) { | |
38 // Dart stream is not enabled for this isolate, do nothing. | |
39 return Object::null(); | |
40 } | |
41 | |
42 GET_NON_NULL_NATIVE_ARGUMENT(Integer, start, arguments->NativeArgAt(0)); | |
43 GET_NON_NULL_NATIVE_ARGUMENT(Integer, id, arguments->NativeArgAt(1)); | |
44 GET_NON_NULL_NATIVE_ARGUMENT(String, phase, arguments->NativeArgAt(2)); | |
45 GET_NON_NULL_NATIVE_ARGUMENT(String, category, arguments->NativeArgAt(3)); | |
46 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(4)); | |
47 GET_NON_NULL_NATIVE_ARGUMENT(String, args, arguments->NativeArgAt(5)); | |
48 | |
49 int64_t pid = OS::ProcessId(); | |
50 int64_t tid = OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadTraceId()); | |
51 | |
52 char* event = OS::SCreate(zone, | |
53 "{\"name\":\"%s\",\"cat\":\"%s\",\"tid\":%" Pd64 ",\"pid\":%" Pd64 "," | |
54 "\"ts\":%" Pd64 ",\"ph\":\"%s\",\"id\":%" Pd64 ", \"args\":%s}", | |
55 name.ToCString(), | |
56 category.ToCString(), | |
57 tid, | |
58 pid, | |
59 start.AsInt64Value(), | |
60 phase.ToCString(), | |
61 id.AsInt64Value(), | |
62 args.ToCString()); | |
63 | |
64 // event was allocated in the zone and will be copied by AppendDartEvent. | |
65 recorder->AppendDartEvent(isolate, event); | |
66 | |
67 return Object::null(); | |
68 } | |
69 | |
70 | |
22 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { | 71 DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) { |
23 TimelineEventRecorder* recorder = Timeline::recorder(); | 72 TimelineEventRecorder* recorder = Timeline::recorder(); |
24 if (recorder == NULL) { | 73 if (recorder == NULL) { |
25 return Object::null(); | 74 return Object::null(); |
26 } | 75 } |
27 | 76 |
28 if (!isolate->GetDartStream()->Enabled()) { | 77 if (!isolate->GetDartStream()->Enabled()) { |
29 // Dart stream is not enabled for this isolate, do nothing. | 78 // Dart stream is not enabled for this isolate, do nothing. |
30 return Object::null(); | 79 return Object::null(); |
31 } | 80 } |
(...skipping 19 matching lines...) Expand all Loading... | |
51 duration, | 100 duration, |
52 args.ToCString()); | 101 args.ToCString()); |
53 | 102 |
54 // event was allocated in the zone and will be copied by AppendDartEvent. | 103 // event was allocated in the zone and will be copied by AppendDartEvent. |
55 recorder->AppendDartEvent(isolate, event); | 104 recorder->AppendDartEvent(isolate, event); |
56 | 105 |
57 return Object::null(); | 106 return Object::null(); |
58 } | 107 } |
59 | 108 |
60 } // namespace dart | 109 } // namespace dart |
OLD | NEW |