Skip to content

Commit

Permalink
tools/*.py: fix invalid escape sequences in regexps
Browse files Browse the repository at this point in the history
With python >=3.8 many tools emit warnings on startup:

/usr/sbin/dcstat:91: SyntaxWarning: invalid escape sequence '\d'
  b.attach_kprobe(event_re="^lookup_fast$|^lookup_fast.constprop.*.\d$", fn_name="count_fast")

Fix this by using raw strings for regular expressions.

Signed-off-by: Holger Hoffstätte <[email protected]>
  • Loading branch information
hhoffstaette authored and yonghong-song committed Nov 6, 2023
1 parent c7753d8 commit aa9f9e6
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tools/cpudist.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
max_pid = int(open("/proc/sys/kernel/pid_max").read())

b = BPF(text=bpf_text, cflags=["-DMAX_PID=%d" % max_pid])
b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
b.attach_kprobe(event_re=r'^finish_task_switch$|^finish_task_switch\.isra\.\d$',
fn_name="sched_switch")

print("Tracing %s-CPU time... Hit Ctrl-C to end." %
Expand Down
2 changes: 1 addition & 1 deletion tools/dcsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
# initialize BPF
b = BPF(text=bpf_text)
if args.all:
b.attach_kprobe(event_re="^lookup_fast$|^lookup_fast.constprop.*.\d$", fn_name="trace_fast")
b.attach_kprobe(event_re=r'^lookup_fast$|^lookup_fast.constprop.*.\d$', fn_name="trace_fast")

mode_s = {
0: 'M',
Expand Down
2 changes: 1 addition & 1 deletion tools/dcstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def usage():

# load BPF program
b = BPF(text=bpf_text)
b.attach_kprobe(event_re="^lookup_fast$|^lookup_fast.constprop.*.\d$", fn_name="count_fast")
b.attach_kprobe(event_re=r'^lookup_fast$|^lookup_fast.constprop.*.\d$', fn_name="count_fast")
b.attach_kretprobe(event="d_lookup", fn_name="count_lookup")

# stat column labels and indexes
Expand Down
2 changes: 1 addition & 1 deletion tools/offcputime.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def signal_ignore(signal, frame):

# initialize BPF
b = BPF(text=bpf_text)
b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
b.attach_kprobe(event_re=r'^finish_task_switch$|^finish_task_switch\.isra\.\d$',
fn_name="oncpu")
matched = b.num_open_kprobes()
if matched == 0:
Expand Down
2 changes: 1 addition & 1 deletion tools/offwaketime.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def signal_ignore(signal, frame):

# initialize BPF
b = BPF(text=bpf_text)
b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
b.attach_kprobe(event_re=r'^finish_task_switch$|^finish_task_switch\.isra\.\d$',
fn_name="oncpu")
b.attach_kprobe(event="try_to_wake_up", fn_name="waker")
matched = b.num_open_kprobes()
Expand Down
2 changes: 1 addition & 1 deletion tools/runqlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
if not is_support_raw_tp:
b.attach_kprobe(event="ttwu_do_wakeup", fn_name="trace_ttwu_do_wakeup")
b.attach_kprobe(event="wake_up_new_task", fn_name="trace_wake_up_new_task")
b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
b.attach_kprobe(event_re=r'^finish_task_switch$|^finish_task_switch\.isra\.\d$',
fn_name="trace_run")

print("Tracing run queue latency... Hit Ctrl-C to end.")
Expand Down
2 changes: 1 addition & 1 deletion tools/runqslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def print_event(cpu, data, size):
if not is_support_raw_tp:
b.attach_kprobe(event="ttwu_do_wakeup", fn_name="trace_ttwu_do_wakeup")
b.attach_kprobe(event="wake_up_new_task", fn_name="trace_wake_up_new_task")
b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
b.attach_kprobe(event_re=r'^finish_task_switch$|^finish_task_switch\.isra\.\d$',
fn_name="trace_run")

print("Tracing run queue latency higher than %d us" % min_us)
Expand Down

0 comments on commit aa9f9e6

Please sign in to comment.