Crate fuchsia_inspect

source ·
Expand description


Components in Fuchsia may expose structured information about themselves conforming to the Inspect API. This crate is the core library for writing inspect data in Rust components.

For a comprehensive guide on how to start using inspect, please refer to the codelab.

Library concepts

There’s two types of inspect values: nodes and properties. These have the following characteristics:

  • A Node may have any number of key/value pairs called Properties.
  • A Node may have any number of children, which are also Nodes.
  • Properties and nodes are created under a parent node. Inspect is already initialized with a root node.
  • The key for a value in a Node is always a UTF-8 string, the value may be one of the supported types (a node or a property of any type).
  • Nodes and properties have strict ownership semantics. Whenever a node or property is created, it is written to the backing VMO and whenever it is dropped it is removed from the VMO.
  • Inspection is best effort, if an error occurs, no panic will happen and nodes and properties might become No-Ops. For example, when the VMO becomes full, any further creation of a property or a node will result in no changes in the VMO and a silent failure. However, mutation of existing properties in the VMO will continue to work.
  • All nodes and properties are thread safe.

Creating vs Recording

There are two functions each for initializing nodes and properties:

  • create_*: returns the created node/property and it’s up to the caller to handle its lifetime.
  • record_*: creates the node/property but doesn’t return it and ties its lifetime to the node where the function was called.

Lazy value support

Lazy (or dynamic) values are values that are created on demand, this is, whenever they are read. Unlike regular nodes, they don’t take any space on the VMO until a reader comes and requests its data.

There’s two ways of creating lazy values:

  • Lazy node: creates a child node of root with the given name. The callback returns a future for an Inspector whose root node is spliced into the parent node when read.
  • Lazy values: works like the previous one, except that all properties and nodes under the future root node node are added directly as children of the parent node.


Add the following to your component main:

use fuchsia_inspect::component;
use fuchsia_component::server::ServiceFs;
use inspect_runtime;

let mut fs = ServiceFs::new();
inspect_runtime::serve(component::inspector(), &mut fs)?;

// Now you can create nodes and properties anywhere!
let child = component::inspector().root().create_child("foo");
child.record_uint("bar", 42);


pub use testing::*;


Component inspection utilities
Health-checking inspect node.
Reading inspect data
Inspect stats node.


Inspect API Bool Property data type.
Inspect Bytes Property data type.
Inspect double array data type.
An exponential histogram property for double values.
A linear histogram property for double values.
Inspect double property type.
The parameters of an exponential histogram.
Root of the Inspect API. Through this API, further nodes can be created and inspect can be served.
Classic builder pattern object for constructing an Inspector.
Inspect int array data type.
An exponential histogram property for int values.
A linear histogram property for integer values.
Inspect int property data type.
Inspect Lazy Node data type. NOTE: do not rely on PartialEq implementation for true comparison. Instead leverage the reader.
The parameters of a linear histogram.
Inspect Node data type.
Statistics about the current inspect state.
Inspect String Property data type.
StringReference is a type that can be constructed and passed into the Inspect API as a name of a Node. If this is done, only one reference counted instance of the string will be allocated per Inspector. They can be safely used with LazyNodes.
Inspect uint array data type.
An exponential histogram property for uint values.
A linear histogram property for unsigned integer values.
Inspect uint property data type.
Holds a list of inspect types that won’t change.


Errors that Inspect API functions can return.


Directiory within the outgoing directory of a component where the diagnostics service should be added.


Trait implemented by all array properties providing common operations on arrays.
Trait implemented by all histogram properties providing common operations.
Trait implemented by all inspect types.
Trait allowing a Node to adopt any Inspect type as its child, removing it from the original parent’s tree.
Get the usable length of a type.
Trait implemented by numeric properties providing common operations.
Trait implemented by properties.


Generates a unique name that can be used in inspect nodes and properties that will be prefixed by the given prefix.