forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing_controller.cc
51 lines (41 loc) · 1.5 KB
/
tracing_controller.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 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/shell/common/tracing_controller.h"
#include <string>
#include "flutter/common/threads.h"
#include "flutter/fml/trace_event.h"
#include "flutter/runtime/dart_init.h"
#include "flutter/shell/common/shell.h"
#include "lib/fxl/logging.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
namespace shell {
TracingController::TracingController() : tracing_active_(false) {
blink::SetEmbedderTracingCallbacks(
std::unique_ptr<blink::EmbedderTracingCallbacks>(
new blink::EmbedderTracingCallbacks([this]() { StartTracing(); },
[this]() { StopTracing(); })));
}
TracingController::~TracingController() {
blink::SetEmbedderTracingCallbacks(nullptr);
}
static void AddTraceMetadata() {
blink::Threads::Gpu()->PostTask([]() { Dart_SetThreadName("gpu_thread"); });
blink::Threads::UI()->PostTask([]() { Dart_SetThreadName("ui_thread"); });
blink::Threads::IO()->PostTask([]() { Dart_SetThreadName("io_thread"); });
blink::Threads::Platform()->PostTask(
[]() { Dart_SetThreadName("platform_thread"); });
}
void TracingController::StartTracing() {
if (tracing_active_)
return;
tracing_active_ = true;
AddTraceMetadata();
}
void TracingController::StopTracing() {
if (!tracing_active_) {
return;
}
tracing_active_ = false;
}
} // namespace shell