3.4 KiB
title, date, weight, geekdocRepo, geekdocEditPath, geekdocFilePath
| title | date | weight | geekdocRepo | geekdocEditPath | geekdocFilePath |
|---|---|---|---|---|---|
| Profiling | 2021-08-24T12:32:20+01:00 | 56 | https://github.com/owncloud/ocis | edit/master/docs/ocis/development | profiling.md |
{{< toc >}}
The only way to enable the profiler currently is to explicitly select which areas to collect samples for. In order to do this, the following steps have to be followed.
1. Clone Reva
git clone github.com/cs3org/reva
2. Patch reva with the area that you want sampled.
For the purposes of this docs let's use the WebDAV PROPFIND path.
diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go
index 0e9c99be..f271572f 100644
--- a/internal/http/services/owncloud/ocdav/propfind.go
+++ b/internal/http/services/owncloud/ocdav/propfind.go
@@ -32,6 +32,8 @@ import (
"strings"
"time"
+ _ "net/http/pprof"
+
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
@@ -311,6 +313,12 @@ func requiresExplicitFetching(n *xml.Name) bool {
return true
}
+func init() {
+ go func() {
+ http.ListenAndServe(":1234", nil)
+ }()
+}
+
// from https://github.com/golang/net/blob/e514e69ffb8bc3c76a71ae40de0118d794855992/webdav/xml.go#L178-L205
func readPropfind(r io.Reader) (pf propfindXML, status int, err error) {
c := countingReader{r: r}
The previous patch will:
- import
net/http/pprof, which will register debug handlers inDefaultServeMux. - define a
init()function that starts an http server with the previously registered handlers.
With everything running one should have access to http://localhost:1234/debug/pprof/
3. Replace reva in oCIS go.mod with local version and build a new binary
diff --git a/go.mod b/go.mod
index 131d14d7b..9668c38e4 100644
--- a/go.mod
+++ b/go.mod
@@ -78,6 +78,7 @@ require (
replace (
github.com/crewjam/saml => github.com/crewjam/saml v0.4.5
+ github.com/cs3org/reva => path/to/your/reva
go.etcd.io/etcd/api/v3 => go.etcd.io/etcd/api/v3 v3.0.0-20210204162551-dae29bb719dd
go.etcd.io/etcd/pkg/v3 => go.etcd.io/etcd/pkg/v3 v3.0.0-20210204162551-dae29bb719dd
)
Make sure to replace github.com/cs3org/reva => path/to/your/reva with the correct location of your reva.
4. Build a new ocis binary
From owncloud/ocis root:
$ cd ocis
$ make clean build
5. Start oCIS server
From owncloud/ocis root:
$ OCIS_LOG_PRETTY=true OCIS_LOG_COLOR=true ocis/bin/ocis server
6. Run pprof
Install pprof
If pprof is not installed make sure to get it; one way of installing it is using the Go tools:
$ go get -u github.com/google/pprof
Collecting samples
Collect 30 seconds of samples:
$ prof -web http://:1234/debug/pprof/profile\?seconds\=30
Once the collection is done a browser tab will open with the result svg, looking similar to this:
For references on how to interpret this graph, continue reading here.
