From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2579BA0558; Tue, 16 Feb 2021 12:39:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98EB516072E; Tue, 16 Feb 2021 12:39:31 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 8C21A40690 for ; Tue, 16 Feb 2021 12:39:29 +0100 (CET) IronPort-SDR: /IqIRnrqdH0bY16IRMBboyhzAq8MXee+jec9SApHP5jhIIw37ZFhQLa21IncjnMBNn75Ut1/oo 6GINg/7TXr3g== X-IronPort-AV: E=McAfee;i="6000,8403,9896"; a="244339601" X-IronPort-AV: E=Sophos;i="5.81,183,1610438400"; d="scan'208";a="244339601" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2021 03:39:28 -0800 IronPort-SDR: c2v/uUwbo9hMspkXzpYg/Ks1a73PX3y0gWp2sfjy5lJburqc8yhhg44uBdKg8GdCu3ZioKsyi7 5CSFFDBTBzxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,183,1610438400"; d="scan'208";a="438887814" Received: from silpixa00399126.ir.intel.com ([10.237.223.216]) by orsmga001.jf.intel.com with ESMTP; 16 Feb 2021 03:39:27 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: anatoly.burakov@intel.com, Bruce Richardson , Kevin Laatz Date: Tue, 16 Feb 2021 11:39:21 +0000 Message-Id: <20210216113921.28725-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210216094415.28000-1-bruce.richardson@intel.com> References: <20210216094415.28000-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] usertools/dpdk-telemetry: print name of app when connected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" When the dpdk-telemetry client connects to a DPDK instance, we can use the PID provided in the initial connection message to query from /proc the name of the process we are connected to, and display that to the user. We use the "cmdline" procfs entry for the query since that is available on both Linux and FreeBSD (assuming procfs is mounted on the BSD instance). Signed-off-by: Bruce Richardson --- V2: Updated with stylistic feedback from Anatoly, and split name query into a separate function. --- usertools/dpdk-telemetry.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py index 181859658..b2acd92ba 100755 --- a/usertools/dpdk-telemetry.py +++ b/usertools/dpdk-telemetry.py @@ -11,6 +11,7 @@ import os import glob import json +import errno import readline # global vars @@ -32,6 +33,20 @@ def read_socket(sock, buf_len, echo=True): return ret +def get_app_name(pid): + """ return the app name for a given pid, for printing """ + proc_cmdline = os.path.join('/proc', str(pid), 'cmdline') + try: + with open(proc_cmdline) as f: + argv0 = f.read(1024).split('\0')[0] + return os.path.basename(argv0) + except IOError as e: + # ignore file not found errors + if e.errno != errno.ENOENT: + raise + return None + + def handle_socket(path): """ Connect to socket and handle user input """ sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) @@ -45,6 +60,9 @@ def handle_socket(path): return json_reply = read_socket(sock, 1024) output_buf_len = json_reply["max_output_len"] + app_name = get_app_name(json_reply["pid"]) + if app_name: + print('Connected to application: "%s"' % app_name) # get list of commands for readline completion sock.send("/".encode()) -- 2.27.0