op_stat_obj_reg()
Abstract
Returns a handle that can be used to write a link, path, module or submodule statistic (local only).
Syntax
op_stat_obj_reg (group_dot_stat_name, obj_id, index)
| Argument | Type | Description |
|---|---|---|
group_dot_stat_name |
const char* |
group and name of statistic for which a handle is to be obtained, separated by a period. |
obj_id |
Objid |
ID of the object containing the statistic to be registered. |
index |
int |
numeric index of the statistic-of-interest, or OPC_STAT_INDEX_NONE if the statistic has no dimension. See Table 79 “Statistic Index Symbolic Constants“ on page 24. |
Return Type
Stathandle
Statistic handle that can be used to call the KPs op_stat_write() and op_stat_write_t().
Example
count = op_topo_assoc_count (self, OPC_TOPO_ASSOC_IN, OPC_OBJMTYPE_LINK);
if (count != 1)
op_sim_end ("Only one link should be connected to packet generator in this model",
"", "", "", "");
objid = op_topo_assoc (self, OPC_TOPO_ASSOC_IN, OPC_OBJMTYPE_LINK, 0);
link_stat = op_stat_obj_reg ("Test.Non-Dimensional Counter", objid,
OPC_STAT_INDEX_NONE);
for (j=0; j < 4; j++)
{
link_dim_stat [j] = op_stat_obj_reg ("Test.Dimensional Counter", objid, j);
}
/* rest of original pksw code */
address_dist = op_dist_load ("uniform_int", 0, 3);
ete_gsh = op_stat_reg ("ETE delay", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
Details
This procedure is similar to op_stat_reg(); the main differences are that this procedure allows you to access the statistics of any object, using any form of executable code (such as pipeline stages and external code), and that only local statistics are supported.
The Simulation Kernel administers global and local statistics centrally. A group, name, index, type, and output vector are maintained for each statistic. The user specifies the group, name, and index of the statistic when it is first registered with op_stat_obj_reg(). Subsequent calls to this KP with a group and name already registered will “rendezvous” with the statistic created during the earlier registration and the same handle is returned. This allows multiple processes to access the same statistic, provided they have a mechanism to synchronize on the name. Processes within the same module can rendezvous on the same local statistic. Any process can rendezvous on the same global statistic.
Dimensioned statistics provide a bank of output statistics. A Stathandle refers to the element of the bank specified by the index. Undimensioned statistics require the symbolic constant OPC_STAT_INDEX_NONE to be used for the index value.
Registration of a statistic involves a search through the set of existing statistics based on the specified name and group. To improve performance, a user should register a statistic only once and cache the resulting statistic handle (i.e., in a state variable) for later use.
Purpose
Statistic registration enables multiple processes to share a common output vector in which to record simulation metrics. By using registration to obtain access to the statistic, processes can coordinate on the name of the statistic. This avoids conflicts between models that are developed independently. This function returns a statistic handle, which is required to write new values to the statistic with the KPs op_stat_write() and op_stat_write_t().
Errors
- Program Abort: Segmentation violation. (due to an invalid or malformed
stat_nameargument) - Recoverable Error: Unable to register stat (
<stat_name>). (due to an undeclared statistic) - Recoverable Error: Unable to register stat (
<stat_name>). (due to a lack of available memory) - Program Abort: KP requires process context.
- Recoverable Error: Statistic index (
<stat_index>) is out-of-range.
Reference
- Use the KP op_stat_reg() to access a node or module statistic from within a process model
- Use the KP op_stat_write() to write a value to an output statistic, tagged with the current simulation time
- Use the KP op_stat_write_t() to write a value to an output statistic, tagged with a specified simulation time
- Use the KP op_stat_scalar_write() to write a value to a scalar statistic