DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] doc: fix issues in metrics example
@ 2017-11-29  9:29 Mattias Rönnblom
  2017-12-12 14:45 ` Kovacevic, Marko
  0 siblings, 1 reply; 2+ messages in thread
From: Mattias Rönnblom @ 2017-11-29  9:29 UTC (permalink / raw)
  To: john.mcnamara; +Cc: dev, Mattias Rönnblom

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] doc: fix issues in metrics example
  2017-11-29  9:29 [dpdk-dev] [PATCH] doc: fix issues in metrics example Mattias Rönnblom
@ 2017-12-12 14:45 ` Kovacevic, Marko
  0 siblings, 0 replies; 2+ messages in thread
From: Kovacevic, Marko @ 2017-12-12 14:45 UTC (permalink / raw)
  To: Mattias Rönnblom, Mcnamara, John; +Cc: dev



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Mattias Rönnblom
> Sent: Wednesday, November 29, 2017 9:29 AM
> To: Mcnamara, John <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
> 
> 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>

Would it be more beneficial to keep the return in these two cases as not to do two jumps to go out instead of just one
And to remove the out: ; at the very end completely.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-12 14:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29  9:29 [dpdk-dev] [PATCH] doc: fix issues in metrics example Mattias Rönnblom
2017-12-12 14:45 ` Kovacevic, Marko

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