| 1 | // Copyright (c) 2020, 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/globals.h" |
| 6 | #if defined(HOST_OS_MACOS) && defined(SUPPORT_TIMELINE) |
| 7 | |
| 8 | |
| 9 | #include "vm/log.h" |
| 10 | #include "vm/timeline.h" |
| 11 | |
| 12 | namespace dart { |
| 13 | |
| 14 | // Only available on iOS 12.0, macOS 10.14 or above |
| 15 | TimelineEventMacosRecorder::TimelineEventMacosRecorder() |
| 16 | : TimelineEventPlatformRecorder() {} |
| 17 | |
| 18 | TimelineEventMacosRecorder::~TimelineEventMacosRecorder() {} |
| 19 | |
| 20 | void TimelineEventMacosRecorder::OnEvent(TimelineEvent* event) { |
| 21 | if (event == NULL) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | #if defined(HOST_OS_SUPPORTS_SIGNPOST) |
| 26 | os_log_t log = event->stream_->macos_log(); |
| 27 | if (!os_signpost_enabled(log)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | const char* label = event->label(); |
| 32 | uint8_t _Alignas(16) buffer[64]; |
| 33 | buffer[0] = 0; |
| 34 | |
| 35 | switch (event->event_type()) { |
| 36 | case TimelineEvent::kInstant: { |
| 37 | _os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT, |
| 38 | OS_SIGNPOST_ID_EXCLUSIVE, label, "" , |
| 39 | buffer, sizeof(buffer)); |
| 40 | break; |
| 41 | } |
| 42 | case TimelineEvent::kBegin: { |
| 43 | _os_signpost_emit_with_name_impl( |
| 44 | &__dso_handle, log, OS_SIGNPOST_INTERVAL_BEGIN, |
| 45 | OS_SIGNPOST_ID_EXCLUSIVE, label, "" , buffer, sizeof(buffer)); |
| 46 | break; |
| 47 | } |
| 48 | case TimelineEvent::kEnd: { |
| 49 | _os_signpost_emit_with_name_impl( |
| 50 | &__dso_handle, log, OS_SIGNPOST_INTERVAL_END, |
| 51 | OS_SIGNPOST_ID_EXCLUSIVE, label, "" , buffer, sizeof(buffer)); |
| 52 | break; |
| 53 | } |
| 54 | case TimelineEvent::kAsyncBegin: { |
| 55 | _os_signpost_emit_with_name_impl( |
| 56 | &__dso_handle, log, OS_SIGNPOST_INTERVAL_BEGIN, event->AsyncId(), |
| 57 | label, "" , buffer, sizeof(buffer)); |
| 58 | break; |
| 59 | } |
| 60 | case TimelineEvent::kAsyncEnd: { |
| 61 | _os_signpost_emit_with_name_impl( |
| 62 | &__dso_handle, log, OS_SIGNPOST_INTERVAL_END, event->AsyncId(), label, |
| 63 | "" , buffer, sizeof(buffer)); |
| 64 | break; |
| 65 | } |
| 66 | case TimelineEvent::kCounter: { |
| 67 | const char* fmt = "%s" ; |
| 68 | Utils::SNPrint(reinterpret_cast<char*>(buffer), sizeof(buffer), fmt, |
| 69 | event->arguments()[0].value); |
| 70 | _os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT, |
| 71 | event->AsyncId(), label, fmt, buffer, |
| 72 | sizeof(buffer)); |
| 73 | break; |
| 74 | } |
| 75 | default: |
| 76 | break; |
| 77 | } |
| 78 | #endif // defined(HOST_OS_SUPPORTS_SIGNPOST) |
| 79 | } |
| 80 | |
| 81 | } // namespace dart |
| 82 | |
| 83 | #endif // defined(HOST_OS_MACOS) && defined(SUPPORT_TIMELINE) |
| 84 | |