From patchwork Wed Nov 29 09:29:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 31745 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F013C2BA9; Wed, 29 Nov 2017 10:29:35 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by dpdk.org (Postfix) with ESMTP id 35E912B9E for ; Wed, 29 Nov 2017 10:29:34 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 7405B40025; Wed, 29 Nov 2017 10:29:33 +0100 (CET) Received: from isengard.friendlyfire.se (fukushima.lysator.liu.se [IPv6:2001:6b0:17:f0a0::5d]) by mail.lysator.liu.se (Postfix) with ESMTP id 1EB2440018; Wed, 29 Nov 2017 10:29:31 +0100 (CET) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: john.mcnamara@intel.com Cc: dev@dpdk.org, =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Wed, 29 Nov 2017 10:29:02 +0100 Message-Id: <1511947742-16839-1-git-send-email-hofors@lysator.liu.se> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH] doc: fix issues in metrics example X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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: + ; }