Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ func runForDuration(cmd *cobra.Command, args []string) error {

time.Sleep(3 * time.Second)

cpuProfilingStarted := false
if _, err := client.StartCPUProfile(cmd.Context(), &proto.StartCPUProfileRequest{}); err != nil {
cmd.PrintErrf("Failed to start CPU profiling: %v\n", err)
} else {
cpuProfilingStarted = true
defer func() {
if cpuProfilingStarted {
if _, err := client.StopCPUProfile(cmd.Context(), &proto.StopCPUProfileRequest{}); err != nil {
cmd.PrintErrf("Failed to stop CPU profiling: %v\n", err)
}
}
}()
}

headerPostUp := fmt.Sprintf("----- NetBird post-up - Timestamp: %s", time.Now().Format(time.RFC3339))
statusOutput := fmt.Sprintf("%s\n%s", headerPostUp, getStatusOutput(cmd, anonymizeFlag))

Expand All @@ -228,6 +242,13 @@ func runForDuration(cmd *cobra.Command, args []string) error {
}
cmd.Println("\nDuration completed")

if cpuProfilingStarted {
if _, err := client.StopCPUProfile(cmd.Context(), &proto.StopCPUProfileRequest{}); err != nil {
cmd.PrintErrf("Failed to stop CPU profiling: %v\n", err)
}
cpuProfilingStarted = false
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

Comment thread
lixmal marked this conversation as resolved.
cmd.Println("Creating debug bundle...")

headerPreDown := fmt.Sprintf("----- NetBird pre-down - Timestamp: %s - Duration: %s", time.Now().Format(time.RFC3339), duration)
Expand Down Expand Up @@ -379,6 +400,7 @@ func generateDebugBundle(config *profilemanager.Config, recorder *peer.Status, c
StatusRecorder: recorder,
SyncResponse: syncResponse,
LogFile: logFilePath,
CPUProfile: nil,
},
debug.BundleConfig{
IncludeSystemInfo: true,
Expand Down
20 changes: 20 additions & 0 deletions client/internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
statusRecorder *peer.Status
syncResponse *mgmProto.SyncResponse
logFile string
cpuProfile []byte

anonymize bool
clientStatus string
Expand All @@ -224,6 +225,7 @@
StatusRecorder *peer.Status
SyncResponse *mgmProto.SyncResponse
LogFile string
CPUProfile []byte
}

func NewBundleGenerator(deps GeneratorDependencies, cfg BundleConfig) *BundleGenerator {
Expand All @@ -240,6 +242,7 @@
statusRecorder: deps.StatusRecorder,
syncResponse: deps.SyncResponse,
logFile: deps.LogFile,
cpuProfile: deps.CPUProfile,

anonymize: cfg.Anonymize,
clientStatus: cfg.ClientStatus,
Expand Down Expand Up @@ -311,6 +314,10 @@
log.Errorf("failed to add profiles to debug bundle: %v", err)
}

if err := g.addCPUProfile(); err != nil {
log.Errorf("failed to add CPU profile to debug bundle: %v", err)
}

if err := g.addSyncResponse(); err != nil {
return fmt.Errorf("add sync response: %w", err)
}
Expand Down Expand Up @@ -490,6 +497,19 @@
return nil
}

func (g *BundleGenerator) addCPUProfile() error {
if g.cpuProfile == nil || len(g.cpuProfile) == 0 {

Check failure on line 501 in client/internal/debug/debug.go

View workflow job for this annotation

GitHub Actions / Darwin

S1009: should omit nil check; len() for nil slices is defined as zero (gosimple)
return nil
}

reader := bytes.NewReader(g.cpuProfile)
if err := g.addFileToZip(reader, "cpu.prof"); err != nil {
return fmt.Errorf("add CPU profile to zip: %w", err)
}

return nil
}

func (g *BundleGenerator) addInterfaces() error {
interfaces, err := net.Interfaces()
if err != nil {
Expand Down
Loading
Loading