Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Statistics Parser

The statistics parser in Yuneta handles requests for retrieving and managing statistics from a GObj. It operates by collecting attributes marked with specific statistical flags (SDF_STATS, SDF_RSTATS, and SDF_PSTATS) and providing a structured way to query, reset, or persist these attributes.

The statistics parser integrates with the gobj_stats API, dynamically selecting between a global parser or a GClass-specific mt_stats method if defined.

json_t *gobj_stats(hgobj gobj, const char *stats, json_t *kw, hgobj src);

Source code in:


How the Internal Statistics Parser Works

1. Attribute Collection

When gobj_stats() is called:

2. Querying Statistics

3. Resetting Statistics

The internal global parser includes a special name, __reset__:

4. Persistence of Statistics

Attributes marked with SDF_PSTATS serve dual purposes:

5. Custom GClass Handling


Flags Relevant to Statistics

FlagDescription
SDF_STATSMarks the attribute as a statistic to be retrieved by the statistics parser.
SDF_RSTATSIndicates that the attribute is a resettable statistic. Can be reset via __reset__.
SDF_PSTATSCombines SDF_STATS with persistence. The attribute is saved as a persistent statistic.

API for Statistics

APIDescription
gobj_stats()Retrieve or reset statistics for a GObj.
ParameterDescription
gobjThe GObj instance for which statistics are being requested.
statsThe name of the statistic to retrieve, or __reset__ to reset all resettable statistics.
kwAdditional parameters for the statistics request.
srcThe source GObj sending the statistics request.

Workflow for gobj_stats()

  1. Receiving a Statistics Request:

    • A request is sent to a GObj using gobj_stats().

    • The stats and kw parameters define the requested statistics and additional options.

  2. Attribute Collection:

    • The parser collects attributes marked with SDF_STATS, SDF_RSTATS, and SDF_PSTATS.

  3. Parsing and Validation:

    • If a specific statistic name is provided, its value is returned.

    • If no name is provided, all SDF_STATS attributes are returned.

  4. Custom or Global Handling:

    • If the GClass defines mt_stats, it is invoked for custom processing.

    • Otherwise, the global parser processes the request.

  5. Resetting Statistics:

    • If __reset__ is passed, all attributes marked with SDF_RSTATS are reset.


Benefits of the Statistics Parser


Use Cases

1. Monitoring and Reporting

Retrieve runtime statistics for performance monitoring or system diagnostics.

2. Dynamic Configuration

Integrate with external systems to query or modify statistical attributes dynamically.

3. State Management

Reset runtime statistics programmatically to maintain operational consistency.