Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <lib/async-loop/cpp/loop.h>
6#include <lib/async-loop/default.h>
7#include <lib/inspect/component/cpp/component.h>
8#include <lib/trace-provider/provider.h>
9#include <lib/trace/event.h>
10
11#include "dart_runner.h"
12#include "flutter/fml/logging.h"
13#include "flutter/fml/platform/fuchsia/log_interest_listener.h"
14#include "flutter/fml/platform/fuchsia/log_state.h"
15#include "flutter/fml/trace_event.h"
16#include "logging.h"
17#include "platform/utils.h"
22#include "third_party/dart/runtime/include/dart_api.h"
23
24#if !defined(DART_PRODUCT)
25// Register native symbol information for the Dart VM's profiler.
26static void RegisterProfilerSymbols(const char* symbols_path,
27 const char* dso_name) {
28 std::string* symbols = new std::string();
29 if (dart_utils::ReadFileToString(symbols_path, symbols)) {
30 Dart_AddSymbols(dso_name, symbols->data(), symbols->size());
31 } else {
32 FML_LOG(ERROR) << "Failed to load " << symbols_path;
33 FML_CHECK(false);
34 }
35}
36#endif // !defined(DART_PRODUCT)
37
38int main(int argc, const char** argv) {
39 async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
40
41 // Setup logging.
43 fml::LogInterestListener listener(fml::LogState::Default().TakeClientEnd(),
44 loop.dispatcher());
46
47 // Create our component context which is served later.
48 auto context = sys::ComponentContext::Create();
50 auto build_info = dart_utils::RootInspectNode::CreateRootChild("build_info");
52
53 dart::SetDartVmNode(std::make_unique<inspect::Node>(
55
56 std::unique_ptr<trace::TraceProviderWithFdio> provider;
57 {
58 bool already_started;
59 // Use CreateSynchronously to prevent loss of early events.
60 trace::TraceProviderWithFdio::CreateSynchronously(
61 loop.dispatcher(), "dart_runner", &provider, &already_started);
62 }
63
64#if !defined(DART_PRODUCT)
65#if defined(AOT_RUNTIME)
66 RegisterProfilerSymbols("pkg/data/dart_aot_runner.dartprofilersymbols", "");
67#else
68 RegisterProfilerSymbols("pkg/data/dart_jit_runner.dartprofilersymbols", "");
69#endif // defined(AOT_RUNTIME)
70#endif // !defined(DART_PRODUCT)
71
72 dart_runner::DartRunner runner(context.get());
73
74 // Wait to serve until we have finished all of our setup.
75 context->outgoing()->ServeFromStartupInfo();
76
77 loop.Run();
78 return 0;
79}
static void Dump(inspect::Node &node)
static void Initialize(sys::ComponentContext *context)
static inspect::Node CreateRootChild(const std::string &name)
void SetTags(const std::initializer_list< std::string > &tags)
Definition log_state.cc:56
static LogState & Default()
Definition log_state.cc:61
DART_EXPORT void Dart_AddSymbols(const char *dso_name, void *buffer, intptr_t buffer_size)
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
bool ReadFileToString(const std::string &path, std::string *result)
Definition files.cc:56
void SetDartVmNode(std::unique_ptr< inspect::Node > node)
Definition main.py:1
#define LOG_TAG
Definition logging.h:11
static void RegisterProfilerSymbols(const char *symbols_path, const char *dso_name)
Definition main.cc:26
#define ERROR(message)