Bug 1792729 - [abrt] bcc-tools: __init__(): __init__.py:325:__init__:Exception: Failed to compile BPF text
Summary: [abrt] bcc-tools: __init__(): __init__.py:325:__init__:Exception: Failed to c...
Keywords:
Status: CLOSED DUPLICATE of bug 1788228
Alias: None
Product: Fedora
Classification: Fedora
Component: bcc
Version: 31
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jiri Olsa
QA Contact: Fedora Extras Quality Assurance
URL: https://retrace.fedoraproject.org/faf...
Whiteboard: abrt_hash:f3461008106f20c8e0edf1f7b1f...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-01-19 13:20 UTC by Mircea Vutcovici
Modified: 2020-01-19 15:33 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2020-01-19 15:33:08 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
File: backtrace (1.81 KB, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details
File: cpuinfo (2.40 KB, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details
File: environ (5.62 KB, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details
File: mountinfo (2.98 KB, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details
File: namespaces (129 bytes, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details
File: open_fds (235 bytes, text/plain)
2020-01-19 13:20 UTC, Mircea Vutcovici
no flags Details

Description Mircea Vutcovici 2020-01-19 13:20:16 UTC
Description of problem:
I was trying to run the following BCC/BPF script:

[mvutcovi@mvutcovi-lap ~]$ cat bpf-profile.py 
#!/usr/bin/python
# @lint-avoid-python-3-compatibility-imports

from __future__ import print_function
from bcc import BPF, PerfType, PerfSWConfig
from sys import stderr
from time import sleep
import argparse
import signal
import os
import errno

# arg validation
def positive_int(val):
    try:
        ival = int(val)
    except ValueError:
        raise argparse.ArgumentTypeError("must be an integer")

    if ival < 0:
        raise argparse.ArgumentTypeError("must be positive")
    return ival

def positive_nonzero_int(val):
    ival = positive_int(val)
    if ival == 0:
        raise argparse.ArgumentTypeError("must be nonzero")
    return ival

# arguments
examples = """examples:
    ./profile -F 99       # profile stack traces at 99 Hertz
"""

parser = argparse.ArgumentParser(
    description="Profile CPU stack traces at a timed interval",
    formatter_class=argparse.RawDescriptionHelpFormatter,
    epilog=examples)
parser.add_argument("-F", "--frequency", type=positive_int,
    help="sample frequency, Hertz")
parser.add_argument("duration", nargs="?", default=99999999,
    type=positive_nonzero_int,
    help="duration of trace, in seconds")
parser.add_argument("-C", "--cpu", type=int, default=-1,
    help="cpu number to run profile on")
parser.add_argument("--ebpf", action="store_true",
    help=argparse.SUPPRESS)

# option logic
args = parser.parse_args()
duration = int(args.duration)
debug = 0

# define BPF program
bpf_text = """
#include <uapi/linux/ptrace.h>
#include <uapi/linux/bpf_perf_event.h>
#include <linux/sched.h>

typedef struct process_freq_key {
    char comm[TASK_COMM_LEN];
    u64  slot;
} process_freq_key_t;

BPF_PERCPU_ARRAY(curfreq, u64, 1);
BPF_HISTOGRAM(hist, process_freq_key_t, 10000);

TRACEPOINT_PROBE(power, cpu_frequency)
{
    int idx = 0;
    u64 val = args->state;
    curfreq.update(&idx, &val);
    return 0;
}

int do_perf_event(struct bpf_perf_event_data *ctx) {
    int idx = 0;
    u64 val, *freq = curfreq.lookup(&idx);

    if (!freq || !*freq)
        return 0;

    val = *freq / 100000;

    if (bpf_get_current_pid_tgid()) {
        process_freq_key_t pkey = { .slot = val };
        bpf_get_current_comm(&pkey.comm, sizeof(pkey.comm));
        hist.increment(pkey);
    } else {
        process_freq_key_t pkey = { .slot = val, .comm = "system" };
        hist.increment(pkey);
    }

    return 0;
}
"""

sample_freq = 0
if args.frequency:
    sample_freq = args.frequency
else:
    # If user didn't specify anything, use default 49Hz sampling
    sample_freq = 49

if debug or args.ebpf:
    print(bpf_text)
    if args.ebpf:
        exit()

# initialize BPF & perf_events
b = BPF(text=bpf_text)
b.attach_perf_event(ev_type=PerfType.SOFTWARE,
    ev_config=PerfSWConfig.CPU_CLOCK, fn_name="do_perf_event",
    sample_period=0, sample_freq=sample_freq, cpu=args.cpu)

# signal handler
def signal_ignore(signal, frame):
    print()

print("Sampling CPU freq system-wide & by process. Ctrl-C to end.\n");

# collect samples
try:
    sleep(duration)
except KeyboardInterrupt:
    # as cleanup can take some time, trap Ctrl-C:
    signal.signal(signal.SIGINT, signal_ignore)

b.get_table("hist").print_linear_hist("FREQ/100000", "COMM")
[mvutcovi@mvutcovi-lap ~]$ 

Version-Release number of selected component:
bcc-tools-0.10.0-2.fc31

Additional info:
reporter:       libreport-2.11.3
cgroup:         0::/user.slice/user-1000.slice/user/gnome-terminal-server.service
cmdline:        /usr/bin/python3 /usr/share/bcc/tools/killsnoop
crash_function: __init__
exception_type: Exception
executable:     /usr/share/bcc/tools/killsnoop
interpreter:    python3-3.7.5-2.fc31.x86_64
kernel:         5.4.8-200.fc31.x86_64
runlevel:       N 5
type:           Python3
uid:            1000

Truncated backtrace:
__init__.py:325:__init__:Exception: Failed to compile BPF text

Traceback (most recent call last):
  File "/usr/share/bcc/tools/killsnoop", line 113, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 325, in __init__
    raise Exception("Failed to compile BPF text")
Exception: Failed to compile BPF text

Local variables in innermost frame:
self: <bcc.BPF object at 0x7f585dfa06d0>
src_file: b''
hdr_file: b''
text: b'\n#include <uapi/linux/ptrace.h>\n#include <linux/sched.h>\n\nstruct val_t {\n   u64 pid;\n   int sig;\n   int tpid;\n   char comm[TASK_COMM_LEN];\n};\n\nstruct data_t {\n   u64 pid;\n   int tpid;\n   int sig;\n   int ret;\n   char comm[TASK_COMM_LEN];\n};\n\nBPF_HASH(infotmp, u32, struct val_t);\nBPF_PERF_OUTPUT(events);\n\nint syscall__kill(struct pt_regs *ctx, int tpid, int sig)\n{\n    u32 pid = bpf_get_current_pid_tgid();\n    \n\n    struct val_t val = {.pid = pid};\n    if (bpf_get_current_comm(&val.comm, sizeof(val.comm)) == 0) {\n        val.tpid = tpid;\n        val.sig = sig;\n        infotmp.update(&pid, &val);\n    }\n\n    return 0;\n};\n\nint do_ret_sys_kill(struct pt_regs *ctx)\n{\n    struct data_t data = {};\n    struct val_t *valp;\n    u32 pid = bpf_get_current_pid_tgid();\n\n    valp = infotmp.lookup(&pid);\n    if (valp == 0) {\n        // missed entry\n        return 0;\n    }\n\n    bpf_probe_read(&data.comm, sizeof(data.comm), valp->comm);\n    data.pid = pid;\n    data.tpid = valp->tpid;\n    data.ret = PT_REGS_RC(ctx);\n    data.sig = valp->sig;\n\n    events.perf_submit(ctx, &data, sizeof(data));\n    infotmp.delete(&pid);\n\n    return 0;\n}\n'
debug: 0
cflags: []
usdt_contexts: []
allow_rlimit: True
cflags_array: <bcc.c_char_p_Array_0 object at 0x7f5866feda70>
ctx_array: <bcc.c_void_p_Array_0 object at 0x7f585e07bc20>
usdt_text: b''

Comment 1 Mircea Vutcovici 2020-01-19 13:20:18 UTC
Created attachment 1653633 [details]
File: backtrace

Comment 2 Mircea Vutcovici 2020-01-19 13:20:19 UTC
Created attachment 1653634 [details]
File: cpuinfo

Comment 3 Mircea Vutcovici 2020-01-19 13:20:20 UTC
Created attachment 1653635 [details]
File: environ

Comment 4 Mircea Vutcovici 2020-01-19 13:20:21 UTC
Created attachment 1653636 [details]
File: mountinfo

Comment 5 Mircea Vutcovici 2020-01-19 13:20:22 UTC
Created attachment 1653637 [details]
File: namespaces

Comment 6 Mircea Vutcovici 2020-01-19 13:20:23 UTC
Created attachment 1653638 [details]
File: open_fds

Comment 7 Rafael Fonseca 2020-01-19 15:28:54 UTC
You need bcc-0.12.0 for kernel >= 5.4. Please update and try again.

Comment 8 Rafael Fonseca 2020-01-19 15:33:08 UTC

*** This bug has been marked as a duplicate of bug 1788228 ***


Note You need to log in before you can comment on or make changes to this bug.