Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Data Structures | Functions
stats.c File Reference

Functions for collecting parsing statistics. More...

#include "./apg.h"
#include <stdio.h>
#include <time.h>
#include "./lib.h"
#include "./parserp.h"
Include dependency graph for stats.c:

Go to the source code of this file.

Data Structures

struct  node_stat
 Holds the statistics for a single node. More...
 
struct  stats
 The totality of all node statistics. More...
 
struct  stats_ctx
 The statistics object context. More...
 

Functions

void * vpStatsCtor (void *vpParserCtx)
 The statistics object constructor. More...
 
void vStatsHit (void *vpCtx, const opcode *spOp, aint uiState)
 Collects the statistics for a single node hit. More...
 
void vStatsToHtml (void *vpCtx, const char *cpMode, const char *cpFileName)
 Generates an HTML page displaying the node hit statistics. More...
 
void vStatsToAscii (void *vpCtx, const char *cpMode, const char *cpFileName)
 Display the statistics in ASCII format. More...
 

Detailed Description

Functions for collecting parsing statistics.

As the parser traverses the syntax tree, these functions collect detailed counts of the tree node hits. Hit counts are kept for each individual operator node type and each hit type (ID_MATCH, ID_NOMATCH). For the rule name (RNM) and User-Defined Terminal (UDT) nodes, the hit counts are further refined by rule/UDT name.

Definition in file stats.c.

Function Documentation

◆ vpStatsCtor()

void* vpStatsCtor ( void *  vpParserCtx)

The statistics object constructor.

  • Note 1. There is no corresponding destructor. This object is destroyed by the parent parser's destructor.
  • Note 2. There is no reset. If the parent parser is run multiple times the statistics will accumulate for the total of all runs.
    Parameters
    vpParserCtxPointer to the parent parser's context. If not valid the application will silently exit with a BAD_CONTEXT exit code.
    Returns
    Pointer to the statistics object's context.

Definition at line 113 of file stats.c.

◆ vStatsHit()

void vStatsHit ( void *  vpCtx,
const opcode *  spOp,
aint  uiState 
)

Collects the statistics for a single node hit.

This function is called only by the parent parser via the macro STATS_HIT.

Parameters
vpCtxPointer to a valid statistics context returned from vpStatsCtor() If not valid the application will silently exit with a BAD_CONTEXT exit code.
spOpPointer to the opcode of the current node.
uiStateThe node state (ID_MATCH or ID_NOMATCH)
Returns
void

Definition at line 156 of file stats.c.

◆ vStatsToAscii()

void vStatsToAscii ( void *  vpCtx,
const char *  cpMode,
const char *  cpFileName 
)

Display the statistics in ASCII format.

Parameters
vpCtxPointer to a valid statistics context returned from vpStatsCtor() If not valid the application will silently exit with a BAD_CONTEXT exit code.
cpModeName of the display mode.
  • "alphabetical" (or any string beginning with "a" or "A"), rule/udt nodes arranged alphabetically
  • "hit count" (or any string beginning with "h" or "H"), rule/udt nodes arranged descending on hit count
  • defaults to "hit count" if mode is NULL or unrecognized as either of above.
cpFileNameName of the file to write the HTML page to. If NULL, writes to stdout.

Definition at line 412 of file stats.c.

◆ vStatsToHtml()

void vStatsToHtml ( void *  vpCtx,
const char *  cpMode,
const char *  cpFileName 
)

Generates an HTML page displaying the node hit statistics.

Parameters
vpCtxPointer to a valid statistics context returned from vpStatsCtor() If not valid the application will silently exit with a BAD_CONTEXT exit code.
cpModeName of the display mode.
  • "alphabetical" (or any string beginning with "a" or "A"), rule/udt nodes arranged alphabetically
  • "hit count" (or any string beginning with "h" or "H"), rule/udt nodes arranged descending on hit count
  • defaults to "hit count" if mode is NULL or unrecognized as either of above.
cpFileNameName of the file to write the HTML page to. If NULL, writes to stdout.

Definition at line 246 of file stats.c.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.