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 B795CA0558; Tue, 16 Feb 2021 13:19:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7AF3E16073D; Tue, 16 Feb 2021 13:19:30 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 5BF8040690 for ; Tue, 16 Feb 2021 13:19:28 +0100 (CET) IronPort-SDR: Q45e2nudS+/sqWgcB0tDLnYnnUCedJr3yZgyeDTPkgqN6sMNfBFl1cS5cAbZ3YQ4ixku6DwfQc POG3yW6+sswA== X-IronPort-AV: E=McAfee;i="6000,8403,9896"; a="170002536" X-IronPort-AV: E=Sophos;i="5.81,183,1610438400"; d="scan'208";a="170002536" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2021 04:19:27 -0800 IronPort-SDR: KqegIiZmrNQgwJqMU2kVJ3CsG9roaRrx8IFjpOdpht1a8vWRYaViJeT9X72cPSVCWel36nPcg6 G056IRIlnWwQ== X-IronPort-AV: E=Sophos;i="5.81,183,1610438400"; d="scan'208";a="399482847" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.232.191]) ([10.213.232.191]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2021 04:19:26 -0800 To: Bruce Richardson , dev@dpdk.org Cc: Kevin Laatz References: <20210216094415.28000-1-bruce.richardson@intel.com> <20210216113921.28725-1-bruce.richardson@intel.com> From: "Burakov, Anatoly" Message-ID: Date: Tue, 16 Feb 2021 12:19:24 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20210216113921.28725-1-bruce.richardson@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [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" On 16-Feb-21 11:39 AM, Bruce Richardson wrote: > 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 > Acked-by: Anatoly Burakov -- Thanks, Anatoly