Tracking and Displaying Application Statistics

As introduced in Application Setup, this example tracks statistics in the 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) {

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.

                     if(helloNum == hello_seq_num) {
                         received = TRUE;
                     } else {

How Statistics Are Communicated to the UI

The 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.

The ODL compiler prepends ODCI_ to the tag names.

static int32_t
hellopics_show_stats (mgmt_sock_t *msp,
                        parse_status_t *csb __unused,
                        char *unparsed __unused)

    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);

    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.

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5