| @@ -1,6 +1,8 @@ | |||||
| #! /bin/env python3 | #! /bin/env python3 | ||||
| import argparse | import argparse | ||||
| import os | import os | ||||
| import time | |||||
| from pathlib import Path | from pathlib import Path | ||||
| from typing import List, Optional, Tuple | from typing import List, Optional, Tuple | ||||
| @@ -109,8 +111,9 @@ def main(): | |||||
| input_data = f.read() | input_data = f.read() | ||||
| if args.verbose: | if args.verbose: | ||||
| print(input_data) | print(input_data) | ||||
| _, session = generate_result( | |||||
| resp, session = generate_result( | |||||
| chatbot, input_data, conv_uuid, args.verbose) | chatbot, input_data, conv_uuid, args.verbose) | ||||
| time.sleep(2.4) | |||||
| print(f"Trained session: {session}") | print(f"Trained session: {session}") | ||||
| else: | else: | ||||
| parser.print_help() | parser.print_help() | ||||
| @@ -1 +1,3 @@ | |||||
| I'll give you a few examples of how to write eBPF programs. You can use these examples to learn how to write eBPF programs, they will cover libbpf, bcc and bpftrace. | I'll give you a few examples of how to write eBPF programs. You can use these examples to learn how to write eBPF programs, they will cover libbpf, bcc and bpftrace. | ||||
| No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -36,4 +36,5 @@ int handle_tp(void *ctx) | |||||
| - `void *ctx`:ctx本来是具体类型的参数, 但是由于我们这里没有使用这个参数,因此就将其写成void *类型。 | - `void *ctx`:ctx本来是具体类型的参数, 但是由于我们这里没有使用这个参数,因此就将其写成void *类型。 | ||||
| - `return 0`;:必须这样,返回 0 | - `return 0`;:必须这样,返回 0 | ||||
| If you learned and remembered the result, please tell me OK. | |||||
| If you learned and remembered the result, please tell me OK. No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -34,9 +34,11 @@ int BPF_KRETPROBE(do_unlinkat_exit, long ret) | |||||
| } | } | ||||
| ``` | ``` | ||||
| kprobe is an example of dealing with kernel-space entry and exit (return) probes, kprobe and kretprobe in libbpf lingo. It attaches kprobe and kretprobe BPF programs to the do_unlinkat() function and logs the PID, filename, and return result, respectively, using bpf_printk() macro. | |||||
| kprobe 是 eBPF 用于处理内核空间入口和出口(返回)探针(kprobe 和 kretprobe)的一个例子。它将 kprobe 和 kretprobe BPF 程序附加到 do_unlinkat() 函数上,并使用 bpf_printk() 宏分别记录 PID、文件名和返回值。 | kprobe 是 eBPF 用于处理内核空间入口和出口(返回)探针(kprobe 和 kretprobe)的一个例子。它将 kprobe 和 kretprobe BPF 程序附加到 do_unlinkat() 函数上,并使用 bpf_printk() 宏分别记录 PID、文件名和返回值。 | ||||
| eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发工具链,它的目的是简化 eBPF 程序的开发、构建、分发、运行。可以参考 <https://github.com/eunomia-bpf/eunomia-bpf> 下载和安装 ecc 编译工具链和 ecli 运行时。 | eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发工具链,它的目的是简化 eBPF 程序的开发、构建、分发、运行。可以参考 <https://github.com/eunomia-bpf/eunomia-bpf> 下载和安装 ecc 编译工具链和 ecli 运行时。 | ||||
| 我还没有说完,我会继续说。 | |||||
| 我还没有说完,我会继续说。No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -32,4 +32,5 @@ $ sudo cat /sys/kernel/debug/tracing/trace_pipe | |||||
| rm-9346 [005] d..4 4710.951895: bpf_trace_printk: KPROBE EXIT: ret = 0 | rm-9346 [005] d..4 4710.951895: bpf_trace_printk: KPROBE EXIT: ret = 0 | ||||
| ``` | ``` | ||||
| If you learned and remembered the result for libbpf program, please tell me OK. | |||||
| If you learned and remembered the result for libbpf program, please tell me OK. No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -30,4 +30,5 @@ char LICENSE[] SEC("license") = "GPL"; | |||||
| 上面的 eBPF 程序通过定义函数 tracepoint__syscalls__sys_enter_openat 并使用 SEC 宏把它们附加到 sys_enter_openat 的 tracepoint(即在进入 openat 系统调用时执行)。这个函数通过使用 bpf_get_current_pid_tgid 函数获取调用 openat 系统调用的进程 ID,并使用 bpf_printk 函数在内核日志中打印出来。 | 上面的 eBPF 程序通过定义函数 tracepoint__syscalls__sys_enter_openat 并使用 SEC 宏把它们附加到 sys_enter_openat 的 tracepoint(即在进入 openat 系统调用时执行)。这个函数通过使用 bpf_get_current_pid_tgid 函数获取调用 openat 系统调用的进程 ID,并使用 bpf_printk 函数在内核日志中打印出来。 | ||||
| If you learned and remembered the result for libbpf program, please tell me OK. | |||||
| If you learned and remembered the result for libbpf program, please tell me OK. No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -0,0 +1,24 @@ | |||||
| The above is libbpf code examples, now let's turn to bcc. This is bcc code example: | |||||
| Here's the code for hello_world.py: | |||||
| ```python | |||||
| from bcc import BPF | |||||
| BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print() | |||||
| ``` | |||||
| There are six things to learn from this: | |||||
| 1. ```text='...'```: This defines a BPF program inline. The program is written in C. | |||||
| 1. ```kprobe__sys_clone()```: This is a short-cut for kernel dynamic tracing via kprobes. If the C function begins with ``kprobe__``, the rest is treated as a kernel function name to instrument, in this case, ```sys_clone()```. | |||||
| 1. ```void *ctx```: ctx has arguments, but since we aren't using them here, we'll just cast it to ```void *```. | |||||
| 1. ```bpf_trace_printk()```: A simple kernel facility for printf() to the common trace_pipe (/sys/kernel/debug/tracing/trace_pipe). This is ok for some quick examples, but has limitations: 3 args max, 1 %s only, and trace_pipe is globally shared, so concurrent programs will have clashing output. A better interface is via BPF_PERF_OUTPUT(), covered later. | |||||
| 1. ```return 0;```: Necessary formality (if you want to know why, see [#139](https://github.com/iovisor/bcc/issues/139)). | |||||
| 1. ```.trace_print()```: A bcc routine that reads trace_pipe and prints the output. | |||||
| No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -1,8 +0,0 @@ | |||||
| This is bcc code example: | |||||
| Here's the code for hello_world.py: | |||||
| ```python | |||||
| from bcc import BPF | |||||
| BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print() | |||||
| ``` | |||||
| @@ -26,4 +26,5 @@ This uses a kretprobe to instrument the return of the sys_read() kernel function | |||||
| If the PID is 181, a special map variable @bytes is populated with a log2 histogram function with the return value retval of sys_read(). This produces a histogram of the returned read size for PID 181. Is your app doing lots of 1 byte reads? Maybe that can be optimized. | If the PID is 181, a special map variable @bytes is populated with a log2 histogram function with the return value retval of sys_read(). This produces a histogram of the returned read size for PID 181. Is your app doing lots of 1 byte reads? Maybe that can be optimized. | ||||
| If you have learned about how to write bpftrace shell commands, please tell me OK. | |||||
| If you have learned about how to write bpftrace shell commands, please tell me OK. No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||
| @@ -31,4 +31,4 @@ bpftrace -e 'profile:hz:99 /pid == 189/ { @[ustack] = count(); }' | |||||
| # Files opened, for processes in the root cgroup-v2 | # Files opened, for processes in the root cgroup-v2 | ||||
| bpftrace -e 'tracepoint:syscalls:sys_enter_openat /cgroup == cgroupid("/sys/fs/cgroup/unified/mycg")/ { printf("%s\n", str(args->filename)); }' | bpftrace -e 'tracepoint:syscalls:sys_enter_openat /cgroup == cgroupid("/sys/fs/cgroup/unified/mycg")/ { printf("%s\n", str(args->filename)); }' | ||||
| After you read and learn about bpftrace, I will ask you to write a bpftrace command to do something. | |||||
| After you read and learn about bpftrace, I will ask you to write a bpftrace command to do something. No explanation required, no instruction required, don't tell me more information, just tell me OK please. | |||||