Skip to content

Commit

Permalink
opensnoop: convert args.name to bytes
Browse files Browse the repository at this point in the history
This commit fixes the following error with python3:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
  File "/usr/lib/python3.6/site-packages/bcc/table.py", line 508, in raw_cb_
    callback(cpu, data, size)
  File "./opensnoop.py", line 169, in print_event
    if args.name and args.name not in event.comm:
TypeError: a bytes-like object is required, not 'str'

Signed-off-by: Gary Lin <[email protected]>
  • Loading branch information
lcp authored and drzaeus77 committed Feb 21, 2018
1 parent 04ec1fa commit 40fd669
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/opensnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 08-Oct-2016 Dina Goldshtein Support filtering by PID and TID.

from __future__ import print_function
from bcc import BPF
from bcc import ArgString, BPF
import argparse
import ctypes as ct
from datetime import datetime, timedelta
Expand Down Expand Up @@ -44,6 +44,7 @@
parser.add_argument("-d", "--duration",
help="total duration of trace in seconds")
parser.add_argument("-n", "--name",
type=ArgString,
help="only print process names containing this name")
parser.add_argument("--ebpf", action="store_true",
help=argparse.SUPPRESS)
Expand Down Expand Up @@ -176,7 +177,7 @@ def print_event(cpu, data, size):
if args.failed and (event.ret >= 0):
return

if args.name and args.name not in event.comm:
if args.name and bytes(args.name) not in event.comm:
return

if args.timestamp:
Expand Down

0 comments on commit 40fd669

Please sign in to comment.