Skip to content

Commit

Permalink
Support eBPF profiling related commands (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Mar 24, 2022
1 parent db980b5 commit 60cee4a
Show file tree
Hide file tree
Showing 40 changed files with 1,401 additions and 72 deletions.
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ header:
- '.gitignore'
- 'go.mod'
- 'go.sum'
- 'pkg/display/graph/flamegraph/flamegraph.html'

comment: on-failure
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Release Notes.
- Change the GraphQL method to the v9 version according to the server version.(#134)
- Add `normal` field to Service entity.(#136)
- Add the command `process` for query Process metadata.(#137)
- Add the command `profiling ebpf` for process ebpf profiling.(#138)
- [Breaking Change] Update the command `profile` as a sub-command `profiling trace`, and update `profiled-analyze` command to `analysis`.(#138)
- `profiling ebpf/trace analysis` generates the profiling graph HTML on default and saves it to the current work directory.(#138)

### Bug Fixes

Expand Down
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,11 @@
See the License for the specific language governing permissions and
limitations under the License.

========================================================================
Apache 2.0 licenses
========================================================================

The following components are provided under the Apache License. See project link for details.
The text of each license is the standard Apache 2.0 license.

pkg/display/graph/flamegraph files from jvm-profiling-tools/async-profiler: https://github.com/jvm-profiling-tools/async-profiler Apache-2.0
Original file line number Diff line number Diff line change
@@ -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 ($request: EBPFProfilingTaskFixedTimeCreationRequest!){
result: createEBPFProfilingFixedTimeTask(request: $request) {
status
id
errorReason
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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: ID!, $duration: Duration!){
result: queryEBPFProfilingSchedules(taskId: $taskID, duration: $duration) {
scheduleId
taskId
startTime
endTime
process {
id
name
serviceId
serviceName
instanceId
instanceName
layer
agentId
detectType
attributes {
name
value
}
}
}
}
34 changes: 34 additions & 0 deletions assets/graphqls/profiling/ebpf/QueryEBPFProfilingTaskList.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 ($query: EBPFProfilingTaskCondition){
result: queryEBPFProfilingTasks(query: $query) {
taskId
processFinderType
serviceId
serviceName
instanceId
instanceName
processId
processName
taskStartTime
triggerType
fixedTriggerDuration
targetType
createTime
}
}
Original file line number Diff line number Diff line change
@@ -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 ($taskID: ID!, $timeRanges: [EBPFProfilingAnalyzeTimeRange!]!){
result: getEBPFProfilingAnalyzation(taskId: $taskID, timeRanges: $timeRanges) {
tip
trees {
elements {
id
parentId
symbol
stackType
dumpCount
}
}
}
}
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions cmd/swctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package main

import (
_ "embed"
"os"
"runtime"

Expand All @@ -36,7 +37,7 @@ import (
"github.com/apache/skywalking-cli/internal/commands/logs"
"github.com/apache/skywalking-cli/internal/commands/metrics"
"github.com/apache/skywalking-cli/internal/commands/process"
"github.com/apache/skywalking-cli/internal/commands/profile"
"github.com/apache/skywalking-cli/internal/commands/profiling"
"github.com/apache/skywalking-cli/internal/commands/service"
"github.com/apache/skywalking-cli/internal/commands/trace"
"github.com/apache/skywalking-cli/internal/logger"
Expand Down Expand Up @@ -96,12 +97,12 @@ services, service instances, etc.`
install.Command,
event.Command,
logs.Command,
profile.Command,
completion.Command,
dependency.Command,
alarm.Command,
layer.Command,
process.Command,
profiling.Command,
}

app.Before = interceptor.BeforeChain(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.1
sigs.k8s.io/controller-runtime v0.7.0
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe
skywalking.apache.org/repo/goapi v0.0.0-20220322033350-0661327d31e3
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe h1:Txa1/FZfiA++l6gEC843VMhM4nMGatag/mzk1j4dhWw=
skywalking.apache.org/repo/goapi v0.0.0-20220310042848-795a2b3fcdfe/go.mod h1:wzVLZ8F88Idy5tlmcGgJCH2NY8GUWxJ2RuNVXkao+SM=
skywalking.apache.org/repo/goapi v0.0.0-20220322033350-0661327d31e3 h1:Y6uXXJh8R6X1b4HNpyBG0yc78mdmCxQA6cTsGZJ3F4o=
skywalking.apache.org/repo/goapi v0.0.0-20220322033350-0661327d31e3/go.mod h1:wzVLZ8F88Idy5tlmcGgJCH2NY8GUWxJ2RuNVXkao+SM=
86 changes: 86 additions & 0 deletions internal/commands/profiling/ebpf/analysis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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 ebpf

import (
"strconv"
"strings"

api "skywalking.apache.org/repo/goapi/query"

"github.com/urfave/cli/v2"

"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 AnalyzationCommand = &cli.Command{
Name: "analysis",
Aliases: []string{"as"},
Usage: `analyze ebpf profiling task`,
UsageText: `This command analysis profiling task, via id of task and time ranges.
Example:
1. Analysis profiling tasks of task id "abc" and time range in 1648020042869 to 1648020100764.
$ swctl profiling ebpf analysis --task-id=abc --time-ranges=1648020042869-1648020100764
`,
Flags: flags.Flags(
flags.DurationFlags,
[]cli.Flag{
&cli.StringFlag{
Name: "task-id",
Usage: "the `task-id` by which task are scheduled",
Required: true,
},
&cli.StringFlag{
Name: "time-ranges",
Usage: "need to analyze time ranges in the segment: start-end,start-end",
},
},
),
Action: func(ctx *cli.Context) error {
taskID := ctx.String("task-id")

timeRangeStr := ctx.String("time-ranges")
var timeRanges []*api.EBPFProfilingAnalyzeTimeRange = nil
if timeRangeStr != "" {
tagArr := strings.Split(timeRangeStr, ",")
for _, tag := range tagArr {
kv := strings.Split(tag, "-")
start, err := strconv.ParseInt(kv[0], 10, 64)
if err != nil {
return err
}
end, err := strconv.ParseInt(kv[1], 10, 64)
if err != nil {
return err
}
timeRanges = append(timeRanges, &api.EBPFProfilingAnalyzeTimeRange{Start: start, End: end})
}
}

analyzation, err := profiling.QueryEBPFProfilingAnalyzation(ctx, taskID, timeRanges)
if err != nil {
return err
}

return display.Display(ctx, &displayable.Displayable{Data: analyzation})
},
}
28 changes: 28 additions & 0 deletions internal/commands/profiling/ebpf/create/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 create

import "github.com/urfave/cli/v2"

var CreateCommand = &cli.Command{
Name: "create",
Usage: "eBPF Profiling task create related sub-command",
Subcommands: []*cli.Command{
FixedTimeCreateCommand,
},
}
Loading

0 comments on commit 60cee4a

Please sign in to comment.