[v1] usertools/telemetry: add non-interactive mode
Checks
Commit Message
Add non-interactive mode to dpdk-telemetry.py so that a query string
can be supplied on the command line, and script dumps out data and
exits. Handing for calling from scripts.
Signed-off-by: David Hunt <david.hunt@intel.com>
---
usertools/dpdk-telemetry.py | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
Comments
On Thu, Sep 09, 2021 at 04:56:25PM +0100, David Hunt wrote:
> Add non-interactive mode to dpdk-telemetry.py so that a query string
> can be supplied on the command line, and script dumps out data and
> exits. Handing for calling from scripts.
>
> Signed-off-by: David Hunt <david.hunt@intel.com>
> ---
Hi Dave,
I'm not sure I like the use of "-q" for adding a query mode - it's more a
shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative
approach here might be to improve support for piping the input commands to
the script instead so that you can do e.g.
"echo /ethdev/stats,0 | dpdk-telemetry.py"
and have that work well in a script.
I'll do up a patchset for improving that and upstream it for feedback.
/Bruce
On Mon, Sep 13, 2021 at 11:43:25AM +0100, Bruce Richardson wrote:
> On Thu, Sep 09, 2021 at 04:56:25PM +0100, David Hunt wrote:
> > Add non-interactive mode to dpdk-telemetry.py so that a query string
> > can be supplied on the command line, and script dumps out data and
> > exits. Handing for calling from scripts.
> >
> > Signed-off-by: David Hunt <david.hunt@intel.com>
> > ---
> Hi Dave,
>
> I'm not sure I like the use of "-q" for adding a query mode - it's more a
> shortcut parameter for a "quiet" mode. If I may, I'd suggest an alternative
> approach here might be to improve support for piping the input commands to
> the script instead so that you can do e.g.
>
> "echo /ethdev/stats,0 | dpdk-telemetry.py"
>
> and have that work well in a script.
>
> I'll do up a patchset for improving that and upstream it for feedback.
>
Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867
/Bruce
Hi Dave,
>-----Original Message-----
>From: Richardson, Bruce <bruce.richardson@intel.com>
>Sent: Monday 13 September 2021 11:54
>To: Hunt, David <david.hunt@intel.com>
>Cc: dev@dpdk.org; Power, Ciara <ciara.power@intel.com>
>Subject: Re: [dpdk-dev] [PATCH v1] usertools/telemetry: add non-interactive
>mode
>
>On Mon, Sep 13, 2021 at 11:43:25AM +0100, Bruce Richardson wrote:
>> On Thu, Sep 09, 2021 at 04:56:25PM +0100, David Hunt wrote:
>> > Add non-interactive mode to dpdk-telemetry.py so that a query string
>> > can be supplied on the command line, and script dumps out data and
>> > exits. Handing for calling from scripts.
>> >
>> > Signed-off-by: David Hunt <david.hunt@intel.com>
>> > ---
>> Hi Dave,
>>
>> I'm not sure I like the use of "-q" for adding a query mode - it's
>> more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an
>> alternative approach here might be to improve support for piping the
>> input commands to the script instead so that you can do e.g.
>>
>> "echo /ethdev/stats,0 | dpdk-telemetry.py"
>>
>> and have that work well in a script.
>>
>> I'll do up a patchset for improving that and upstream it for feedback.
>>
>
>Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867
>
>/Bruce
Thanks for this, although I do think the improvement to allow for piping is a better solution.
I have acked Bruce's patchset, hopefully that will be suitable for your use case.
Thanks,
Ciara
On 15/9/2021 11:49 AM, Power, Ciara wrote:
> Hi Dave,
>
>> -----Original Message-----
>> From: Richardson, Bruce <bruce.richardson@intel.com>
>> Sent: Monday 13 September 2021 11:54
>> To: Hunt, David <david.hunt@intel.com>
>> Cc: dev@dpdk.org; Power, Ciara <ciara.power@intel.com>
>> Subject: Re: [dpdk-dev] [PATCH v1] usertools/telemetry: add non-interactive
>> mode
>>
>> On Mon, Sep 13, 2021 at 11:43:25AM +0100, Bruce Richardson wrote:
>>> On Thu, Sep 09, 2021 at 04:56:25PM +0100, David Hunt wrote:
>>>> Add non-interactive mode to dpdk-telemetry.py so that a query string
>>>> can be supplied on the command line, and script dumps out data and
>>>> exits. Handing for calling from scripts.
>>>>
>>>> Signed-off-by: David Hunt <david.hunt@intel.com>
>>>> ---
>>> Hi Dave,
>>>
>>> I'm not sure I like the use of "-q" for adding a query mode - it's
>>> more a shortcut parameter for a "quiet" mode. If I may, I'd suggest an
>>> alternative approach here might be to improve support for piping the
>>> input commands to the script instead so that you can do e.g.
>>>
>>> "echo /ethdev/stats,0 | dpdk-telemetry.py"
>>>
>>> and have that work well in a script.
>>>
>>> I'll do up a patchset for improving that and upstream it for feedback.
>>>
>> Now at: http://patches.dpdk.org/project/dpdk/list/?series=18867
>>
>> /Bruce
> Thanks for this, although I do think the improvement to allow for piping is a better solution.
> I have acked Bruce's patchset, hopefully that will be suitable for your use case.
>
> Thanks,
> Ciara
+1
I'll mark my patchset as superceeded.
Rgds,
Dave.
@@ -48,7 +48,7 @@ def get_app_name(pid):
return None
-def handle_socket(path):
+def handle_socket(path, query):
""" Connect to socket and handle user input """
sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
global CMDS
@@ -69,13 +69,17 @@ def handle_socket(path):
sock.send("/".encode())
CMDS = read_socket(sock, output_buf_len, False)["/"]
- # interactive prompt
- text = input('--> ').strip()
- while text != "quit":
- if text.startswith('/'):
- sock.send(text.encode())
- read_socket(sock, output_buf_len)
+ if (query != ""):
+ sock.send(query.encode())
+ read_socket(sock, output_buf_len)
+ else:
+ # interactive prompt
text = input('--> ').strip()
+ while text != "quit":
+ if text.startswith('/'):
+ sock.send(text.encode())
+ read_socket(sock, output_buf_len)
+ text = input('--> ').strip()
sock.close()
@@ -104,6 +108,8 @@ def get_dpdk_runtime_dir(fp):
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file-prefix', \
help='Provide file-prefix for DPDK runtime directory', default='rte')
+parser.add_argument('-q', '--query', \
+ help='run this query and exit', default='')
args = parser.parse_args()
rdir = get_dpdk_runtime_dir(args.file_prefix)
-handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)))
+handle_socket(os.path.join(rdir, 'dpdk_telemetry.{}'.format(TELEMETRY_VERSION)), args.query)