Browse Source

add README and install.sh

pull/3/head
yunwei37 2 years ago
parent
commit
4e6018e246
6 changed files with 78 additions and 6 deletions
  1. +30
    -0
      README.md
  2. +13
    -0
      doc/talk.md
  3. +4
    -0
      install.sh
  4. +1
    -6
      main.py
  5. +29
    -0
      prompts/1.md
  6. +1
    -0
      requirements.txt

+ 30
- 0
README.md View File

@@ -1,2 +1,32 @@
# GPTtrace # GPTtrace


## Usage

```console
python main.py
usage: GPTtrace [-h] [-e | -r TEXT] [-u UUID] [-t ACCESS_TOKEN]

Use ChatGPT to write eBPF programs (bpftrace, etc.)

optional arguments:
-h, --help show this help message and exit
-e, --explain Let ChatGPT explain what's eBPF
-r TEXT, --run TEXT Generate commands using your input with ChatGPT, and run it
-u UUID, --uuid UUID Conversion UUID to use, or passed through environment variable `GPTTRACE_CONV_UUID`
-t ACCESS_TOKEN, --access-token ACCESS_TOKEN
ChatGPT access token, see `https://chat.openai.com/api/auth/session` or passed through
`GPTTRACE_ACCESS_TOKEN`
```

## Examples

- Files opened by process
- Syscall count by program
- Read bytes by process:
- Read size distribution by process:
- Show per-second syscall rates:
- Trace disk size by process
- Count page faults by process
- Count LLC cache misses by process name and PID (uses PMCs):
- Profile user-level stacks at 99 Hertz, for PID 189:
- Files opened, for processes in the root cgroup-v2

+ 13
- 0
doc/talk.md View File

@@ -0,0 +1,13 @@
# talk

当我们开发软件时,经常需要进行调试和追踪,以发现程序中的问题。而 eBPF 技术已经成为了一个越来越受欢迎的工具,它可以帮助我们更加高效地进行追踪和分析。

但是,eBPF 的开发需要一定的专业知识,对于一些不熟悉该技术的开发人员来说,可能会有一定的困难。这时,我们的 demo 工具 GPTtrace 就可以帮助你解决这个问题。

使用 GPTtrace 工具,你只需要用最自然的语言描述你想要追踪的程序,它就会自动为你生成和运行 eBPF 程序,让你更加高效地进行追踪和分析。而且,如果你不了解 eBPF 技术,也不用担心,GPTtrace 会帮助你解释它是什么以及如何使用。

除了自动追踪,GPTtrace 还有其他功能。通过 "-d bpftrace" 和 "-d eunomia" 参数,你可以深入了解 eBPF 的实现细节,并生成内核态代码,提高追踪的效率。而通过 "-o" 参数,你可以生成可执行文件,让你更加方便地运行你的追踪程序。

当然,需要注意的是,GPTtrace 只是一个 demo 工具,不能应用于生产环境。但是,它展示了 ChatGPT 和 eBPF 技术结合的巨大潜力,相信这种结合将在未来的软件开发和调试中发挥重要作用。

因此,如果你想更加高效地进行追踪和分析,GPTtrace 工具是一个值得尝试的工具。让我们期待 ChatGPT 在 eBPF 开发领域中的更多可能性!

+ 4
- 0
install.sh View File

@@ -0,0 +1,4 @@
#!/bin/bash

sudo apt install bpftrace
pip install -r requirements.txt

+ 1
- 6
main.py View File

@@ -11,7 +11,6 @@ from marko.inline import RawText
ENV_UUID = "GPTTRACE_CONV_UUID" ENV_UUID = "GPTTRACE_CONV_UUID"
ENV_ACCESS_TOKEN = "GPTTRACE_ACCESS_TOKEN" ENV_ACCESS_TOKEN = "GPTTRACE_ACCESS_TOKEN"



def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='GPTtrace', prog='GPTtrace',
@@ -50,9 +49,7 @@ def main():
print(f"Command to run: {parsed[0]}") print(f"Command to run: {parsed[0]}")
os.system(parsed[0]) os.system(parsed[0])




def generate_result(bot: Chatbot, text: str, session: str | None, print_out: bool = False) -> str:
def generate_result(bot: Chatbot, text: str, session: str = None, print_out: bool = False) -> str:
from io import StringIO from io import StringIO
prev_text = "" prev_text = ""
buf = StringIO() buf = StringIO()
@@ -69,7 +66,6 @@ def generate_result(bot: Chatbot, text: str, session: str | None, print_out: boo
print() print()
return buf.getvalue() return buf.getvalue()



def extract_code_blocks(text: str) -> List[str]: def extract_code_blocks(text: str) -> List[str]:
result = [] result = []
parser = Parser() parser = Parser()
@@ -80,6 +76,5 @@ def extract_code_blocks(text: str) -> List[str]:
result.append(blk.children) result.append(blk.children)
return result return result



if __name__ == "__main__": if __name__ == "__main__":
main() main()

+ 29
- 0
prompts/1.md View File

@@ -0,0 +1,29 @@
# Files opened by process
bpftrace -e 'tracepoint:syscalls:sys_enter_open { printf("%s %s\n", comm, str(args->filename)); }'

# Syscall count by program
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'

# Read bytes by process:
bpftrace -e 'tracepoint:syscalls:sys_exit_read /args->ret/ { @[comm] = sum(args->ret); }'

# Read size distribution by process:
bpftrace -e 'tracepoint:syscalls:sys_exit_read { @[comm] = hist(args->ret); }'

# Show per-second syscall rates:
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @ = count(); } interval:s:1 { print(@); clear(@); }'

# Trace disk size by process
bpftrace -e 'tracepoint:block:block_rq_issue { printf("%d %s %d\n", pid, comm, args->bytes); }'

# Count page faults by process
bpftrace -e 'software:faults:1 { @[comm] = count(); }'

# Count LLC cache misses by process name and PID (uses PMCs):
bpftrace -e 'hardware:cache-misses:1000000 { @[comm, pid] = count(); }'

# Profile user-level stacks at 99 Hertz, for PID 189:
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)); }'

+ 1
- 0
requirements.txt View File

@@ -35,3 +35,4 @@ tomlkit==0.11.6
typing_extensions==4.5.0 typing_extensions==4.5.0
urllib3==1.26.14 urllib3==1.26.14
wrapt==1.14.1 wrapt==1.14.1
marko==1.3.0

Loading…
Cancel
Save