Flutter Engine
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/sys/inspect/cpp/component.h>
8 #include <lib/syslog/global.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"
14 #include "flutter/fml/trace_event.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.
25 static 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 
37 int main(int argc, const char** argv) {
38  async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
39 
40  // Create our component context which is served later.
41  auto context = sys::ComponentContext::Create();
43  auto build_info = dart_utils::RootInspectNode::CreateRootChild("build_info");
44  dart_utils::BuildInfo::Dump(build_info);
45 
46  dart::SetDartVmNode(std::make_unique<inspect::Node>(
48 
49  std::unique_ptr<trace::TraceProviderWithFdio> provider;
50  {
51  bool already_started;
52  // Use CreateSynchronously to prevent loss of early events.
53  trace::TraceProviderWithFdio::CreateSynchronously(
54  loop.dispatcher(), "dart_runner", &provider, &already_started);
55  }
56 
57 #if !defined(DART_PRODUCT)
58 #if defined(AOT_RUNTIME)
59  RegisterProfilerSymbols("pkg/data/dart_aot_runner.dartprofilersymbols", "");
60 #else
61  RegisterProfilerSymbols("pkg/data/dart_jit_runner.dartprofilersymbols", "");
62 #endif // defined(AOT_RUNTIME)
63 #endif // !defined(DART_PRODUCT)
64 
65  dart_utils::RunnerTemp runner_temp;
66  dart_runner::DartRunner runner(context.get());
67 
68  // Wait to serve until we have finished all of our setup.
69  context->outgoing()->ServeFromStartupInfo();
70 
71  loop.Run();
72  return 0;
73 }
static void RegisterProfilerSymbols(const char *symbols_path, const char *dso_name)
Definition: main.cc:25
#define FML_LOG(severity)
Definition: logging.h:65
static void Dump(inspect::Node &node)
int main(int argc, const char **argv)
Definition: main.cc:37
bool ReadFileToString(const std::string &path, std::string *result)
Definition: files.cc:56
#define FML_CHECK(condition)
Definition: logging.h:68
static void Initialize(sys::ComponentContext *context)
static inspect::Node CreateRootChild(const std::string &name)