Skip to content

Commit 538fc6b

Browse files
committed
Add support for Go execution traces
1 parent 0e63e8e commit 538fc6b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141

4242
Visiting [http://localhost:8080/myroute/](http://localhost:8080/myroute/) will then return:
4343

44-
![](http://f.cl.ly/items/2d13110V2S2H3T1c0n3b/Screen%20Shot%202015-03-19%20at%2017.22.19.png)
44+
![](https://photos-6.dropbox.com/t/2/AAD-NOjqUVH6yKuSAR2sA07VQTQPeVAGCtqEhY-McVehRQ/12/5033766/png/32x32/1/_/1/2/Screen%20Shot%202015-10-29%20at%2017.01.45.png/ENyv4gMYlvYWIAcoBw/vaSYDZEeuTA-8biklDyYORywwvL9SbVYH41Jff_CuBk?size=1600x1200&size_mode=2)
4545

4646
`netbug` also provides a simple way of adding some authentication:
4747

@@ -79,6 +79,17 @@ As an example though, if you want to run a 30-second CPU profile on your running
7979
$ go tool pprof https://example.com/myroute/profile
8080
```
8181

82+
##### New in Go 1.5
83+
You can now produce [execution traces](https://golang.org/pkg/runtime/trace/) of your remotely running program using netbug.
84+
85+
To do this run one of the trace profiles, which will result in a file being downloaded. Then use the Go `trace` tool to generate a trace, which will open up in your browser.
86+
87+
```
88+
$ go tool trace binary-being-profiled /path/to/downloaded/trace
89+
```
90+
91+
When compiling `binary-being-profiled`, you will need to have targeted the same architecture as the binary that generated the profile.
92+
8293
## Background
8394
The [net/http/pprof](http://golang.org/pkg/net/http/pprof/) package is great.
8495
It let's you access profiling and debug information about your running services, via `HTTP`, and even plugs straight into `go tool pprof`.

netbug.go

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func handler(token string) http.Handler {
3333
nhpprof.Cmdline(w, r)
3434
case "profile":
3535
nhpprof.Profile(w, r)
36+
case "trace":
37+
nhpprof.Trace(w, r)
3638
case "symbol":
3739
nhpprof.Symbol(w, r)
3840
default:
@@ -125,6 +127,8 @@ var indexTmpl = template.Must(template.New("index").Parse(`<html>
125127
<tr><td align=right>{{.Count}}<td><a href="{{.Name}}?debug=1{{if $.Token}}&token={{$.Token}}{{end}}">{{.Name}}</a>
126128
{{end}}
127129
<tr><td align=right><td><a href="profile{{if .Token}}?token={{.Token}}{{end}}">CPU</a>
130+
<tr><td align=right><td><a href="trace?seconds=5{{if .Token}}&token={{.Token}}{{end}}">5-second trace</a>
131+
<tr><td align=right><td><a href="trace?seconds=30{{if .Token}}&token={{.Token}}{{end}}">30-second trace</a>
128132
</table>
129133
<br>
130134
debug information:<br>

0 commit comments

Comments
 (0)