cmd/kubectl-gadget/profile: Use BaseParser.Transform on cpu gadget
@@ -161,20 +161,7 @@ func (p *CPUParser) DisplayResultsCallback(traceOutputMode string, results []str
}
for _, report := range reports {
- switch p.OutputConfig.OutputMode {
- case commonutils.OutputModeJSON:
- b, err := json.Marshal(report)
- if err != nil {
- return commonutils.WrapInErrMarshalOutput(err)
- }
- fmt.Println(string(b))
- case commonutils.OutputModeColumns:
- fallthrough
- case commonutils.OutputModeCustomColumns:
- fmt.Println(p.TransformEvent(&report))
- default:
- return commonutils.WrapInErrOutputModeNotSupported(p.OutputConfig.OutputMode)
- }
+ fmt.Println(p.TransformReport(&report))
}
}
@@ -196,7 +183,8 @@ func getReverseStringSlice(toReverse []string) string {
return fmt.Sprintf("\n\t%s", strings.Join(toReverse, "\n\t"))
}
-func (p *CPUParser) TransformEvent(report *types.Report) string {
+func (p *CPUParser) TransformReport(report *types.Report) string {
+ return p.Transform(report, func(e *types.Report) string {
var sb strings.Builder
for _, col := range p.OutputConfig.CustomColumns {
@@ -230,4 +218,5 @@ func (p *CPUParser) TransformEvent(report *types.Report) string {
}
return sb.String()
+ })
}
