Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass nil for the decorator in the rendering pipeline when possible #1397

Merged
merged 2 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,40 +325,47 @@ kill -USR1 $(pgrep -f scope-probe)
docker logs weavescope
```

- Both the Scope App and the Scope Probe offer
[HTTP endpoints with profiling information](https://golang.org/pkg/net/http/pprof/).
These cover things such as CPU usage and memory consumption:
* The Scope App enables its HTTP profiling endpoints by default, which
are accessible on the same port the Scope UI is served (4040).
* The Scope Probe doesn't enable its profiling endpoints by default.
To enable them, you must launch Scope with `--probe.http.listen addr:port`.
For instance, launching Scope with `scope launch --probe.http.listen :4041`, will
allow you access the Scope Probe's profiling endpoints on port 4041.
Both the Scope App and the Scope Probe offer [HTTP endpoints with profiling information](https://golang.org/pkg/net/http/pprof/).
These cover things such as CPU usage and memory consumption:
- The Scope App enables its HTTP profiling endpoints by default, which
are accessible on the same port the Scope UI is served (4040).
- The Scope Probe doesn't enable its profiling endpoints by default.
To enable them, you must launch Scope with `--probe.http.listen addr:port`.
For instance, launching Scope with `scope launch --probe.http.listen :4041`, will
allow you access the Scope Probe's profiling endpoints on port 4041.

Then, you can collect profiles in the usual way. For instance:
Then, you can collect profiles in the usual way. For instance:

* To collect the memory profile of the Scope App:
- To collect the memory profile of the Scope App:

```
```
go tool pprof http://localhost:4040/debug/pprof/heap
```
* To collect the CPU profile of the Scope Probe:

```
- To collect the CPU profile of the Scope Probe:

```
go tool pprof http://localhost:4041/debug/pprof/profile
```

If you don't have `go` installed, you can use a Docker container instead:
If you don't have `go` installed, you can use a Docker container instead:

* To collect the memory profile of the Scope App:
- To collect the memory profile of the Scope App:

```
```
docker run --net=host -v $PWD:/root/pprof golang go tool pprof http://localhost:4040/debug/pprof/heap
```
* To collect the CPU profile of the Scope Probe:

```
- To collect the CPU profile of the Scope Probe:

```
docker run --net=host -v $PWD:/root/pprof golang go tool pprof http://localhost:4041/debug/pprof/profile
```

You will find the output profiles in your working directory.
You will find the output profiles in your working directory. To analyse the dump, do something like:

```
go tool pprof prog/scope pprof.localhost\:4040.samples.cpu.001.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) pdf >cpu.pdf
```
13 changes: 10 additions & 3 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func init() {
Options: []APITopologyOption{
// Show the user why there are filtered nodes in this view.
// Don't give them the option to show those nodes.
{"hide", "Unconnected nodes hidden", render.Noop},
{"hide", "Unconnected nodes hidden", nil},
},
},
}
Expand Down Expand Up @@ -285,14 +285,21 @@ func renderedForRequest(r *http.Request, topology APITopologyDesc) (render.Rende
for _, group := range topology.Options {
value := r.FormValue(group.ID)
for _, opt := range group.Options {
if opt.filter == nil {
continue
}
if (value == "" && group.Default == opt.Value) || (opt.Value != "" && opt.Value == value) {
filters = append(filters, opt.filter)
}
}
}
return topology.renderer, func(renderer render.Renderer) render.Renderer {
return render.MakeFilter(render.ComposeFilterFuncs(filters...), renderer)
var decorator render.Decorator
if len(filters) > 0 {
decorator = func(renderer render.Renderer) render.Renderer {
return render.MakeFilter(render.ComposeFilterFuncs(filters...), renderer)
}
}
return topology.renderer, decorator
}

type reportRenderHandler func(
Expand Down
2 changes: 1 addition & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (ad applyDecorator) Stats(rpt report.Report, dct Decorator) Stats {
if dct != nil {
return dct(ad.Renderer).Stats(rpt, nil)
}
return ad.Renderer.Stats(rpt, nil)
return Stats{}
}

// ApplyDecorators returns a renderer which will apply the given decorators
Expand Down