Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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/syslog/cpp/log_settings.h>
9#include <lib/trace-provider/provider.h>
10#include <lib/trace/event.h>
11
12#include "dart_runner.h"
13#include "flutter/fml/logging.h"
15#include "logging.h"
16#include "platform/utils.h"
21#include "third_party/dart/runtime/include/dart_api.h"
22
23#if !defined(DART_PRODUCT)
24// Register native symbol information for the Dart VM's profiler.
25static void RegisterProfilerSymbols(const char* symbols_path,
26 const char* dso_name) {
27 std::string* symbols = new std::string();
28 if (dart_utils::ReadFileToString(symbols_path, symbols)) {
29 Dart_AddSymbols(dso_name, symbols->data(), symbols->size());
30 } else {
31 FML_LOG(ERROR) << "Failed to load " << symbols_path;
32 FML_CHECK(false);
33 }
34}
35#endif // !defined(DART_PRODUCT)
36
37int main(int argc, const char** argv) {
38 async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
39
40 // Set up logging.
41 fuchsia_logging::LogSettingsBuilder()
42 .WithTags({LOG_TAG})
43 .WithDispatcher(loop.dispatcher())
44 .BuildAndInitialize();
45
46 // Create our component context which is served later.
47 auto context = sys::ComponentContext::Create();
49 auto build_info = dart_utils::RootInspectNode::CreateRootChild("build_info");
51
52 dart::SetDartVmNode(std::make_unique<inspect::Node>(
54
55 std::unique_ptr<trace::TraceProviderWithFdio> provider;
56 {
57 bool already_started;
58 // Use CreateSynchronously to prevent loss of early events.
59 trace::TraceProviderWithFdio::CreateSynchronously(
60 loop.dispatcher(), "dart_runner", &provider, &already_started);
61 }
62
63#if !defined(DART_PRODUCT)
64#if defined(AOT_RUNTIME)
65 RegisterProfilerSymbols("pkg/data/dart_aot_runner.dartprofilersymbols", "");
66#else
67 RegisterProfilerSymbols("pkg/data/dart_jit_runner.dartprofilersymbols", "");
68#endif // defined(AOT_RUNTIME)
69#endif // !defined(DART_PRODUCT)
70
71 dart_runner::DartRunner runner(context.get());
72
73 // Wait to serve until we have finished all of our setup.
74 context->outgoing()->ServeFromStartupInfo();
75
76 loop.Run();
77 return 0;
78}
static void Dump(inspect::Node &node)
static void Initialize(sys::ComponentContext *context)
static inspect::Node CreateRootChild(const std::string &name)
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
char ** argv
Definition library.h:9
bool ReadFileToString(const std::string &path, std::string *result)
Definition files.cc:56
#define LOG_TAG
Definition logging.h:11
int main(int argc, const char **argv)
Definition main.cc:37
static void RegisterProfilerSymbols(const char *symbols_path, const char *dso_name)
Definition main.cc:25