dart-sdk/runtime/vm/timeline_macos.cc
Ryan Macnak 1ab217ac40 Reland "[vm] Forward dynamic events names to os_signposts as arguments."
Assume the embedder provides static strings for event labels.

TEST=Instruments
Bug: https://github.com/dart-lang/sdk/issues/49178
Change-Id: I40aa4996fed2b1230da64d182e6f172f60480fdf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251145
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-07-25 17:42:49 +00:00

81 lines
2.6 KiB
C++

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#if defined(DART_HOST_OS_MACOS) && defined(SUPPORT_TIMELINE)
#include "vm/log.h"
#include "vm/timeline.h"
namespace dart {
// Only available on iOS 12.0, macOS 10.14 or above
TimelineEventMacosRecorder::TimelineEventMacosRecorder()
: TimelineEventPlatformRecorder() {
Timeline::set_recorder_discards_clock_values(true);
}
TimelineEventMacosRecorder::~TimelineEventMacosRecorder() {}
void TimelineEventMacosRecorder::OnEvent(TimelineEvent* event) {
if (event == NULL) {
return;
}
#if defined(DART_HOST_OS_SUPPORTS_SIGNPOST)
os_log_t log = event->stream_->macos_log();
if (!os_signpost_enabled(log)) {
return;
}
const char* label = event->label();
bool is_static_label = event->stream_->has_static_labels();
uint8_t _Alignas(16) buffer[64];
buffer[0] = 0;
switch (event->event_type()) {
case TimelineEvent::kInstant:
if (is_static_label) {
_os_signpost_emit_with_name_impl(&__dso_handle, log, OS_SIGNPOST_EVENT,
OS_SIGNPOST_ID_EXCLUSIVE, label, "",
buffer, sizeof(buffer));
} else {
os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Event", "%s",
label);
}
break;
case TimelineEvent::kBegin:
case TimelineEvent::kAsyncBegin:
if (is_static_label) {
_os_signpost_emit_with_name_impl(
&__dso_handle, log, OS_SIGNPOST_INTERVAL_BEGIN, event->Id(), label,
"", buffer, sizeof(buffer));
} else {
os_signpost_interval_begin(log, event->Id(), "Event", "%s", label);
}
break;
case TimelineEvent::kEnd:
case TimelineEvent::kAsyncEnd:
if (is_static_label) {
_os_signpost_emit_with_name_impl(&__dso_handle, log,
OS_SIGNPOST_INTERVAL_END, event->Id(),
label, "", buffer, sizeof(buffer));
} else {
os_signpost_interval_end(log, event->Id(), "Event");
}
break;
case TimelineEvent::kCounter:
os_signpost_event_emit(log, OS_SIGNPOST_ID_EXCLUSIVE, "Counter", "%s=%s",
label, event->arguments()[0].value);
break;
default:
break;
}
#endif // defined(DART_HOST_OS_SUPPORTS_SIGNPOST)
}
} // namespace dart
#endif // defined(DART_HOST_OS_MACOS) && defined(SUPPORT_TIMELINE)