github.com/operator-framework/operator-lifecycle-manager@v0.30.0/doc/design/profiling.md (about)

     1  # Profiling OLM Operators
     2  
     3  OLM's `olm` and `catalog` commands support serving profiling samples via the `--profiling` option.
     4  
     5  ```sh
     6  # run olm operator with profiling enabled
     7  $ go run cmd/olm/main.go --profiling --kubeconfig ~/.kube/config
     8  ```
     9  
    10  Samples are in a format recognized by [pprof](https://golang.org/pkg/net/http/pprof) and an index of available profile types is made available at `https://127.0.0.1:8080/debug/pprof`.
    11  
    12  If profiling is enabled, but operators are running on a kubernetes cluster, a convienient way to expose samples locally is with `kubectl port-forward`:
    13  
    14  ```sh
    15  # forward traffic from 127.0.0.1:8080 to port 8080 of catalog operator pods
    16  $ kubectl -n <olm-namespace> port-forward deployments/catalog-operator
    17  ```
    18  
    19  When profiling is enabled, `go tool pprof` can be used to export and visualize samples:
    20  
    21  ```sh
    22  # assuming a catalog operator's samples are accessible at 127.0.0.1:8080:
    23  # show in-use heap memory in top format
    24  $ go tool pprof -top http://127.0.0.1:8080/debug/pprof/heap
    25  Fetching profile over HTTP from http://127.0.0.1:8080/debug/pprof/heap
    26  Saved profile in /Users/nhale/pprof/pprof.catalog.alloc_objects.alloc_space.inuse_objects.inuse_space.013.pb.gz
    27  File: catalog
    28  Type: inuse_space
    29  Time: Jun 27, 2019 at 12:27pm (EDT)
    30  Showing nodes accounting for 2202.74kB, 100% of 2202.74kB total
    31        flat  flat%   sum%        cum   cum%
    32    650.62kB 29.54% 29.54%   650.62kB 29.54%  bufio.NewWriterSize
    33    520.04kB 23.61% 53.15%   520.04kB 23.61%  golang.org/x/net/http2.NewFramer.func1
    34    520.04kB 23.61% 76.75%   520.04kB 23.61%  sync.(*Map).LoadOrStore
    35    512.03kB 23.25%   100%   512.03kB 23.25%  github.com/modern-go/reflect2.newUnsafeStructField
    36    ...
    37  
    38  # save in-use objects graph to svg file
    39  $ go tool pprof -sample_index=inuse_objects -svg http://127.0.0.1:8080/debug/pprof/heap
    40  Fetching profile over HTTP from http://127.0.0.1:8080/debug/pprof/heap
    41  Saved profile in /Users/<user>/pprof/pprof.catalog.alloc_objects.alloc_space.inuse_objects.inuse_space.01.pb.gz
    42  Generating report in profile001.svg
    43  ```