This is an automated email from the ASF dual-hosted git repository.
liuhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
The following commit(s) were added to refs/heads/master by this push:
new 9a1beab support pprof cli feature (#226)
9a1beab is described below
commit 9a1beab08413ce415a00a8547a238a14691c5655
Author: Jingyi Qu <[email protected]>
AuthorDate: Mon Oct 13 19:47:03 2025 +0800
support pprof cli feature (#226)
---
CHANGES.md | 1 +
assets/graphqls/profiling/pprof/CreateTask.graphql | 24 ++++++
.../graphqls/profiling/pprof/GetAnalysis.graphql | 30 +++++++
.../graphqls/profiling/pprof/GetTaskList.graphql | 31 +++++++
.../profiling/pprof/GetTaskProgress.graphql | 30 +++++++
dist/LICENSE | 2 +-
go.mod | 2 +-
go.sum | 4 +-
internal/commands/interceptor/instance.go | 1 +
internal/commands/interceptor/service.go | 1 +
internal/commands/profiling/pprof/create.go | 96 ++++++++++++++++++++++
internal/commands/profiling/pprof/getAnalyze.go | 74 +++++++++++++++++
internal/commands/profiling/pprof/getTaskList.go | 85 +++++++++++++++++++
.../commands/profiling/pprof/getTaskProgress.go | 54 ++++++++++++
.../profiling/{profiling.go => pprof/pprof.go} | 25 ++----
internal/commands/profiling/profiling.go | 2 +
.../profiling.go => model/pprof/pprofEventType.go} | 43 ++++++----
pkg/graphql/profiling/pprof.go | 72 ++++++++++++++++
18 files changed, 539 insertions(+), 38 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 4ae94b8..3af9896 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -15,6 +15,7 @@ Release Notes.
* Add the `trace-v2 list` command for adapt the new trace query API by
@mrproliu in https://github.com/apache/skywalking-cli/pull/225
* Add the duration field in the `trace list` command by @mrproliu in
https://github.com/apache/skywalking-cli/pull/225
* Remove the oldest `queryTraceFromColdStage` query call in the `trace list`
command by @mrproliu in https://github.com/apache/skywalking-cli/pull/225
+* Add the sub-command `profiling pprof` for pprof query API by @JophieQu in
https://github.com/apache/skywalking-cli/pull/226
### Bug Fixes
diff --git a/assets/graphqls/profiling/pprof/CreateTask.graphql
b/assets/graphqls/profiling/pprof/CreateTask.graphql
new file mode 100644
index 0000000..385e236
--- /dev/null
+++ b/assets/graphqls/profiling/pprof/CreateTask.graphql
@@ -0,0 +1,24 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+mutation ($condition: PprofTaskCreationRequest!) {
+ result: createPprofTask(pprofTaskCreationRequest: $condition) {
+ errorReason
+ code
+ id
+ }
+}
\ No newline at end of file
diff --git a/assets/graphqls/profiling/pprof/GetAnalysis.graphql
b/assets/graphqls/profiling/pprof/GetAnalysis.graphql
new file mode 100644
index 0000000..3e7c590
--- /dev/null
+++ b/assets/graphqls/profiling/pprof/GetAnalysis.graphql
@@ -0,0 +1,30 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+query ($condition: PprofAnalyzationRequest!) {
+ result: queryPprofAnalyze(request: $condition) {
+ tree {
+ elements {
+ id
+ parentId
+ codeSignature
+ total
+ self
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/assets/graphqls/profiling/pprof/GetTaskList.graphql
b/assets/graphqls/profiling/pprof/GetTaskList.graphql
new file mode 100644
index 0000000..fc0ec70
--- /dev/null
+++ b/assets/graphqls/profiling/pprof/GetTaskList.graphql
@@ -0,0 +1,31 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+query ($condition: PprofTaskListRequest!) {
+ result: queryPprofTaskList(request: $condition) {
+ errorReason
+ tasks {
+ serviceId
+ serviceInstanceIds
+ createTime
+ events
+ duration
+ dumpPeriod
+ id
+ }
+ }
+}
diff --git a/assets/graphqls/profiling/pprof/GetTaskProgress.graphql
b/assets/graphqls/profiling/pprof/GetTaskProgress.graphql
new file mode 100644
index 0000000..0c74658
--- /dev/null
+++ b/assets/graphqls/profiling/pprof/GetTaskProgress.graphql
@@ -0,0 +1,30 @@
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+query ($taskId: String!){
+ result: queryPprofTaskProgress(taskId: $taskId) {
+ errorInstanceIds
+ successInstanceIds
+ logs {
+ id
+ instanceId
+ instanceName
+ operationType
+ operationTime
+ }
+ }
+}
\ No newline at end of file
diff --git a/dist/LICENSE b/dist/LICENSE
index e88d41e..fad46a8 100644
--- a/dist/LICENSE
+++ b/dist/LICENSE
@@ -213,7 +213,7 @@ The text of each license is also included at
licenses/license-[project].txt.
sigs.k8s.io/controller-runtime v0.20.4 Apache-2.0
sigs.k8s.io/randfill v1.0.0 Apache-2.0
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 Apache-2.0
- skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc
Apache-2.0
+ skywalking.apache.org/repo/goapi v0.0.0-20251011100214-efff910f2031
Apache-2.0
========================================================================
Apache-2.0 and BSD-3-Clause licenses
diff --git a/go.mod b/go.mod
index 6a22c66..4230fda 100644
--- a/go.mod
+++ b/go.mod
@@ -18,7 +18,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.33.1
sigs.k8s.io/controller-runtime v0.20.4
- skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc
+ skywalking.apache.org/repo/goapi v0.0.0-20251011100214-efff910f2031
)
require (
diff --git a/go.sum b/go.sum
index 6587f3f..d664728 100644
--- a/go.sum
+++ b/go.sum
@@ -543,5 +543,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.7.0
h1:qPeWmscJcXP0snki5IYF79Z8xrl8ETFxg
sigs.k8s.io/structured-merge-diff/v4 v4.7.0/go.mod
h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
-skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc
h1:HhlLDl0aOIgiIdJl9p0a7PHHdZbs9epKEnewB7AWdZs=
-skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc/go.mod
h1:Vj9vINJYsTQASPsbQ1i81YgH8nFC/Xds4GjcXvmRYwM=
+skywalking.apache.org/repo/goapi v0.0.0-20251011100214-efff910f2031
h1:iMd6gzltWrWOtV3COm0mWydeXhpy7r1vkNlTsm7Co0g=
+skywalking.apache.org/repo/goapi v0.0.0-20251011100214-efff910f2031/go.mod
h1:Vj9vINJYsTQASPsbQ1i81YgH8nFC/Xds4GjcXvmRYwM=
diff --git a/internal/commands/interceptor/instance.go
b/internal/commands/interceptor/instance.go
index d381717..83ccfbb 100644
--- a/internal/commands/interceptor/instance.go
+++ b/internal/commands/interceptor/instance.go
@@ -106,6 +106,7 @@ func parseInstanceList(required bool, idListFlagName,
nameListFlagName, serviceI
if idsArg == "" && namesArgs == "" {
if required {
+ _ = cli.ShowSubcommandHelp(ctx)
return fmt.Errorf(`either flags "--%s" or
"--%s" must be given`, idListFlagName, nameListFlagName)
}
return nil
diff --git a/internal/commands/interceptor/service.go
b/internal/commands/interceptor/service.go
index d87e12a..183cc3b 100644
--- a/internal/commands/interceptor/service.go
+++ b/internal/commands/interceptor/service.go
@@ -74,6 +74,7 @@ func parseService(required bool, idFlagName, nameFlagName
string, nodeType nodeT
if id == "" && name == "" {
if required {
+ _ = cli.ShowSubcommandHelp(ctx)
return fmt.Errorf(`either flags "--%s" or
"--%s" must be given`, idFlagName, nameFlagName)
}
return nil
diff --git a/internal/commands/profiling/pprof/create.go
b/internal/commands/profiling/pprof/create.go
new file mode 100644
index 0000000..618c4df
--- /dev/null
+++ b/internal/commands/profiling/pprof/create.go
@@ -0,0 +1,96 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package pprof
+
+import (
+ "strings"
+
+ "github.com/urfave/cli/v2"
+ "skywalking.apache.org/repo/goapi/query"
+
+ "github.com/apache/skywalking-cli/internal/commands/interceptor"
+ "github.com/apache/skywalking-cli/internal/flags"
+ "github.com/apache/skywalking-cli/internal/model/pprof"
+ "github.com/apache/skywalking-cli/pkg/display"
+ "github.com/apache/skywalking-cli/pkg/display/displayable"
+ "github.com/apache/skywalking-cli/pkg/graphql/profiling"
+)
+
+var createCommand = &cli.Command{
+ Name: "create",
+ Aliases: []string{"c"},
+ Usage: "Create a new pprof task",
+ UsageText: `Create a new pprof task
+
+Examples:
+1. Create pprof task
+$ swctl profiling pprof create --service-name=service-name --duration=10
--events=mutex \
+ --instance-name-list=instance-name1,instance-name2 --dump-period=1`,
+ Flags: flags.Flags(
+ flags.ServiceFlags,
+ flags.InstanceListFlags,
+ []cli.Flag{
+ &cli.IntFlag{
+ Name: "duration",
+ Usage: "task continuous time(minute), required
for cpu, block and mutex events. ",
+ },
+ &cli.GenericFlag{
+ Name: "events",
+ Usage: "which event types this task needs to
collect.",
+ Required: true,
+ Value: &pprof.ProfilingEventTypeEnumValue{
+ Enum: query.AllPprofEventType,
+ Default: query.PprofEventTypeCPU,
+ },
+ },
+ &cli.StringFlag{
+ Name: "dump-period",
+ Usage: "pprof dump period parameters, required
for block and mutex events. ",
+ },
+ },
+ ),
+ Before: interceptor.BeforeChain(
+ interceptor.ParseService(true),
+ interceptor.ParseInstanceList(true),
+ ),
+ Action: func(ctx *cli.Context) error {
+ serviceID := ctx.String("service-id")
+ instanceIDs := strings.Split(ctx.String("instance-id-list"),
",")
+ eventTypes :=
ctx.Generic("events").(*pprof.ProfilingEventTypeEnumValue).Selected
+ var dumpPeriod, duration *int
+ if durationtime := ctx.Int("duration"); durationtime != 0 {
+ duration = &durationtime
+ }
+ if period := ctx.Int("dump-period"); period != 0 {
+ dumpPeriod = &period
+ }
+ request := &query.PprofTaskCreationRequest{
+ ServiceID: serviceID,
+ ServiceInstanceIds: instanceIDs,
+ Duration: duration,
+ Events: eventTypes,
+ DumpPeriod: dumpPeriod,
+ }
+ task, err := profiling.CreatePprofTask(ctx.Context, request)
+ if err != nil {
+ return err
+ }
+
+ return display.Display(ctx.Context,
&displayable.Displayable{Data: task, Condition: request})
+ },
+}
diff --git a/internal/commands/profiling/pprof/getAnalyze.go
b/internal/commands/profiling/pprof/getAnalyze.go
new file mode 100644
index 0000000..fe0dd09
--- /dev/null
+++ b/internal/commands/profiling/pprof/getAnalyze.go
@@ -0,0 +1,74 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package pprof
+
+import (
+ "strings"
+
+ "github.com/urfave/cli/v2"
+ "skywalking.apache.org/repo/goapi/query"
+
+ "github.com/apache/skywalking-cli/internal/commands/interceptor"
+ "github.com/apache/skywalking-cli/internal/flags"
+ "github.com/apache/skywalking-cli/pkg/display"
+ "github.com/apache/skywalking-cli/pkg/display/displayable"
+ "github.com/apache/skywalking-cli/pkg/graphql/profiling"
+)
+
+var analysisCommand = &cli.Command{
+ Name: "analysis",
+ Aliases: []string{"a"},
+ Usage: "Query pprof analysis",
+ UsageText: `Query pprof analysis
+
+Examples:
+1. Query the flame graph produced by pprof
+$ swctl profiling pprof analysis --service-name=service-name --task-id=task-id
\
+ --instance-name-list=instance-name1,instance-name2`,
+ Flags: flags.Flags(
+ flags.ServiceFlags,
+ flags.InstanceListFlags,
+ []cli.Flag{
+ &cli.StringFlag{
+ Name: "task-id",
+ Usage: "pprof task id",
+ Required: true,
+ },
+ },
+ ),
+ Before: interceptor.BeforeChain(
+ interceptor.ParseService(true),
+ interceptor.ParseInstanceList(true),
+ ),
+ Action: func(ctx *cli.Context) error {
+ taskID := ctx.String("task-id")
+ instances := strings.Split(ctx.String("instance-id-list"), ",")
+
+ request := &query.PprofAnalyzationRequest{
+ TaskID: taskID,
+ InstanceIds: instances,
+ }
+
+ analyze, err := profiling.GetPprofAnalyze(ctx.Context, request)
+ if err != nil {
+ return err
+ }
+
+ return display.Display(ctx.Context,
&displayable.Displayable{Data: analyze, Condition: request})
+ },
+}
diff --git a/internal/commands/profiling/pprof/getTaskList.go
b/internal/commands/profiling/pprof/getTaskList.go
new file mode 100644
index 0000000..f6df79b
--- /dev/null
+++ b/internal/commands/profiling/pprof/getTaskList.go
@@ -0,0 +1,85 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package pprof
+
+import (
+ "github.com/urfave/cli/v2"
+ "skywalking.apache.org/repo/goapi/query"
+
+ "github.com/apache/skywalking-cli/internal/commands/interceptor"
+ "github.com/apache/skywalking-cli/internal/flags"
+ "github.com/apache/skywalking-cli/internal/model"
+ "github.com/apache/skywalking-cli/pkg/display"
+ "github.com/apache/skywalking-cli/pkg/display/displayable"
+ "github.com/apache/skywalking-cli/pkg/graphql/profiling"
+)
+
+var getTaskListCommand = &cli.Command{
+ Name: "list",
+ Aliases: []string{"l"},
+ Usage: "Query pprof task list",
+ UsageText: `Query pprof task list
+
+Examples:
+1. Query all pprof tasks
+$ swctl profiling pprof list --service-name=service-name`,
+ Flags: flags.Flags(
+ flags.ServiceFlags,
+ flags.DurationFlags,
+ []cli.Flag{
+ &cli.IntFlag{
+ Name: "limit",
+ Usage: "Limit defines the number of the tasks
to be returned.",
+ },
+ },
+ ),
+ Before: interceptor.BeforeChain(
+ interceptor.ParseService(true),
+ interceptor.DurationInterceptor,
+ ),
+ Action: func(ctx *cli.Context) error {
+ serviceID := ctx.String("service-id")
+ start := ctx.String("start")
+ end := ctx.String("end")
+ step := ctx.Generic("step")
+ cold := ctx.Bool("cold")
+ duration := query.Duration{
+ Start: start,
+ End: end,
+ Step: step.(*model.StepEnumValue).Selected,
+ ColdStage: &cold,
+ }
+ var limit *int
+ if limitArg := ctx.Int("limit"); limitArg != 0 {
+ limit = &limitArg
+ }
+
+ request := &query.PprofTaskListRequest{
+ ServiceID: serviceID,
+ QueryDuration: &duration,
+ Limit: limit,
+ }
+
+ tasks, err := profiling.GetPprofTaskList(ctx.Context, request)
+ if err != nil {
+ return err
+ }
+
+ return display.Display(ctx.Context,
&displayable.Displayable{Data: tasks, Condition: request})
+ },
+}
diff --git a/internal/commands/profiling/pprof/getTaskProgress.go
b/internal/commands/profiling/pprof/getTaskProgress.go
new file mode 100644
index 0000000..f032590
--- /dev/null
+++ b/internal/commands/profiling/pprof/getTaskProgress.go
@@ -0,0 +1,54 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package pprof
+
+import (
+ "github.com/urfave/cli/v2"
+
+ "github.com/apache/skywalking-cli/pkg/display"
+ "github.com/apache/skywalking-cli/pkg/display/displayable"
+ "github.com/apache/skywalking-cli/pkg/graphql/profiling"
+)
+
+var getTaskProgressCommand = &cli.Command{
+ Name: "progress",
+ Aliases: []string{"p"},
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "task-id",
+ Usage: "pprof task id.",
+ Required: true,
+ },
+ },
+ Usage: "Query pprof task progress",
+ UsageText: `Query pprof task progress
+
+Examples:
+1. Query task progress, including task logs and successInstances and
errorInstances
+$ swctl profiling pprof progress --task-id=task-id`,
+ Action: func(ctx *cli.Context) error {
+ taskID := ctx.String("task-id")
+
+ data, err := profiling.GetPprofTaskProgress(ctx.Context, taskID)
+ if err != nil {
+ return err
+ }
+
+ return display.Display(ctx.Context,
&displayable.Displayable{Data: data, Condition: taskID})
+ },
+}
diff --git a/internal/commands/profiling/profiling.go
b/internal/commands/profiling/pprof/pprof.go
similarity index 58%
copy from internal/commands/profiling/profiling.go
copy to internal/commands/profiling/pprof/pprof.go
index 54144b6..fdb4019 100644
--- a/internal/commands/profiling/profiling.go
+++ b/internal/commands/profiling/pprof/pprof.go
@@ -15,26 +15,17 @@
// specific language governing permissions and limitations
// under the License.
-package profiling
+package pprof
-import (
- "github.com/urfave/cli/v2"
-
-
"github.com/apache/skywalking-cli/internal/commands/profiling/asyncprofiler"
-
"github.com/apache/skywalking-cli/internal/commands/profiling/continuous"
- "github.com/apache/skywalking-cli/internal/commands/profiling/ebpf"
- "github.com/apache/skywalking-cli/internal/commands/profiling/trace"
-)
+import "github.com/urfave/cli/v2"
var Command = &cli.Command{
- Name: "profiling",
- Usage: "profiling related sub-command",
- UsageText: `If your application has performance issue, you could try to
profiling.
-Please following sub-command to get more information.`,
+ Name: "pprof",
+ Usage: "pprof related sub-command",
Subcommands: []*cli.Command{
- trace.Command,
- ebpf.Command,
- continuous.Command,
- asyncprofiler.Command,
+ createCommand,
+ getTaskListCommand,
+ getTaskProgressCommand,
+ analysisCommand,
},
}
diff --git a/internal/commands/profiling/profiling.go
b/internal/commands/profiling/profiling.go
index 54144b6..bc2eab1 100644
--- a/internal/commands/profiling/profiling.go
+++ b/internal/commands/profiling/profiling.go
@@ -23,6 +23,7 @@ import (
"github.com/apache/skywalking-cli/internal/commands/profiling/asyncprofiler"
"github.com/apache/skywalking-cli/internal/commands/profiling/continuous"
"github.com/apache/skywalking-cli/internal/commands/profiling/ebpf"
+ "github.com/apache/skywalking-cli/internal/commands/profiling/pprof"
"github.com/apache/skywalking-cli/internal/commands/profiling/trace"
)
@@ -36,5 +37,6 @@ Please following sub-command to get more information.`,
ebpf.Command,
continuous.Command,
asyncprofiler.Command,
+ pprof.Command,
},
}
diff --git a/internal/commands/profiling/profiling.go
b/internal/model/pprof/pprofEventType.go
similarity index 54%
copy from internal/commands/profiling/profiling.go
copy to internal/model/pprof/pprofEventType.go
index 54144b6..08eeaf8 100644
--- a/internal/commands/profiling/profiling.go
+++ b/internal/model/pprof/pprofEventType.go
@@ -15,26 +15,35 @@
// specific language governing permissions and limitations
// under the License.
-package profiling
+package pprof
import (
- "github.com/urfave/cli/v2"
+ "fmt"
+ "strings"
-
"github.com/apache/skywalking-cli/internal/commands/profiling/asyncprofiler"
-
"github.com/apache/skywalking-cli/internal/commands/profiling/continuous"
- "github.com/apache/skywalking-cli/internal/commands/profiling/ebpf"
- "github.com/apache/skywalking-cli/internal/commands/profiling/trace"
+ api "skywalking.apache.org/repo/goapi/query"
)
-var Command = &cli.Command{
- Name: "profiling",
- Usage: "profiling related sub-command",
- UsageText: `If your application has performance issue, you could try to
profiling.
-Please following sub-command to get more information.`,
- Subcommands: []*cli.Command{
- trace.Command,
- ebpf.Command,
- continuous.Command,
- asyncprofiler.Command,
- },
+type ProfilingEventTypeEnumValue struct {
+ Enum []api.PprofEventType
+ Default api.PprofEventType
+ Selected api.PprofEventType
+}
+
+func (e *ProfilingEventTypeEnumValue) Set(value string) error {
+ for _, enum := range e.Enum {
+ if strings.EqualFold(enum.String(), value) {
+ e.Selected = enum
+ return nil
+ }
+ }
+ orders := make([]string, len(api.AllPprofEventType))
+ for i, order := range api.AllPprofEventType {
+ orders[i] = order.String()
+ }
+ return fmt.Errorf("allowed analysis aggregate type are %s",
strings.Join(orders, ", "))
+}
+
+func (e *ProfilingEventTypeEnumValue) String() string {
+ return e.Selected.String()
}
diff --git a/pkg/graphql/profiling/pprof.go b/pkg/graphql/profiling/pprof.go
new file mode 100644
index 0000000..6f4a70b
--- /dev/null
+++ b/pkg/graphql/profiling/pprof.go
@@ -0,0 +1,72 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package profiling
+
+import (
+ "context"
+
+ "github.com/machinebox/graphql"
+ api "skywalking.apache.org/repo/goapi/query"
+
+ "github.com/apache/skywalking-cli/assets"
+ "github.com/apache/skywalking-cli/pkg/graphql/client"
+)
+
+func CreatePprofTask(ctx context.Context, condition
*api.PprofTaskCreationRequest) (api.PprofTaskCreationResult, error) {
+ var response map[string]api.PprofTaskCreationResult
+
+ request :=
graphql.NewRequest(assets.Read("graphqls/profiling/pprof/CreateTask.graphql"))
+ request.Var("condition", condition)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}
+
+func GetPprofTaskProgress(ctx context.Context, taskID string)
(api.PprofTaskProgress, error) {
+ var response map[string]api.PprofTaskProgress
+
+ request :=
graphql.NewRequest(assets.Read("graphqls/profiling/pprof/GetTaskProgress.graphql"))
+ request.Var("taskId", taskID)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}
+
+func GetPprofTaskList(ctx context.Context, condition
*api.PprofTaskListRequest) (api.PprofTaskListResult, error) {
+ var response map[string]api.PprofTaskListResult
+
+ request :=
graphql.NewRequest(assets.Read("graphqls/profiling/pprof/GetTaskList.graphql"))
+ request.Var("condition", condition)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}
+
+func GetPprofAnalyze(ctx context.Context, condition
*api.PprofAnalyzationRequest) (api.PprofAnalyzation, error) {
+ var response map[string]api.PprofAnalyzation
+
+ request :=
graphql.NewRequest(assets.Read("graphqls/profiling/pprof/GetAnalysis.graphql"))
+ request.Var("condition", condition)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}