diff --git a/CHANGES.md b/CHANGES.md index 88d5d660..ca7a1075 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Release Notes. - Remove `duration` flag in `profiling ebpf schedules`.(#150) - [Breaking Change] Remove `total` field in `trace list` and `logs list` commands.(#152) - [Breaking Change] Remove `total` field in `event list`, `browser logs list`, `alarm list` commands.(#153) +- Add `aggregate` flag in `profiling ebpf analysis` commands.(#154) 0.10.0 ------------------ diff --git a/assets/graphqls/profiling/ebpf/AnalysisEBPFProfilingResult.graphql b/assets/graphqls/profiling/ebpf/AnalysisEBPFProfilingResult.graphql index be9a8ba5..ff6b103d 100644 --- a/assets/graphqls/profiling/ebpf/AnalysisEBPFProfilingResult.graphql +++ b/assets/graphqls/profiling/ebpf/AnalysisEBPFProfilingResult.graphql @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. -query ($scheduleIdList: [ID!]!, $timeRanges: [EBPFProfilingAnalyzeTimeRange!]!){ - result: analysisEBPFProfilingResult(scheduleIdList: $scheduleIdList, timeRanges: $timeRanges) { +query ($scheduleIdList: [ID!]!, $timeRanges: [EBPFProfilingAnalyzeTimeRange!]!, $aggregateType: EBPFProfilingAnalyzeAggregateType){ + result: analysisEBPFProfilingResult(scheduleIdList: $scheduleIdList, timeRanges: $timeRanges, aggregateType: $aggregateType) { tip trees { elements { diff --git a/internal/commands/profiling/ebpf/analysis.go b/internal/commands/profiling/ebpf/analysis.go index a338000f..6698ff4c 100644 --- a/internal/commands/profiling/ebpf/analysis.go +++ b/internal/commands/profiling/ebpf/analysis.go @@ -26,6 +26,7 @@ import ( "github.com/urfave/cli/v2" "github.com/apache/skywalking-cli/internal/flags" + "github.com/apache/skywalking-cli/internal/model/ebpf" "github.com/apache/skywalking-cli/pkg/display" "github.com/apache/skywalking-cli/pkg/display/displayable" "github.com/apache/skywalking-cli/pkg/graphql/profiling" @@ -53,6 +54,15 @@ $ swctl profiling ebpf analysis --schedule-id=abc --time-ranges=1648020042869-16 Name: "time-ranges", Usage: "need to analyze time ranges in the segment: start-end,start-end", }, + &cli.GenericFlag{ + Name: "aggregate", + Usage: "the aggregate type for the profiling data anlysis", + Value: &ebpf.ProfilingAnalyzeAggregateTypeEnumValue{ + Enum: api.AllEBPFProfilingAnalyzeAggregateType, + Default: api.EBPFProfilingAnalyzeAggregateTypeCount, + Selected: api.EBPFProfilingAnalyzeAggregateTypeCount, + }, + }, }, ), Action: func(ctx *cli.Context) error { @@ -77,7 +87,8 @@ $ swctl profiling ebpf analysis --schedule-id=abc --time-ranges=1648020042869-16 } } - analyzation, err := profiling.AnalysisEBPFProfilingResult(ctx, scheduleIDList, timeRanges) + aggregateType := ctx.Generic("aggregate").(*ebpf.ProfilingAnalyzeAggregateTypeEnumValue).Selected + analyzation, err := profiling.AnalysisEBPFProfilingResult(ctx, scheduleIDList, timeRanges, aggregateType) if err != nil { return err } diff --git a/internal/model/ebpf/profilingAnalyzeAggregateType.go b/internal/model/ebpf/profilingAnalyzeAggregateType.go new file mode 100644 index 00000000..73f1c59d --- /dev/null +++ b/internal/model/ebpf/profilingAnalyzeAggregateType.go @@ -0,0 +1,49 @@ +// 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 ( + "fmt" + "strings" + + api "skywalking.apache.org/repo/goapi/query" +) + +type ProfilingAnalyzeAggregateTypeEnumValue struct { + Enum []api.EBPFProfilingAnalyzeAggregateType + Default api.EBPFProfilingAnalyzeAggregateType + Selected api.EBPFProfilingAnalyzeAggregateType +} + +func (e *ProfilingAnalyzeAggregateTypeEnumValue) 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.AllEBPFProfilingAnalyzeAggregateType)) + for i, order := range api.AllEBPFProfilingAnalyzeAggregateType { + orders[i] = order.String() + } + return fmt.Errorf("allowed analysis aggregate type are %s", strings.Join(orders, ", ")) +} + +func (e *ProfilingAnalyzeAggregateTypeEnumValue) String() string { + return e.Selected.String() +} diff --git a/pkg/graphql/profiling/ebpf.go b/pkg/graphql/profiling/ebpf.go index 16408e50..2d9c10ca 100644 --- a/pkg/graphql/profiling/ebpf.go +++ b/pkg/graphql/profiling/ebpf.go @@ -74,12 +74,13 @@ func QueryEBPFProfilingScheduleList(ctx *cli.Context, taskID string) ([]*api.EBP } func AnalysisEBPFProfilingResult(ctx *cli.Context, scheduleIDList []string, - timeRanges []*api.EBPFProfilingAnalyzeTimeRange) (*api.EBPFProfilingAnalyzation, error) { + timeRanges []*api.EBPFProfilingAnalyzeTimeRange, aggregateType api.EBPFProfilingAnalyzeAggregateType) (*api.EBPFProfilingAnalyzation, error) { var response map[string]*api.EBPFProfilingAnalyzation request := graphql.NewRequest(assets.Read("graphqls/profiling/ebpf/AnalysisEBPFProfilingResult.graphql")) request.Var("scheduleIdList", scheduleIDList) request.Var("timeRanges", timeRanges) + request.Var("aggregateType", aggregateType) err := client.ExecuteQuery(ctx, request, &response)