Files
sdk/runtime/vm/timeline_linux.cc
T
Zach Anderson f407419d0a [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_
This relands https://dart-review.googlesource.com/c/sdk/+/205633
but without renaming TARGET_OS_IPHONE to DART_TARGET_OS_IPHONE.
It also changes uses of TARGET_OS_IOS to
DART_TARGET_OS_MACOS_IOS to be consistent with the rest of the
VM.

TargetConditionals.h for XCode 13 defines several
TARGET_OS_* preprocessor symbols that confuse the
Dart build. There is probably a more targeted fix
for this, but renaming the symbols that Dart uses
will also prevent this problem if more symbols
are added to the platform headers in the future.

See: https://github.com/dart-lang/sdk/issues/46499

TEST=It builds.

Change-Id: Ie775c19dd23cfdf5f65e5ebc6ee4ec3a561676fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205860
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2021-07-02 19:06:45 +00:00

119 lines
3.5 KiB
C++

// Copyright (c) 2017, 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_LINUX) && defined(SUPPORT_TIMELINE)
#include <errno.h>
#include <fcntl.h>
#include <cstdlib>
#include "platform/atomic.h"
#include "platform/signal_blocker.h"
#include "vm/isolate.h"
#include "vm/json_stream.h"
#include "vm/lockers.h"
#include "vm/log.h"
#include "vm/object.h"
#include "vm/service_event.h"
#include "vm/thread.h"
#include "vm/timeline.h"
namespace dart {
DECLARE_FLAG(bool, trace_timeline);
static int OpenTraceFD() {
const char* kSystraceDebugPath = "/sys/kernel/debug/tracing/trace_marker";
const char* kSystracePath = "/sys/kernel/tracing/trace_marker";
int fd = TEMP_FAILURE_RETRY(::open(kSystracePath, O_WRONLY));
if (fd < 0) {
fd = TEMP_FAILURE_RETRY(::open(kSystraceDebugPath, O_WRONLY));
}
if (fd < 0 && FLAG_trace_timeline) {
OS::PrintErr("TimelineEventSystraceRecorder: Could not open `%s` or `%s`\n",
kSystraceDebugPath, kSystracePath);
}
return fd;
}
TimelineEventSystraceRecorder::TimelineEventSystraceRecorder()
: TimelineEventPlatformRecorder(), systrace_fd_(OpenTraceFD()) {}
TimelineEventSystraceRecorder::~TimelineEventSystraceRecorder() {
if (systrace_fd_ >= 0) {
close(systrace_fd_);
}
}
intptr_t TimelineEventSystraceRecorder::PrintSystrace(TimelineEvent* event,
char* buffer,
intptr_t buffer_size) {
ASSERT(buffer != NULL);
ASSERT(buffer_size > 0);
buffer[0] = '\0';
intptr_t length = 0;
int64_t pid = OS::ProcessId();
switch (event->event_type()) {
case TimelineEvent::kBegin: {
length = Utils::SNPrint(buffer, buffer_size, "B|%" Pd64 "|%s", pid,
event->label());
break;
}
case TimelineEvent::kEnd: {
length = Utils::SNPrint(buffer, buffer_size, "E");
break;
}
case TimelineEvent::kCounter: {
if (event->arguments_length() > 0) {
// We only report the first counter value.
length = Utils::SNPrint(buffer, buffer_size, "C|%" Pd64 "|%s|%s", pid,
event->label(), event->arguments()[0].value);
}
break;
}
case TimelineEvent::kAsyncBegin: {
length = Utils::SNPrint(buffer, buffer_size, "S|%" Pd64 "|%s|%" Pd64 "",
pid, event->label(), event->AsyncId());
break;
}
case TimelineEvent::kAsyncEnd: {
length = Utils::SNPrint(buffer, buffer_size, "F|%" Pd64 "|%s|%" Pd64 "",
pid, event->label(), event->AsyncId());
break;
}
default:
// Ignore event types that we cannot serialize to the Systrace format.
break;
}
return length;
}
void TimelineEventSystraceRecorder::OnEvent(TimelineEvent* event) {
if (event == NULL) {
return;
}
if (systrace_fd_ < 0) {
return;
}
// Serialize to the systrace format.
const intptr_t kBufferLength = 1024;
char buffer[kBufferLength];
const intptr_t event_length = PrintSystrace(event, &buffer[0], kBufferLength);
if (event_length > 0) {
ssize_t result;
// Repeatedly attempt the write while we are being interrupted.
do {
result = write(systrace_fd_, buffer, event_length);
} while ((result == -1L) && (errno == EINTR));
}
}
} // namespace dart
#endif // defined(DART_HOST_OS_LINUX) && !defined(PRODUCT)