bpflist: use smarter print format
BPF object type can be wider than 8 characters, e.g., for the "raw-tracepoint"
type.  Compute the printing format automatically based on the maximum length of
BPF objects to be listed.
@@ -76,7 +76,12 @@ for pdir in os.listdir('/proc'):
find_bpf_fds(int(pdir))
except OSError:
continue
-print("%-6s %-16s %-8s %s" % ("PID", "COMM", "TYPE", "COUNT"))
-for (pid, typ), count in sorted(counts.items(), key=lambda t: t[0][0]):
+
+items = counts.items()
+max_type_len = items and max(list(map(lambda t: len(t[0][1]), items))) or 0
+print_format = "%%-6s %%-16s %%-%ss %%s" % (max_type_len + 1)
+
+print(print_format % ("PID", "COMM", "TYPE", "COUNT"))
+for (pid, typ), count in sorted(items, key=lambda t: t[0][0]):
comm = comm_for_pid(pid)
- print("%-6d %-16s %-8s %-4d" % (pid, comm, typ, count))
+ print(print_format % (pid, comm, typ, count))
