From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B3AD8A0526; Tue, 21 Jul 2020 18:14:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6BD9B1BFE7; Tue, 21 Jul 2020 18:14:44 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A5F2B1BFE4 for ; Tue, 21 Jul 2020 18:14:42 +0200 (CEST) IronPort-SDR: WPDY3lEutHx9B0hzT5bPGKdbnB/y1a2C52k+TgcmxrH6mZuhbcAKjgK7fcddMXEA7mqioHezDV WKU+0t9ajEbg== X-IronPort-AV: E=McAfee;i="6000,8403,9689"; a="150146771" X-IronPort-AV: E=Sophos;i="5.75,379,1589266800"; d="scan'208";a="150146771" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2020 09:14:41 -0700 IronPort-SDR: wU+N+nSyrt2ZR2HVHg7C0bL+s2ALzAaLfoLWeymnzZ/2RAAQO98rvnqNyIoHHCu3+IdBTViRyY AUU87T2ID3yQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,379,1589266800"; d="scan'208";a="283908568" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by orsmga003.jf.intel.com with ESMTP; 21 Jul 2020 09:14:40 -0700 From: Ciara Power To: kevin.laatz@intel.com Cc: dev@dpdk.org, bruce.richardson@intel.com, Ciara Power Date: Tue, 21 Jul 2020 17:09:24 +0100 Message-Id: <20200721160924.62082-1-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] doc: add more detail to telemetry guides 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" This patch adds examples to the Telemetry HowTo guide, to demonstrate commands that use parameters. The programmer's guide is also modified to include details on writing a callback function for a new command. Signed-off-by: Ciara Power --- v2: - Replaced examples of using commands in the programmer's guide with a link to the HowTo guide. - Added an example showing the use of a single string value. - Replaced inline functions with a synthetic example function below the list of parameters. --- doc/guides/howto/telemetry.rst | 46 ++++++- doc/guides/prog_guide/telemetry_lib.rst | 172 ++++++++++++++++++++---- 2 files changed, 187 insertions(+), 31 deletions(-) diff --git a/doc/guides/howto/telemetry.rst b/doc/guides/howto/telemetry.rst index b4a34ed67..7e8a5d6f3 100644 --- a/doc/guides/howto/telemetry.rst +++ b/doc/guides/howto/telemetry.rst @@ -1,6 +1,7 @@ .. SPDX-License-Identifier: BSD-3-Clause Copyright(c) 2020 Intel Corporation. +.. _telemetry: DPDK Telemetry User Guide ========================= @@ -69,12 +70,43 @@ and query information using the telemetry client python script. --> #. The user can now input commands to send across the socket, and receive the - response. + response. Some available commands are shown below. - .. code-block:: console + * List all commands. + + .. code-block:: console + + --> / + {"/": ["/", "/eal/app_params", "/eal/params", "/ethdev/list", + "/ethdev/link_status", "/ethdev/xstats", "/help", "/info"]} + + * Get the list of ethdev ports. + + .. code-block:: console + + --> /ethdev/list + {"/ethdev/list": [0, 1]} + + .. Note:: + + For commands that expect a parameter, use "," to separate the command + and parameter. See examples below. + + * Get extended statistics for an ethdev port. + + .. code-block:: console + + --> /ethdev/xstats,0 + {"/ethdev/xstats": {"rx_good_packets": 0, "tx_good_packets": 0, + "rx_good_bytes": 0, "tx_good_bytes": 0, "rx_missed_errors": 0, + ... + "tx_priority7_xon_to_xoff_packets": 0}} + + * Get the help text for a command. This will indicate what parameters are + required. Pass the command as a parameter. + + .. code-block:: console - --> / - {"/": ["/", "/eal/app_params", "/eal/params", "/ethdev/list", - "/ethdev/link_status", "/ethdev/xstats", "/help", "/info"]} - --> /ethdev/list - {"/ethdev/list": [0, 1]} + --> /help,/ethdev/xstats + {"/help": {"/ethdev/xstats": "Returns the extended stats for a port. + Parameters: int port_id"}} diff --git a/doc/guides/prog_guide/telemetry_lib.rst b/doc/guides/prog_guide/telemetry_lib.rst index 8563a7200..694cef26b 100644 --- a/doc/guides/prog_guide/telemetry_lib.rst +++ b/doc/guides/prog_guide/telemetry_lib.rst @@ -16,6 +16,150 @@ function that will format the library specific stats into the correct data format, when requested. +Creating Callback Functions +--------------------------- + + +Function Type +~~~~~~~~~~~~~ + +When creating a callback function in a library/app, it must be of the following type: + +.. code-block:: c + + typedef int (*telemetry_cb)(const char *cmd, const char *params, + struct rte_tel_data *info); + +For example, the callback for "/ethdev/list" is: + +.. code-block:: c + + static int + handle_port_list(const char *cmd __rte_unused, const char *params __rte_unused, + struct rte_tel_data *d) + +The parameters for a callback function are: + +* **cmd** + + This is the command requested by the client, e.g. "/ethdev/list". + For most callbacks this may be unused, however it will allow for handling + multiple commands in one callback function. This can be seen in the example + callback below. + +* **params** + + This will contain any parameters required for the command. For example + when calling "/ethdev/link_status,0", the port ID will be passed to the + callback function in params. This can be seen in the example callback below. + +* **d** + + The rte_tel_data pointer will be used by the callback function to format the + requested data to be returned to Telemetry. The data APIs provided will + enable adding to the struct, examples of this are shown later in this + document. + +**Example Callback** + +This callback is an example of handling multiple commands in one callback, +and also shows the use of params which holds a port ID. The params input needs +to be validated and converted to the required integer type for port ID. The cmd +parameter is then used in a comparison to decide which command was requested, +which will decide what port information should fill the rte_tel_data structure. + +.. code-block:: c + + int + handle_cmd_request(const char *cmd, const char *params, + struct rte_tel_data *d) + { + int port_id, used = 0; + + if (params == NULL || strlen(params) == 0 || !isdigit(*params)) + return -1; + + port_id = atoi(params); + if (!rte_eth_dev_is_valid_port(port_id)) + return -1; + + if (strcmp(cmd, "/cmd_1") == 0) + /* Build up port data requested for command 1 */ + else + /* Build up port data requested for command 2 */ + + return used; + } + + +Formatting Data +~~~~~~~~~~~~~~~ + +The callback function provided by the library must format its telemetry +information in the required data format. The Telemetry library provides a data +utilities API to build up the data structure with the required information. +The telemetry library is then responsible for formatting the data structure +into a JSON response before sending to the client. + +* **Array Data** + + Some data will need to be formatted in a list structure. For example, the + ethdev library provides a list of available ethdev ports in a formatted data + response, constructed using the following functions to build up the list: + + .. code-block:: c + + rte_tel_data_start_array(d, RTE_TEL_INT_VAL); + RTE_ETH_FOREACH_DEV(port_id) + rte_tel_data_add_array_int(d, port_id); + + The resulting response to the client shows the port list data provided above + by the handler function in ethdev, placed in a JSON reply by telemetry: + + .. code-block:: console + + {"/ethdev/list": [0, 1]} + +* **Dictionary Data** + + For data that needs to be structured in a dictionary with key/value pairs, + the data utilities API can also be used. For example, telemetry provides an + info command that has multiple key/value pairs, constructed in the callback + function shown below: + + .. code-block:: c + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_string(d, "version", rte_version()); + rte_tel_data_add_dict_int(d, "pid", getpid()); + rte_tel_data_add_dict_int(d, "max_output_len", MAX_OUTPUT_LEN); + + The resulting response to the client shows the key/value data provided above + by the handler function in telemetry, placed in a JSON reply by telemetry: + + .. code-block:: console + + {"/info": {"version": "DPDK 20.08.0-rc0", "pid": 3838, "max_output_len": 16384}} + +* **String Data** + + Telemetry also supports single string data. The data utilities API can again + be used for this, see the example below. + + .. code-block:: c + + rte_tel_data_string(d, "This is an example string"); + + Giving the following response to the client: + + .. code-block:: console + + {"/string_example": "This is an example string"} + +For more information on the range of data functions available in the API, +please refer to the docs. + + Registering Commands -------------------- @@ -35,28 +179,8 @@ command. An example showing ethdev commands being registered is shown below: "Returns the link status for a port. Parameters: int port_id"); -Formatting JSON response ------------------------- - -The callback function provided by the library must format its telemetry -information in the required data format. The Telemetry library provides a data -utilities API to build up the response. For example, the ethdev library provides a -list of available ethdev ports in a formatted data response, constructed using the -following functions to build up the list: +Using Commands +-------------- -.. code-block:: c - - rte_tel_data_start_array(d, RTE_TEL_INT_VAL); - RTE_ETH_FOREACH_DEV(port_id) - rte_tel_data_add_array_int(d, port_id); - -The data structure is then formatted into a JSON response before sending. -The resulting response shows the port list data provided above by the handler -function in ethdev, placed in a JSON reply by telemetry: - -.. code-block:: console - - {"/ethdev/list": [0, 1]} - -For more information on the range of data functions available in the API, -please refer to the docs. +To use commands, with a DPDK app running (e.g. testpmd), use the +dpdk-telemetry.py script. For details on its use, see the :ref:`telemetry`. -- 2.17.1