提交 f9c86cdd 编写于 作者: C Chinmay Garde 提交者: GitHub

Add a temporary engine systrace logger till the Dart timeline learns how to...

Add a temporary engine systrace logger till the Dart timeline learns how to log to systrace. (#2978)
上级 ce36db67
......@@ -31,6 +31,8 @@ source_set("common") {
"shell.h",
"switches.cc",
"switches.h",
"systrace_logger.cc",
"systrace_logger.h",
"tracing_controller.cc",
"tracing_controller.h",
"ui/animator.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/sky/shell/systrace_logger.h"
#include "lib/ftl/files/eintr_wrapper.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
namespace sky {
namespace shell {
static const size_t kBufferSize = 256;
SystraceLogger::SystraceLogger()
: trace_fd_(HANDLE_EINTR(
::open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY))),
pid_(getpid()) {}
SystraceLogger::~SystraceLogger() {
IGNORE_EINTR(::close(trace_fd_));
}
void SystraceLogger::TraceBegin(const char* label) const {
char buffer[kBufferSize];
int buffer_written = snprintf(buffer, sizeof(buffer), "B|%d|%s", pid_, label);
if (buffer_written <= 0 || buffer_written > kBufferSize) {
return;
}
HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}
void SystraceLogger::TraceEnd() const {
HANDLE_EINTR(::write(trace_fd_, "E", 1));
}
void SystraceLogger::TraceCount(const char* label, int count) const {
char buffer[kBufferSize];
int buffer_written =
snprintf(buffer, sizeof(buffer), "C|%d|%s|%d", pid_, label, count);
if (buffer_written <= 0 || buffer_written > kBufferSize) {
return;
}
HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}
} // namespace shell
} // namespace sky
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SKY_SHELL_SYSTRACE_LOGGER_H_
#define FLUTTER_SKY_SHELL_SYSTRACE_LOGGER_H_
#include "lib/ftl/macros.h"
#include <sys/types.h>
namespace sky {
namespace shell {
class SystraceLogger {
public:
SystraceLogger();
~SystraceLogger();
void TraceBegin(const char* label) const;
void TraceEnd() const;
void TraceCount(const char* label, int count) const;
private:
int trace_fd_;
int pid_;
FTL_DISALLOW_COPY_AND_ASSIGN(SystraceLogger);
};
} // namespace shell
} // namespace sky
#endif // FLUTTER_SKY_SHELL_SYSTRACE_LOGGER_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册