DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Bruce Richardson <bruce.richardson@intel.com>, dev@dpdk.org
Cc: Kevin Laatz <kevin.laatz@intel.com>
Subject: Re: [dpdk-dev] [PATCH v2] usertools/dpdk-telemetry: print name of app when connected
Date: Tue, 16 Feb 2021 12:19:24 +0000	[thread overview]
Message-ID: <e2e8a6d3-749d-5819-f8fc-1be900c3ed6a@intel.com> (raw)
In-Reply-To: <20210216113921.28725-1-bruce.richardson@intel.com>

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 <bruce.richardson@intel.com>
> 
> ---
> 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 <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly

  reply	other threads:[~2021-02-16 12:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16  9:44 [dpdk-dev] [PATCH] " Bruce Richardson
2021-02-16 10:40 ` Burakov, Anatoly
2021-02-16 11:02   ` Bruce Richardson
2021-02-16 11:13     ` Burakov, Anatoly
2021-02-16 11:39 ` [dpdk-dev] [PATCH v2] " Bruce Richardson
2021-02-16 12:19   ` Burakov, Anatoly [this message]
2021-02-17 13:57   ` Kevin Laatz
2021-03-25 17:00     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2e8a6d3-749d-5819-f8fc-1be900c3ed6a@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=kevin.laatz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).