Skip to content

Commit

Permalink
Add bpftrace examples to the demo
Browse files Browse the repository at this point in the history
bpftrace is at least as prevalent as bcc-tools now so lets include it in
the example commands to be used with the demo.
  • Loading branch information
mmcshane committed Jan 1, 2021
1 parent a8d308f commit 2b0d691
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ anything after that. In the second window run the bcc trace program on the
`salpdemo` process, monitoring probes `p1` and `p2`.

```bash
sudo trace -p "$(pgrep salpdemo | head -n1)" \
'u::p1 "arg1=%d arg2=%s", arg1, arg2' \
'u::p2 "arg1=%d", arg1'
sudo trace -p "$(pgrep -n salpdemo)" \
'u::p1 "i=%d err='%s' date='%s'", arg1, arg2, arg3' \
'u::p2 "j=%d flag=%d", arg1, arg2'
```

`trace` will output the values of `arg1` and `arg2` from probe `p1` and the
value of `arg1` from probe `p2`.
or alternatively the same thing with `bpftrace`

```bash
sudo bpftrace -p "$(pgrep -n salpdemo)" /dev/stdin <<EOF
usdt:p1 { printf("i=%d err='%s' date='%s'\n", arg0, str(arg1), str(arg2)); }
usdt:p2 { printf("j=%d flag=%d\n", arg0, arg1); }
EOF
```

Either trace invocations will output the values of the three args to probe 1 and
the two args to probe 2.
20 changes: 14 additions & 6 deletions internal/salpdemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ var (

func main() {
defer salp.UnloadAndDispose(probes)
fmt.Println("List the go probes in this demo with")
fmt.Println("\tsudo tplist -vp \"$(pgrep salpdemo)\" \"salp-demo*\"")
fmt.Println("Trace this process with")
fmt.Println("\tsudo trace -p \"$(pgrep salpdemo | head -n1)\" 'u::p1 \"i=%d err=`%s` date=`%s`\", arg1, arg2, arg3' 'u::p2 \"j=%d flag=%d\", arg1, arg2'")
fmt.Println("\tor")
fmt.Println("\tsudo trace -p \"$(pgrep salpdemo | head -n1)\" 'u::p1 (arg1 % 2 == 0) \"i=%d err='%s'\", arg1, arg2'")
fmt.Println(`List the go probes in this demo
# With bcc tools
sudo tplist -vp "$(pgrep -n salpdemo)" "*salp-demo*"
# With bpftrace
sudo bpftrace -p "$(pgrep -n salpdemo)" -l "usdt:*:salp-demo:*"
Trace this process
# With bcc tools
sudo trace -p "$(pgrep -n salpdemo)" 'u::p1 "i=%d err='%s' date='%s'", arg1, arg2, arg3' 'u::p2 "j=%d flag=%d", arg1, arg2'
# With bpftrace
sudo bpftrace -p "$(pgrep -n salpdemo)" -e 'usdt:p1 { printf("%d (%s)\n", arg0, str(arg2)); }'
sudo bpftrace -p "$(pgrep -n salpdemo)" -e 'usdt:p2 { if(arg1) { printf("Truthy! %d\n", arg0); } }'`)

salp.MustLoadProvider(probes)

Expand Down

0 comments on commit 2b0d691

Please sign in to comment.