DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <hofors@lysator.liu.se>
To: john.mcnamara@intel.com
Cc: dev@dpdk.org, "Mattias Rönnblom" <hofors@lysator.liu.se>
Subject: [dpdk-dev] [PATCH] doc: fix issues in metrics example
Date: Wed, 29 Nov 2017 10:29:02 +0100	[thread overview]
Message-ID: <1511947742-16839-1-git-send-email-hofors@lysator.liu.se> (raw)

The metrics example didn't retrieve the metrics' names, and also had
some more minor issues with repetitive error handling code and missing
variable declarations.

Signed-off-by: Mattias Rönnblom <hofors@lysator.liu.se>
---
 doc/guides/prog_guide/metrics_lib.rst | 40 ++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/doc/guides/prog_guide/metrics_lib.rst b/doc/guides/prog_guide/metrics_lib.rst
index d52204f..6326980 100644
--- a/doc/guides/prog_guide/metrics_lib.rst
+++ b/doc/guides/prog_guide/metrics_lib.rst
@@ -143,41 +143,47 @@ print out all metrics for a given port:
 
 .. code-block:: c
 
-    void print_metrics() {
+    void print_metrics(int port_id)
+    {
         struct rte_metric_value *metrics;
         struct rte_metric_name *names;
         int len;
+        int ret;
+        int i;
 
         len = rte_metrics_get_names(NULL, 0);
         if (len < 0) {
-            printf("Cannot get metrics count\n");
-            return;
-        }
-        if (len == 0) {
-            printf("No metrics to display (none have been registered)\n");
-            return;
+            printf("Cannot get metrics count.\n");
+            goto out;
+        } else if (len == 0) {
+            printf("No metrics to display (none have been registered).\n");
+            goto out;
         }
         metrics = malloc(sizeof(struct rte_metric_value) * len);
-        names =  malloc(sizeof(struct rte_metric_name) * len);
+        names = malloc(sizeof(struct rte_metric_name) * len);
         if (metrics == NULL || names == NULL) {
-            printf("Cannot allocate memory\n");
-            free(metrics);
-            free(names);
-            return;
+            printf("Cannot allocate memory.\n");
+            goto out_free;
+        }
+        ret = rte_metrics_get_names(names, len);
+        if (ret < 0 || ret > len) {
+            printf("Cannot get metrics names.\n");
+            goto out_free;
         }
         ret = rte_metrics_get_values(port_id, metrics, len);
         if (ret < 0 || ret > len) {
-            printf("Cannot get metrics values\n");
-            free(metrics);
-            free(names);
-            return;
+            printf("Cannot get metrics values.\n");
+            goto out_free;
         }
         printf("Metrics for port %i:\n", port_id);
         for (i = 0; i < len; i++)
             printf("  %s: %"PRIu64"\n",
-                names[metrics[i].key].name, metrics[i].value);
+                   names[metrics[i].key].name, metrics[i].value);
+     out_free:
         free(metrics);
         free(names);
+     out:
+        ;
     }
 
 
-- 
2.7.4

             reply	other threads:[~2017-11-29  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29  9:29 Mattias Rönnblom [this message]
2017-12-12 14:45 ` Kovacevic, Marko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1511947742-16839-1-git-send-email-hofors@lysator.liu.se \
    --to=hofors@lysator.liu.se \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).