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