Skip to content

Commit

Permalink
Merge pull request #1 from chaozbj/chao-66
Browse files Browse the repository at this point in the history
add profiling subcommand
  • Loading branch information
Lance Liu authored Jul 26, 2020
2 parents 96fb031 + 344ec6e commit 09e76a9
Show file tree
Hide file tree
Showing 5 changed files with 1,097 additions and 0 deletions.
72 changes: 72 additions & 0 deletions plugins/admin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,56 @@ Global Flags:
Use "kn admin autoscaling [command] --help" for more information about a command.
----

#### `kn admin profiling`

----
Enable Knative components profiling and download profile data
Usage:
kn admin profiling [flags]
Aliases:
profiling, prof
Examples:
# To enable profiling
kn admin profiling --enable
# To download heap profile data of autoscaler
kn admin profiling --target autoscaler --heap
# To download 2 minutes execution trace data of networking-istio
kn admin profiling --target networking-istio --trace 2m
# To download go routing block and memory allocations data of activator and save them to /tmp
kn admin profiling --target activator --block --mem-allocs --save-to /tmp
# To download all available profile data for specified pod activator-5979f56548
kn admin profiling --target activator-5979f56548 --all
Flags:
--all Download all profile data
--block Download go routine blocking data
--cpu string Download cpu profile data, you can specify a profile data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
--disable Disable Knative profiling
--enable Enable Knative profiling
--goroutine Download stack traces of all current goroutines data
--heap Download heap profile data
-h, --help help for profiling
--mem-allocs Download memory allocations data
--mutex Download holders of contended mutexes data
-s, --save-to string The path to save the downloaded profile data, if not speicifed, the data will be saved in current working folder
-t, --target string The profiling target. It can be a Knative component name or a specific pod name, e.g: 'activator' or 'activator-586d468c99-w59cm'
--thread-create Download stack traces that led to the creation of new OS threads data
--trace string Download execution trace data, you can specify a trace data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
Global Flags:
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
----
### Examples

Expand Down Expand Up @@ -174,3 +224,25 @@ $ kn admin autoscaling update --scale-to-zero
Updated Knative autoscaling config enable-scale-to-zero: true
-----
=====

#### As a Knative administrator, I want to enable Knative profiling and download profile data.

.Enable Knative profiling.
=====
-----
$ kn admin profiling --enable
Knative profiling is enabled
-----
=====

.Download 5 seconds cpu profile data of activator component and save data to /tmp folder
=====
-----
$ kn admin profiling --target activator --cpu 5s --save-to /tmp
Starting to download profile data for pod activator-586d468c99-w59cm...
Saving 5 second(s) cpu profile data to /tmp/activator-586d468c99-w59cm_cpu_5s_20200725165758
Forwarding from 127.0.0.1:18008 -> 8008
Forwarding from [::1]:18008 -> 8008
Handling connection for 18008
-----
=====
2 changes: 2 additions & 0 deletions plugins/admin/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"knative.dev/client-contrib/plugins/admin/pkg/command"
"knative.dev/client-contrib/plugins/admin/pkg/command/autoscaling"
"knative.dev/client-contrib/plugins/admin/pkg/command/domain"
"knative.dev/client-contrib/plugins/admin/pkg/command/profiling"
private_registry "knative.dev/client-contrib/plugins/admin/pkg/command/registry"
)

Expand All @@ -50,6 +51,7 @@ func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
rootCmd.AddCommand(domain.NewDomainCmd(p))
rootCmd.AddCommand(private_registry.NewPrivateRegistryCmd(p))
rootCmd.AddCommand(autoscaling.NewAutoscalingCmd(p))
rootCmd.AddCommand(profiling.NewProfilingCommand(p))
rootCmd.AddCommand(command.NewVersionCommand())

// Add default help page if there's unknown command
Expand Down
1 change: 1 addition & 0 deletions plugins/admin/core/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestNewAdminCommand(t *testing.T) {
"domain",
"registry",
"autoscaling",
"profiling",
}

cmd := NewAdminCommand()
Expand Down
Loading

0 comments on commit 09e76a9

Please sign in to comment.