[v2] devbind: don't display non-existent device categories

Message ID 9ee6c634ef079abef070a72fff26d06e364a609b.1542623365.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] devbind: don't display non-existent device categories |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Anatoly Burakov Nov. 19, 2018, 10:33 a.m. UTC
  If there aren't any devices of a particular category on user's
system, we still display them, which is bad for usability. Fix
devbind to not print out a category unless there are devices in
it.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: David Hunt <david.hunt@intel.com>
---

Notes:
    v2: fix indentation

 usertools/dpdk-devbind.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
  

Comments

Thomas Monjalon Nov. 22, 2018, 5:12 p.m. UTC | #1
19/11/2018 11:33, Anatoly Burakov:
> If there aren't any devices of a particular category on user's
> system, we still display them, which is bad for usability. Fix
> devbind to not print out a category unless there are devices in
> it.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> Reviewed-by: David Hunt <david.hunt@intel.com>

Applied, thanks

I think we can strip output more and remove "no detected" messages.
  
Anatoly Burakov Nov. 23, 2018, 9:23 a.m. UTC | #2
On 22-Nov-18 5:12 PM, Thomas Monjalon wrote:
> 19/11/2018 11:33, Anatoly Burakov:
>> If there aren't any devices of a particular category on user's
>> system, we still display them, which is bad for usability. Fix
>> devbind to not print out a category unless there are devices in
>> it.
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> Reviewed-by: David Hunt <david.hunt@intel.com>
> 
> Applied, thanks
> 
> I think we can strip output more and remove "no detected" messages.
> 

I had an idea to do that, but for now i decided to keep it for the 
purposes of providing just enough useful information to the user with 
little expense.
  

Patch

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 7d564634c..6051f6f9e 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -546,14 +546,27 @@  def show_device_status(devices_type, device_name):
             else:
                 kernel_drv.append(devices[d])
 
+    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
+
+    # don't bother displaying anything if there are no devices
+    if n_devs == 0:
+        msg = "No '%s' devices detected" % device_name
+        print("")
+        print(msg)
+        print("".join('=' * len(msg)))
+        return
+
     # print each category separately, so we can clearly see what's used by DPDK
-    display_devices("%s devices using DPDK-compatible driver" % device_name,
-                    dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
-    display_devices("%s devices using kernel driver" % device_name, kernel_drv,
-                    "if=%(Interface)s drv=%(Driver_str)s "
-                    "unused=%(Module_str)s %(Active)s")
-    display_devices("Other %s devices" % device_name, no_drv,
-                    "unused=%(Module_str)s")
+    if len(dpdk_drv) != 0:
+        display_devices("%s devices using DPDK-compatible driver" % device_name,
+                        dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
+    if len(kernel_drv) != 0:
+        display_devices("%s devices using kernel driver" % device_name, kernel_drv,
+                        "if=%(Interface)s drv=%(Driver_str)s "
+                        "unused=%(Module_str)s %(Active)s")
+    if len(no_drv) != 0:
+        display_devices("Other %s devices" % device_name, no_drv,
+                        "unused=%(Module_str)s")
 
 def show_status():
     '''Function called when the script is passed the "--status" option.