Applet Contract¶
The applet contract is frozen, and sdk/include/caliper/abi.h is its single source. Any change to it is an epoch bump. Compatibility and epochs explains how the contract grows.
The contract uses C types only. It has no STL, exceptions, or third-party types. Each struct starts with struct_size. The CALIPER_EXPORT macro marks a function for export: __declspec(dllexport) on Windows and default visibility on the other platforms.
Types¶
CaliperAppletDescriptor¶
The description of an applet, which the applet gives to the host.
The id and version values match the manifest of the applet.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
The value of sizeof(CaliperAppletDescriptor) as the applet was built. |
abi_epoch |
uint32_t |
The ABI epoch of the applet. It must equal an epoch that the host supports. |
id |
const char* |
The identifier of the applet in reverse-DNS form. It matches the manifest. |
version |
const char* |
The version of the applet as a semantic version. It matches the manifest. |
name |
const char* |
The display name of the applet. |
summary |
const char* |
A one-line summary of the applet. |
tag |
const char* |
The tag that groups the applet in the host. |
required_services |
const char* const* |
The ids of the services that the applet needs, as a list that ends with NULL. The pointer may be NULL. |
api |
CaliperAppletAPI |
The entry points of the applet. |
CaliperAppletAPI¶
The entry points of an applet.
The host calls these functions on the instance that create returns. Future entry points are appended to the end of this struct and guarded by struct_size.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
The value of sizeof(CaliperAppletAPI) as the applet was built. |
create |
void* (*)(void) |
Return a new applet instance, or NULL on failure. |
destroy |
void (*)(void* self) |
Destroy the instance and free its memory. |
initialize |
bool (*)(void* self, const CaliperHost* host) |
Start the instance with the host, and return true on success. |
frame |
void (*)(void* self, const CaliperFrameInfo* info) |
Run the instance once for each frame, with the description of the frame in info. |
cleanup |
void (*)(void* self) |
Clean up the instance before the host destroys it. |
CaliperHost¶
The host, as the applet sees it.
The host is a service registry and not a struct of fields. An applet reads the identity of the host from this struct and gets every capability through get_service.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
The value of sizeof(CaliperHost) as the host built it. |
abi_epoch |
uint32_t |
The ABI epoch that this host speaks. |
host_version |
uint32_t |
The version of the host, packed as (major<<16)|(minor<<8)|patch. |
applet_data_dir |
const char* |
The per-applet sandbox directory, as a UTF-8 string. The host owns the string. |
get_service |
const void* (*)(const struct CaliperHost* host, const char* service_id) |
Return the service table for service_id, or NULL if the host has no such service. The pointer stays valid for the lifetime of the applet. An unknown id returns NULL and never causes undefined behavior. |
CaliperFrameInfo¶
The description of one frame, which the host passes to frame.
The fb_width and fb_height values are physical framebuffer pixels. ImGui coordinates are logical units, and the physical size equals the logical size times dpi_scale.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
The value of sizeof(CaliperFrameInfo) as the host built it. |
fb_width |
int32_t |
The width of the framebuffer in physical pixels. |
fb_height |
int32_t |
The height of the framebuffer in physical pixels. |
dpi_scale |
float |
The number of physical pixels for each logical unit. |
time_sec |
double |
The time since the start of the host in seconds. |
delta_sec |
double |
The time since the previous frame in seconds. |
Calls¶
Every epoch-3 applet exports exactly one symbol. The CALIPER_APPLET macro in caliper.hpp generates it, or you can write it by hand in C. The CALIPER_DESCRIPTOR_SYMBOL macro holds the name of the symbol. The header declares the symbol only in a comment, thus the generated tables do not list it.
| Call | Signature | Description |
|---|---|---|
caliper_applet_descriptor |
const CaliperAppletDescriptor* (void) |
Return the descriptor of the applet. |
The other calls are the entry points of the applet and the get_service call of the host.
| Call | Signature | Description |
|---|---|---|
CaliperHost.get_service |
const void* (const struct CaliperHost* host, const char* service_id) |
Return the service table for service_id, or NULL if the host has no such service. The pointer stays valid for the lifetime of the applet. An unknown id returns NULL and never causes undefined behavior. |
CaliperAppletAPI.create |
void* (void) |
Return a new applet instance, or NULL on failure. |
CaliperAppletAPI.destroy |
void (void* self) |
Destroy the instance and free its memory. |
CaliperAppletAPI.initialize |
bool (void* self, const CaliperHost* host) |
Start the instance with the host, and return true on success. |
CaliperAppletAPI.frame |
void (void* self, const CaliperFrameInfo* info) |
Run the instance once for each frame, with the description of the frame in info. |
CaliperAppletAPI.cleanup |
void (void* self) |
Clean up the instance before the host destroys it. |
The pointer from get_service stays valid for the lifetime of the applet. Future entry points are appended to CaliperAppletAPI and guarded by struct_size.
Ids¶
| Name | Value | Description |
|---|---|---|
CALIPER_ABI_EPOCH |
3 |
The epoch of this contract. Any change to the frozen contract bumps the epoch. |
CALIPER_DESCRIPTOR_SYMBOL |
"caliper_applet_descriptor" |
The name of the one symbol that every applet exports, as a string. |