Skip to content

Commit

Permalink
tools: fix a python 3 map issue in dbstat and dbslower
Browse files Browse the repository at this point in the history
In python 3, map returns an iterator and not a list anymore. This
patch cast the map into a list. It fixes the following error:

$ /usr/share/bcc/tools/dbstat mysql
Traceback (most recent call last):
  File "/usr/share/bcc/tools/dbstat", line 95, in <module>
    bpf = BPF(text=program, usdt_contexts=usdts)
  File "/usr/lib/python3.6/site-packages/bcc/__init__.py", line 339, in __init__
    ctx_array = (ct.c_void_p * len(usdt_contexts))()
TypeError: object of type 'map' has no len()
  • Loading branch information
jeromemarchand authored and yonghong-song committed Jun 10, 2020
1 parent e4de95e commit c9805f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tools/dbslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
args.pids = map(int, subprocess.check_output(
"pidof postgres".split()).split())

usdts = map(lambda pid: USDT(pid=pid), args.pids)
usdts = list(map(lambda pid: USDT(pid=pid), args.pids))
for usdt in usdts:
usdt.enable_probe("query__start", "query_start")
usdt.enable_probe("query__done", "query_end")
Expand Down
2 changes: 1 addition & 1 deletion tools/dbstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
program = program.replace("FILTER", "" if args.threshold == 0 else
"if (delta / 1000000 < %d) { return 0; }" % args.threshold)

usdts = map(lambda pid: USDT(pid=pid), args.pids)
usdts = list(map(lambda pid: USDT(pid=pid), args.pids))
for usdt in usdts:
usdt.enable_probe("query__start", "probe_start")
usdt.enable_probe("query__done", "probe_end")
Expand Down

0 comments on commit c9805f4

Please sign in to comment.