hellopics_stats_t
structure:
typedef struct hellopics_stats_s { uint32_t msgs_sent; // total number of messages sent to PICs uint32_t msgs_received; // total number of messages received from PICs uint32_t msgs_missed; // total number of messages expected but never received from PICs uint32_t msgs_badorder; // total number of messages received out of order } hellopics_stats_t;
All statistics tracking is performed in the management component, as follows.
The management component increments msgs_sent
in its sendHelloMessage()
function. This happens right after sending a HELLO either to the data component or to the control component.
Before sending a message in the same function, the management component increments msgs_missed
if the received
variable was not set:
if(!received) { ++hellopics_stats.msgs_missed; }
After the message is sent, the function sets received
to FALSE
.
received
is set to TRUE
in the management component's receive_message()
handler at the same time it increments msgs_received
.
hello_seq_num
is set to 0 when the management component calls init_server()
to initialize the server connection, and incremented whenever the management component sends a message.
The function checks that the sequence number from the message matches the number the function currently stores. If not, it increments msgs_badorder
and leaves received
set to FALSE
.
case MSG_HELLO: ... if(helloNum == hello_seq_num) { ++hellopics_stats.msgs_received; received = TRUE; } else { ++hellopics_stats.msgs_badorder; }
hellopics-mgmt_ui.c
file contains the menu structure for the show sync hellopics statistics
command. (For details about how to code the menu structure, see Creating the Commands Menu Array.) The menu executes the hellopics_show_stats()
function, which executes ODL calls to display the statistics.
static const parse_menu_t show_sync_hellopics_menu[] = { { "statistics", NULL, 0, NULL, hellopics_show_stats }, { NULL, NULL, 0, NULL, NULL } };
The ODL was written as follows to describe the command output.
dtd hellopics; tag hellopics-statistics { flag root; tag cycles-sent { type int; help "The number of messages sent"; description "The number of cycle messages sent to the PIC applications"; formal-name "Sent Message"; } tag cycles-received { type int; help "The number of messages received"; description "The number of cycle messages received back from the PIC applications"; formal-name "Received Messages"; } tag cycles-missed { type int; help "The number of messages dropped somewhere"; description "The number of cycle messages dropped somewhere in the cycle"; formal-name "Dropped Messages"; } tag cycles-out-of-order { type int; help "The number of messages received out-of-order"; description "The number of messages received out-of-order (also missed)"; formal-name "Missed Messages Received Out of Order"; } format stats-format { header "Hello PICs Cycled-Message Statistics:\\n"; indent 2; line { field cycles-sent flag leading colon; } line { field cycles-received flag leading colon; } line { field cycles-missed flag leading colon; } line { field cycles-out-of-order flag leading colon; } } }
The calls in hellopics_show_stats()
access the compiled ODL to format and display the command output.
XML_OPEN()
emits an opening XML tag.XML_ELT()
tags the XML element being described as a format statement followed by arguments.XML_CLOSE()
emits a closing XML tag.ODCI_
to the tag names.
static int32_t hellopics_show_stats (mgmt_sock_t *msp, parse_status_t *csb __unused, char *unparsed __unused) { XML_OPEN(msp, ODCI_HELLOPICS_STATISTICS); XML_ELT(msp, ODCI_CYCLES_SENT, "%d", hellopics_stats.msgs_sent); XML_ELT(msp, ODCI_CYCLES_RECEIVED, "%d", hellopics_stats.msgs_received); XML_ELT(msp, ODCI_CYCLES_MISSED, "%d", hellopics_stats.msgs_missed); XML_ELT(msp, ODCI_CYCLES_OUT_OF_ORDER, "%d", hellopics_stats.msgs_badorder); XML_CLOSE(msp, ODCI_HELLOPICS_STATISTICS); return 0; }
For more information about ODL, see the programming task Creating a User Interface with DDL and ODL and the ODL Programmer's Guide included with this documentation set.