diff --git a/GPTtrace.py b/GPTtrace.py index 4a278b4..dcb34ac 100755 --- a/GPTtrace.py +++ b/GPTtrace.py @@ -1,6 +1,8 @@ #! /bin/env python3 import argparse import os +import time + from pathlib import Path from typing import List, Optional, Tuple @@ -109,8 +111,9 @@ def main(): input_data = f.read() if args.verbose: print(input_data) - _, session = generate_result( + resp, session = generate_result( chatbot, input_data, conv_uuid, args.verbose) + time.sleep(2.4) print(f"Trained session: {session}") else: parser.print_help() diff --git a/prompts/0.md b/prompts/0.md index 6fab7f4..db9aa04 100644 --- a/prompts/0.md +++ b/prompts/0.md @@ -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. + +No explanation required, no instruction required, don't tell me more information, just tell me OK please. diff --git a/prompts/1.md b/prompts/1.0.md similarity index 91% rename from prompts/1.md rename to prompts/1.0.md index be5ab46..98051c6 100644 --- a/prompts/1.md +++ b/prompts/1.0.md @@ -36,4 +36,5 @@ int handle_tp(void *ctx) - `void *ctx`:ctx本来是具体类型的参数, 但是由于我们这里没有使用这个参数,因此就将其写成void *类型。 - `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. + diff --git a/prompts/1.1.md b/prompts/1.1.md index d4f4b27..da7771c 100644 --- a/prompts/1.1.md +++ b/prompts/1.1.md @@ -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、文件名和返回值。 eunomia-bpf 是一个结合 Wasm 的开源 eBPF 动态加载运行时和开发工具链,它的目的是简化 eBPF 程序的开发、构建、分发、运行。可以参考 下载和安装 ecc 编译工具链和 ecli 运行时。 -我还没有说完,我会继续说。 \ No newline at end of file +我还没有说完,我会继续说。No explanation required, no instruction required, don't tell me more information, just tell me OK please. diff --git a/prompts/1.2.md b/prompts/1.2.md index 643f4a6..9cc2979 100644 --- a/prompts/1.2.md +++ b/prompts/1.2.md @@ -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 ``` -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. + diff --git a/prompts/1.3.md b/prompts/1.3.md index 2f359ee..5ee2708 100644 --- a/prompts/1.3.md +++ b/prompts/1.3.md @@ -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 函数在内核日志中打印出来。 -​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. + diff --git a/prompts/2.0.md b/prompts/2.0.md new file mode 100644 index 0000000..f77573e --- /dev/null +++ b/prompts/2.0.md @@ -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. diff --git a/prompts/2.md b/prompts/2.md deleted file mode 100644 index e6ac645..0000000 --- a/prompts/2.md +++ /dev/null @@ -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() -``` diff --git a/prompts/3.md b/prompts/3.0.md similarity index 90% rename from prompts/3.md rename to prompts/3.0.md index 6b64af0..e0f09db 100644 --- a/prompts/3.md +++ b/prompts/3.0.md @@ -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 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. + diff --git a/prompts/3.1.md b/prompts/3.1.md index 5708d7c..e4c25bb 100644 --- a/prompts/3.1.md +++ b/prompts/3.1.md @@ -31,4 +31,4 @@ bpftrace -e 'profile:hz:99 /pid == 189/ { @[ustack] = count(); }' # 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)); }' -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.