Hi Remy,

While adapting an application to the new xstats API, I discovered
that it may not be so efficient to display the statistics and their
names.

I think the test-pmd code illustrates the issue pretty well:

/* Display xstats */
for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
        for (idx_name = 0; idx_name < cnt_xstats; idx_name++)
                if (xstats_names[idx_name].id == xstats[idx_xstat].id) {
                        printf("%s: %"PRIu64"\n",
                                xstats_names[idx_name].name,
                                xstats[idx_xstat].value);
                        break;
                }

The displaying is in O(n^2).

It's possible to enhance the code to have it in O(n), but it
requires an intermediate table.

Why not changing this:

   struct rte_eth_xstat {
        uint64_t id;
        uint64_t value;
   };
   struct rte_eth_xstat_name {
        char name[RTE_ETH_XSTATS_NAME_SIZE];
        uint64_t id;
   };

Into this:

   struct rte_eth_xstat {
        uint64_t id;
        uint64_t value;
   };
   struct rte_eth_xstat_name {
        char name[RTE_ETH_XSTATS_NAME_SIZE];
        /* No identifier */
   };

And assume that the id field in rte_eth_xstat corresponds to
the index in the rte_eth_xstat_name table?


The test-pmd code would be something like this:

/* Display xstats */
for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
        printf("%s: %"PRIu64"\n",
                xstats_names[xstats[idx_xstats].id].name,
                xstats[idx_xstat].value);
}


What do you think?

Regards
Olivier

Reply via email to