From b165f63327ec5d0f0be3112592740de80212c513 Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Tue, 15 Apr 2025 11:36:41 +0200 Subject: [PATCH] [client] Add heap profile to debug bundle (#3679) --- client/server/debug.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/client/server/debug.go b/client/server/debug.go index bdb1f7543..27b4f99d2 100644 --- a/client/server/debug.go +++ b/client/server/debug.go @@ -34,7 +34,8 @@ import ( ) const readmeContent = `Netbird debug bundle -This debug bundle contains the following files: +This debug bundle contains the following files. +If the --anonymize flag is set, the files are anonymized to protect sensitive information. status.txt: Anonymized status information of the NetBird client. client.log: Most recent, anonymized client log file of the NetBird client. @@ -50,6 +51,7 @@ state.json: Anonymized client state dump containing netbird states. mutex.prof: Mutex profiling information. goroutine.prof: Goroutine profiling information. block.prof: Block profiling information. +heap.prof: Heap profiling information (snapshot of memory allocations). Anonymization Process @@ -92,11 +94,14 @@ The state file follows the same anonymization rules as other files: - Domain names are consistently anonymized - Technical identifiers and non-sensitive data remain unchanged -Mutex, Goroutines, and Block Profiling Files -The goroutine, block, and mutex profiling files contains process information that might help the NetBird team diagnose performance issues. The information in these files don't contain personal data. +Mutex, Goroutines, Block, and Heap Profiling Files +The goroutine, block, mutex, and heap profiling files contain process information that might help the NetBird team diagnose performance or memory issues. The information in these files doesn't contain personal data. You can check each using the following go command: -go tool pprof -http=:8088 mutex.prof +go tool pprof -http=:8088 .prof + +For example, to view the heap profile: +go tool pprof -http=:8088 heap.prof This will open a web browser tab with the profiling information. @@ -180,7 +185,7 @@ func (s *Server) DebugBundle(_ context.Context, req *proto.DebugBundleRequest) ( func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleRequest) error { archive := zip.NewWriter(bundlePath) - if err := s.addReadme(req, archive); err != nil { + if err := s.addReadme(archive); err != nil { return fmt.Errorf("add readme: %w", err) } @@ -242,12 +247,10 @@ func (s *Server) addSystemInfo(req *proto.DebugBundleRequest, anonymizer *anonym } } -func (s *Server) addReadme(req *proto.DebugBundleRequest, archive *zip.Writer) error { - if req.GetAnonymize() { - readmeReader := strings.NewReader(readmeContent) - if err := addFileToZip(archive, readmeReader, "README.txt"); err != nil { - return fmt.Errorf("add README file to zip: %w", err) - } +func (s *Server) addReadme(archive *zip.Writer) error { + readmeReader := strings.NewReader(readmeContent) + if err := addFileToZip(archive, readmeReader, "README.txt"); err != nil { + return fmt.Errorf("add README file to zip: %w", err) } return nil } @@ -334,7 +337,7 @@ func (s *Server) addProf(req *proto.DebugBundleRequest, anonymizer *anonymize.An time.Sleep(5 * time.Second) - for _, profile := range []string{"goroutine", "block", "mutex"} { + for _, profile := range []string{"goroutine", "block", "mutex", "heap"} { var buff []byte myBuff := bytes.NewBuffer(buff) err := pprof.Lookup(profile).WriteTo(myBuff, 0)