[fuchsia] Adds a singleton to access inspect root node. (flutter/engine#25745)
Bug: fxbug.dev/75281
This commit is contained in:
@@ -1373,6 +1373,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/inlines.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/logging.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/root_inspect_node.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/root_inspect_node.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/vmo.cc
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "logging.h"
|
||||
#include "platform/utils.h"
|
||||
#include "runtime/dart/utils/files.h"
|
||||
#include "runtime/dart/utils/root_inspect_node.h"
|
||||
#include "runtime/dart/utils/tempfs.h"
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
|
||||
@@ -37,11 +38,10 @@ int main(int argc, const char** argv) {
|
||||
|
||||
// Create our component context which is served later.
|
||||
auto context = sys::ComponentContext::Create();
|
||||
sys::ComponentInspector inspector(context.get());
|
||||
dart_utils::RootInspectNode::Initialize(context.get());
|
||||
|
||||
inspect::Node& root = inspector.inspector()->GetRoot();
|
||||
|
||||
dart::SetDartVmNode(std::make_unique<inspect::Node>(root.CreateChild("vm")));
|
||||
dart::SetDartVmNode(std::make_unique<inspect::Node>(
|
||||
dart_utils::RootInspectNode::CreateRootChild("vm")));
|
||||
|
||||
std::unique_ptr<trace::TraceProviderWithFdio> provider;
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "loop.h"
|
||||
#include "platform/utils.h"
|
||||
#include "runner.h"
|
||||
#include "runtime/dart/utils/root_inspect_node.h"
|
||||
#include "runtime/dart/utils/tempfs.h"
|
||||
|
||||
int main(int argc, char const* argv[]) {
|
||||
@@ -19,13 +20,12 @@ int main(int argc, char const* argv[]) {
|
||||
|
||||
// Create our component context which is served later.
|
||||
auto context = sys::ComponentContext::Create();
|
||||
sys::ComponentInspector inspector(context.get());
|
||||
|
||||
inspect::Node& root = inspector.inspector()->GetRoot();
|
||||
dart_utils::RootInspectNode::Initialize(context.get());
|
||||
|
||||
// We inject the 'vm' node into the dart vm so that it can add any inspect
|
||||
// data that it needs to the inspect tree.
|
||||
dart::SetDartVmNode(std::make_unique<inspect::Node>(root.CreateChild("vm")));
|
||||
dart::SetDartVmNode(std::make_unique<inspect::Node>(
|
||||
dart_utils::RootInspectNode::CreateRootChild("vm")));
|
||||
|
||||
std::unique_ptr<trace::TraceProviderWithFdio> provider;
|
||||
{
|
||||
|
||||
@@ -22,6 +22,8 @@ template("make_utils") {
|
||||
"logging.h",
|
||||
"mapped_resource.cc",
|
||||
"mapped_resource.h",
|
||||
"root_inspect_node.cc",
|
||||
"root_inspect_node.h",
|
||||
"tempfs.cc",
|
||||
"tempfs.h",
|
||||
"vmo.cc",
|
||||
@@ -39,6 +41,7 @@ template("make_utils") {
|
||||
"$fuchsia_sdk_root/pkg:fdio",
|
||||
"$fuchsia_sdk_root/pkg:memfs",
|
||||
"$fuchsia_sdk_root/pkg:sys_cpp",
|
||||
"$fuchsia_sdk_root/pkg:sys_inspect_cpp",
|
||||
"$fuchsia_sdk_root/pkg:syslog",
|
||||
"$fuchsia_sdk_root/pkg:trace",
|
||||
"$fuchsia_sdk_root/pkg:vfs_cpp",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2013 The Flutter 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 "root_inspect_node.h"
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
std::unique_ptr<sys::ComponentInspector> RootInspectNode::inspector_;
|
||||
std::mutex RootInspectNode::mutex_;
|
||||
|
||||
void RootInspectNode::Initialize(sys::ComponentContext* context) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!inspector_) {
|
||||
inspector_ = std::make_unique<sys::ComponentInspector>(context);
|
||||
}
|
||||
}
|
||||
|
||||
inspect::Node RootInspectNode::CreateRootChild(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return inspector_->inspector()->GetRoot().CreateChild(name);
|
||||
}
|
||||
|
||||
} // namespace dart_utils
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_ROOT_INSPECT_NODE_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_ROOT_INSPECT_NODE_H_
|
||||
|
||||
#include <lib/sys/inspect/cpp/component.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
// This singleton object offers a way to create a new inspect node under the
|
||||
// root node in a thread safe way.
|
||||
//
|
||||
// Usage notes:
|
||||
// RootInspectNode::Initialize() must be invoked once in the program's
|
||||
// main before trying to obtain a child node.
|
||||
class RootInspectNode {
|
||||
private:
|
||||
RootInspectNode() = default;
|
||||
~RootInspectNode() = default;
|
||||
|
||||
public:
|
||||
// Initializes the underlying component inspector. Must be invoked at least
|
||||
// once before calling CreateRootChild().
|
||||
static void Initialize(sys::ComponentContext* context);
|
||||
|
||||
// Creates an inspect node which is a child of the component's root inspect
|
||||
// node with the provided |name|.
|
||||
static inspect::Node CreateRootChild(const std::string& name);
|
||||
|
||||
private:
|
||||
static std::unique_ptr<sys::ComponentInspector> inspector_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace dart_utils
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_ROOT_INSPECT_NODE_H_
|
||||
Reference in New Issue
Block a user