Google is committed to advancing racial equity for Black communities. See how.

Extending the Inspect File Format

This document describes how to extend the Component Inspection File Format

Adding a new type

A total of 256 types are possible in the Inspect Format. This section describes how to add a new type and update all library implementations.

This section describes how to break down your change into multiple CLs:

Choose type number

View the type table in the Inspect file format, and choose an unused type number.

Update the documentation for your new type, and then submit this change for review.

Update the C++ reference implementation.

The examples in this section create a new type called "MyFoo."

Every change from this section goes into a single CL:

Set up

  1. Include tests fx set --with-base //garnet/packages/tests:zircon
  2. Build and repave between each modification fx build && fx pave -1
  3. Run tests. fx shell runtests --names inspect-test

Bitfield updates

This section describes how to define the bitfields for your new type.

Update /zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/block.h.

  1. Change BlockType to include your new type. For example: kMyFoo = #;

  2. If your type needs a new header (typically if it is not a VALUE):

    Define the header bitfields for your type with a struct. For example: struct MyFooBlockFields final : public BlockFields.

  3. If your type needs a new payload (it requires using the second 8 bytes of the block):

    Define the payload bitfields for your type with a struct. For example: struct MyFooBlockPayload final.

  4. If your type contains enums (such as format):

    Define a new enum at the top of block.h. For example: enum class MyFooBlockFormat : uint8_t.

Type wrapper declaration

This section describes how to declare a C++ RAII-style wrapper for your new type.

Type wrappers contain indices of blocks that are owned by the type. You are responsible for implementing operations on those blocks, including creation and deletion, in State action updates.

Update /zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/types.h.


  • If you can reuse an existing wrapper depending on the operations you need to support:
    1. If you need to support Add, Subtract, and Set: using MyFoo = internal::NumericProperty<T>, where T is the argument type to those operations.
    2. If you need to support Set: using MyFoo = internal::Property<T>, where T is the argument type to Set.
    3. If you need to support numeric operations on an array: using MyFood = internal::ArrayProperty<T>, where T is the argument type for slots in the array.
    4. If you need to support inserting to a histogram: using MyFoo = internal::{Linear,Expnential}Histogram<T>, where T is the argument to Insert.
  • If you cannot reuse an existing type:
    1. Create a new type wrapper. For example class MyFoo final.
    2. Ensure your class has internal::State as a friend class. Note: See class Link for a copyable starting point.

State action updates

The State class is the actual implementation for all operations on all types. This section describes how to implement the operations you will need to complete your wrapper implementation.

Update /zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/state.h:

  1. Update /zircon/system/ulib/inspect/include/lib/inspect/cpp/vmo/state.h:
    1. Add Create and Free methods. For example: MyFoo CreateMyFoo(<args>); void FreeMyFoo(MyFoo* property); where args typically includes name, parent, and some initial value.
    2. Add methods for each operation you need to support on your type. For example, if your type can be Set, void SetMyFoo(MyFoo* property, T), where T is the same type from your update to types.h.
  2. Update /zircon/system/ulib/inspect/vmo/
    1. Implement your new type's methods. The implementation varies between the different types. This section provides a high-level overview of what each method must do:
      • MyFoo CreateMyFoo(Args...) is responsible for allocating a number of blocks, setting their values, and returning them wrapped in a MyFoo. You may use a private constructor to create MyFoo from the BlockIndex objects it wraps. Various internal helpers exist to simplify this operation. See CreateIntProperty for an example.
      • void FreeMyFoo(MyFoo* property) is responsible for freeing all blocks wrapped by the MyFoo. There are sometimes particular ordering requirements or updates necessary for freeing blocks. See InnerFreeValue for an example of how values are freed.
      • Operations, such as void SetMyFoo(MyFoo* property, T value) change the value of blocks allocated to MyFoo to implement the operation. See SetIntProperty for an example.
      • Note:
      • Always lock the state before accessing any internal data, using std::lock_guard<std::mutex> lock(mutex_);
      • Always lock the buffer before making any modifications to blocks, using AutoGenerationIncrement gen(header_, heap_.get());

Implement the type wrapper

This section describes how to implement the wrapper methods declared previously.

  1. Update /zircon/system/ulib/inspect/vmo/
    • If you used an existing templated type, you need to override each method for your new base type T. For example, if you typed using MyFoo = internal::Property<T>, you will write: template<> void internal::Property<T>::OPERATION(...) { ... }
    • If you created your own type, simply create definitions for the methods you declared. You need to do the following:
      • Make your constructor call state_->CreateMyFoo(...);
      • Make your destructor call state_->FreeMyFoo(...);
      • Make your other methods call the corresponding implementation on State.
      • Have all of your constructors and methods check that state_ is not null before calling.

Implement the type reader

This section describes how to make your new type readable.

  1. Update /zircon/system/ulib/inspect/include/lib/inspect/cpp/hierarchy.h:
  2. Based on your type:
    • A value (child of Node):
      1. Update PropertyFormat enum with a new number for your type. This must be sequential in this specific enum and does not need to match the format type ordinal you chose.
      2. Create a new value type. For example, using MyFooValue = internal::Value\<T, static_cast<size_t>(PropertyFormat::kMyFoo)>;
      3. Update PropertyValue variant with the new value. Note: The index in fit::internal::variant must match the value of PropertyFormat.
    • Not a value: You need to make your own in-memory representation objects in the /zircon/system/ulib/inspect/include/lib/inspect/cpp/hierarchy.h file.
  3. Update the actual reader in /zircon/system/ulib/inspect/
    1. Update InnerScanBlocks to dispatch your type. If you are creating a new Property, you may only have to add your BlockType.
    2. If you need a custom parser, implement InnerParseMyFoo which takes a parent (if needed) and the pointer to the scanned block.

Implement tests

  1. Update /zircon/system/ulib/inspect/test/ with tests for your low-level operations.
  2. Update /zircon/system/ulib/inspect/test/ with tests for your high-level reader implementation.

Update Validator


Update Rust Library


Update Dart Library