auto component_context = sys::ComponentContext::Create();
// ...
loop.Run();
```
This sets up an async loop, creates a `ComponentContext` wrapping handles provided by the runtime, and then runs that loop following some other initialization work.
**Change your initialization code to look like the following:**
> Note: You will need to `#include <lib/inspect/component.h>`
You are now using Inspect! To add some data and see it in action, try adding the following:
```
// Important: Make sure to hold on to hello_world_property and don't let it go out of scope.
auto hello_world_property = root_node.CreateStringProperty("hello", "world");
```
See [Viewing Inspect Data](#viewing-inspect-data) below to view what you are now exporting.
See [Supported Data Types](#supported-data-types) for a full list of data types you can try.
Want to test your Inspect integration? Include [testing/inspect.h](/garnet/public/lib/inspect/testing/inspect.h)
in your unit test for a full set of matchers. See [this example](/garnet/public/lib/inspect/tests/inspect_vmo_unittest.cc)
of how it is used.
Read on to learn how Inspect is meant to be used in C++.
#### Dynamic Value Support
Certain features, such as LazyProperty, LazyMetric, and ChildrenCallback are deprecated, but a replacement is on the way (CF-761). If you determine that you need one of these data types, you may use the deprecated API by replacing the setup code with the following:
```
// Legacy work required to expose an inspect hierarchy over FIDL.
Now that you have a `root_node` you may start building your hierarchy. This section describes some important concepts and patterns to help you get started.
* A Node may have any number of key/value pairs called **Values**.
* A numeric Value is called a **Metric** and a non-numeric Value is called a **Property**.
* A Node may have any number of children, which are also Nodes.
The code above gives you access to a single node named "root". `hello_world_property` is a Property that contains a string value (aptly called a **StringProperty**).
* Values and Nodes are created under a parent Node.
Class `Node` has creator methods for every type of supported value. `hello_world_property` was created using `CreateStringProperty`. You could create a child under the root node by calling `root_node.CreateChild("child name")`. Note that names must always be UTF-8 strings.
* Values and Nodes have strict ownership semantics.
`hello_world_property` owns the Property. When it is destroyed (goes out of scope) the underlying Property is deleted and no longer present in your component's Inspect output. This is true for Metrics and child Nodes as well.
* Inspection is best-effort.
Due to space limitations, the Inspect library may be unable to satisfy a `Create` request. This error is not surfaced to your code: you will receive a Node/Metric/Property object for which the methods are no-ops.
* Pattern: Pass in child Nodes to child objects.
It is useful to add an `inspect::Node` argument to the constructors for your own classes. The parent object, which should own its own `inspect::Node`, may then pass in the result of `CreateChild(...)` to its children when they are constructed:
> Rust support for inspect is currently in development.
>
> TODO(crjohns,miguelfrde)
## Dart
> Dart support for inspect is currently in development.
>
> TODO(cphoenix)
# Viewing Inspect Data
You can use the [`iquery`](iquery.md) tool to view the Inspect data you exported from your component by looking through the Hub.
This section assumes you have SSH access to your running Fuchsia system and that you started running your component. We will use the name `my_component.cmx` as a placeholder for the name of your component.
## Find your Inspect endpoint
Try the following:
```
# This prints all Inspect endpoints on the system.
$ iquery --find /hub
# This filters the above list to only print your component.
$ iquery --find /hub | grep my_component.cmx
```
> Under the listed directories you will see some paths including "system\_objects." This Inspect data is placed there by the Component Runtime itself.
Your component's endpoint will be listed as `<path>/my_component.cmx/<id>/out/objects/root.inspect`.
> Note: If you followed [Dynamic Value Support](#dynamic-value-support) above, "root.inspect" will be missing.
## Read your Inspect data
Navigate to the `out/objects` directory that was printed above, and run:
```
$ iquery --recursive root.inspect
# OR, if you used Dynamic Values:
$ iquery --recursive .
```
This will print out the following if you followed the suggested steps above:
```
root:
hello = world
```
# Supported Data Types
Type | Description | Notes
-----|-------------|-------
IntMetric | A metric containing a signed 64-bit integer. | All Languages
UIntMetric | A metric containing an unsigned 64-bit integer. | Not supported in Dart
DoubleMetric | A metric containing a double floating-point number. | All Languages
{Int,Double,UInt}Array | An array of metric types, includes typed wrappers for various histograms. | Same language support as base metric type
StringProperty | A property with a UTF-8 string value. | All Languages
ByteVectorProperty | A property with an arbitrary byte value. | All Languages
Node | A node under which metrics, properties, and more nodes may be nested. | All Languages
LazyMetric | A metric which dynamically sets its value as the result of a callback. | DEPRECATED: C++ Only
LazyProperty | A property which dynamically sets its value as the result of a callback. | DEPRECATED: C++ Only
ChildrenCallback | A callback that dynamically injects children into a Node on demand. | DEPRECATED: C++ Only
Link | Instantiates a complete tree of Nodes dynamically. | IN PROGRESS(CF-761): This will replace Lazy metrics, properties, and children