@@ -22,17 +22,7 @@ func getProfileFlags() map[string]string {
2222 }
2323}
2424
25- func getPprofTextParams () []string {
26- return []string {
27- "-cum" ,
28- "-edgefraction=0" ,
29- "-nodefraction=0" ,
30- "-top" ,
31- }
32- }
33-
3425const (
35- textExtension = "txt"
3626 binExtension = "out"
3727 descriptionFileName = "description.txt"
3828 moduleNotFoundMsg = "go: cannot find main module"
@@ -115,36 +105,8 @@ func buildBenchmarkCommand(benchmarkName string, profiles []string, count int) (
115105 return cmd , nil
116106}
117107
118- func deleteContents (dir string ) error {
119- info , err := os .Stat (dir )
120-
121- if os .IsNotExist (err ) {
122- return nil
123- } else if err != nil {
124- return err
125- }
126-
127- if ! info .IsDir () {
128- return fmt .Errorf ("path is not a directory: %s" , dir )
129- }
130-
131- entries , err := os .ReadDir (dir )
132- if err != nil {
133- return fmt .Errorf ("failed to read directory: %w" , err )
134- }
135-
136- for _ , entry := range entries {
137- path := filepath .Join (dir , entry .Name ())
138- if err = os .RemoveAll (path ); err != nil {
139- return fmt .Errorf ("failed to remove %s: %w" , path , err )
140- }
141- }
142-
143- return nil
144- }
145-
146108// getOutputDirectories gets or creates the output directories.
147- func getOrCreateOutputDirectories (benchmarkName , tag string ) (textDir string , binDir string ) {
109+ func getOutputDirectories (benchmarkName , tag string ) (textDir string , binDir string ) {
148110 tagDir := filepath .Join (shared .MainDirOutput , tag )
149111 textDir = filepath .Join (tagDir , shared .ProfileTextDir , benchmarkName )
150112 binDir = filepath .Join (tagDir , shared .ProfileBinDir , benchmarkName )
@@ -212,34 +174,6 @@ func moveTestFiles(benchmarkName, binDir string) error {
212174 return nil
213175}
214176
215- func generateTextProfile (profileFile , outputFile string ) error {
216- pprofTextParams := getPprofTextParams ()
217- cmd := append ([]string {"go" , "tool" , "pprof" }, pprofTextParams ... )
218- cmd = append (cmd , profileFile )
219-
220- // #nosec G204 -- cmd is constructed internally by generateTextProfile(), not from user input
221- execCmd := exec .Command (cmd [0 ], cmd [1 :]... )
222- output , err := execCmd .Output ()
223- if err != nil {
224- return fmt .Errorf ("pprof command failed: %w" , err )
225- }
226-
227- return os .WriteFile (outputFile , output , shared .PermFile )
228- }
229-
230- func generatePNGVisualization (profileFile , outputFile string ) error {
231- cmd := []string {"go" , "tool" , "pprof" , "-png" , profileFile }
232-
233- // #nosec G204 -- cmd is constructed internally by generatePNGVisualization(), not from user input
234- execCmd := exec .Command (cmd [0 ], cmd [1 :]... )
235- output , err := execCmd .Output ()
236- if err != nil {
237- return fmt .Errorf ("pprof PNG generation failed: %w" , err )
238- }
239-
240- return os .WriteFile (outputFile , output , shared .PermFile )
241- }
242-
243177// ProfilePaths holds paths for profile text, binary, and output directories.
244178type ProfilePaths struct {
245179 // Desired file path for specified profile
@@ -265,7 +199,7 @@ type ProfilePaths struct {
265199// - bench/v1.0/cpu_functions/BenchmarkPool/function1.txt
266200func getProfilePaths (tag , benchmarkName , profile string ) ProfilePaths {
267201 tagDir := filepath .Join ("bench" , tag )
268- profileTextFile := fmt .Sprintf ("%s_%s.%s" , benchmarkName , profile , textExtension )
202+ profileTextFile := fmt .Sprintf ("%s_%s.%s" , benchmarkName , profile , shared . TextExtension )
269203 profileBinFile := fmt .Sprintf ("%s_%s.%s" , benchmarkName , profile , binExtension )
270204
271205 return ProfilePaths {
@@ -274,35 +208,3 @@ func getProfilePaths(tag, benchmarkName, profile string) ProfilePaths {
274208 FunctionDirectory : filepath .Join (tagDir , profile + shared .FunctionsDirSuffix , benchmarkName ),
275209 }
276210}
277-
278- // saveAllFunctionsPprofContents calls [getFunctionPprofContent] sequentially.
279- func saveAllFunctionsPprofContents (functions []string , paths ProfilePaths ) error {
280- for _ , function := range functions {
281- if err := getFunctionPprofContent (function , paths ); err != nil {
282- return fmt .Errorf ("failed to extract function content for %s: %w" , function , err )
283- }
284- }
285-
286- return nil
287- }
288-
289- // getFunctionPprofContent gets code line level mapping of specified function
290- // and writes the data to a file named after the function.
291- func getFunctionPprofContent (function string , paths ProfilePaths ) error {
292- outputFile := filepath .Join (paths .FunctionDirectory , function + "." + textExtension )
293- cmd := []string {"go" , "tool" , "pprof" , fmt .Sprintf ("-list=%s" , function ), paths .ProfileBinaryFile }
294-
295- // #nosec ProfileTextDir04 -- cmd is constructed internally by getFunctionPprofContent(), not from user input
296- execCmd := exec .Command (cmd [0 ], cmd [1 :]... )
297- output , err := execCmd .Output ()
298- if err != nil {
299- return fmt .Errorf ("pprof list command failed: %w" , err )
300- }
301-
302- if err = os .WriteFile (outputFile , output , shared .PermFile ); err != nil {
303- return fmt .Errorf ("failed to write function content: %w" , err )
304- }
305-
306- slog .Info ("Collected function" , "function" , function )
307- return nil
308- }
0 commit comments