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 82C4DA00C5; Thu, 30 Apr 2020 18:03:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7871A1DBFF; Thu, 30 Apr 2020 18:02:18 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 67F1F1DBED for ; Thu, 30 Apr 2020 18:02:15 +0200 (CEST) IronPort-SDR: z+syt6TUdLVrrYNtynXHd97vL+CrRAyZNOj/ZoWoUvhjjg/eDD7trXP28cqtNfRe53p7Ep+R/Q Dr5cjsVy8kuQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2020 09:02:15 -0700 IronPort-SDR: f207U98NnH+gYH6VLqTl3+vAvyRaL3YtMuOLiwy2p8Pdy8VHgT7GSPAwSwpPbrIB/FBxrYcwvW /jfg1IJe1i6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,336,1583222400"; d="scan'208";a="258345135" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by orsmga003.jf.intel.com with ESMTP; 30 Apr 2020 09:02:12 -0700 From: Ciara Power To: dev@dpdk.org, kevin.laatz@intel.com Cc: reshma.pattan@intel.com, jerinjacobk@gmail.com, david.marchand@redhat.com, keith.wiles@intel.com, mb@smartsharesystems.com, thomas@monjalon.net, stephen@networkplumber.org, bluca@debian.org, Ciara Power , Bruce Richardson Date: Thu, 30 Apr 2020 17:01:27 +0100 Message-Id: <20200430160137.59135-9-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430160137.59135-1-ciara.power@intel.com> References: <20200319171907.60891-1-ciara.power@intel.com> <20200430160137.59135-1-ciara.power@intel.com> Subject: [dpdk-dev] [PATCH v5 08/18] telemetry: add default callback commands 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 default commands are now added to provide the list of commands available, help text for a specified command, and also information about DPDK and telemetry. Signed-off-by: Ciara Power Signed-off-by: Bruce Richardson Reviewed-by: Keith Wiles --- v4: Added help command to provide help text for a command. --- lib/librte_telemetry/telemetry.c | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c index d1e92340dd..9f4234c049 100644 --- a/lib/librte_telemetry/telemetry.c +++ b/lib/librte_telemetry/telemetry.c @@ -73,6 +73,51 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help) return 0; } +static int +list_commands(const char *cmd __rte_unused, const char *params __rte_unused, + struct rte_tel_data *d) +{ + int i; + + rte_tel_data_start_array(d, RTE_TEL_STRING_VAL); + for (i = 0; i < num_callbacks; i++) + rte_tel_data_add_array_string(d, callbacks[i].cmd); + return 0; +} + +static int +json_info(const char *cmd __rte_unused, const char *params __rte_unused, + struct rte_tel_data *d) +{ + 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); + return 0; +} + +static int +command_help(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + int i; + + if (!params) + return -1; + rte_tel_data_start_dict(d); + rte_spinlock_lock(&callback_sl); + for (i = 0; i < num_callbacks; i++) + if (strcmp(params, callbacks[i].cmd) == 0) { + rte_tel_data_add_dict_string(d, params, + callbacks[i].help); + break; + } + rte_spinlock_unlock(&callback_sl); + if (i == num_callbacks) + return -1; + return 0; +} + static void output_json(const char *cmd, const struct rte_tel_data *d, int s) { @@ -296,6 +341,12 @@ telemetry_v2_init(const char *runtime_dir) { pthread_t t_new; + rte_telemetry_register_cmd("/", list_commands, + "Returns list of available commands, Takes no parameters"); + rte_telemetry_register_cmd("/info", json_info, + "Returns DPDK Telemetry information. Takes no parameters"); + rte_telemetry_register_cmd("/help", command_help, + "Returns help text for a command. Parameters: string command"); v2_socket.fn = client_handler; if (strlcpy(v2_socket.path, get_socket_path(runtime_dir, 2), sizeof(v2_socket.path)) >= sizeof(v2_socket.path)) { -- 2.17.1