Browse Source

Merge remote-tracking branch 'upstream/master'

Raul Silvera 9 years ago
parent
commit
3c947c38ad
2 changed files with 14 additions and 7 deletions
  1. 8
    0
      internal/driver/commands.go
  2. 6
    7
      internal/report/source.go

+ 8
- 0
internal/driver/commands.go View File

68
 	pprofCommands[cmd] = &command{format, post, false, desc, usage}
68
 	pprofCommands[cmd] = &command{format, post, false, desc, usage}
69
 }
69
 }
70
 
70
 
71
+// SetVariableDefault sets the default value for a pprof
72
+// variable. This enables extensions to set their own defaults.
73
+func SetVariableDefault(variable, value string) {
74
+	if v := pprofVariables[variable]; v != nil {
75
+		v.value = value
76
+	}
77
+}
78
+
71
 // PostProcessor is a function that applies post-processing to the report output
79
 // PostProcessor is a function that applies post-processing to the report output
72
 type PostProcessor func(input []byte, output io.Writer, ui plugin.UI) error
80
 type PostProcessor func(input []byte, output io.Writer, ui plugin.UI) error
73
 
81
 

+ 6
- 7
internal/report/source.go View File

339
 // file and annotates it with the samples in fns. Returns the sources
339
 // file and annotates it with the samples in fns. Returns the sources
340
 // as nodes, using the info.name field to hold the source code.
340
 // as nodes, using the info.name field to hold the source code.
341
 func getSourceFromFile(file, sourcePath string, fns graph.Nodes, start, end int) (graph.Nodes, string, error) {
341
 func getSourceFromFile(file, sourcePath string, fns graph.Nodes, start, end int) (graph.Nodes, string, error) {
342
-	f, file, err := openSourceFile(file, sourcePath)
342
+	file = trimPath(file)
343
+	f, err := openSourceFile(file, sourcePath)
343
 	if err != nil {
344
 	if err != nil {
344
 		return nil, file, err
345
 		return nil, file, err
345
 	}
346
 	}
434
 // profile. File names in a profile after often relative paths, so
435
 // profile. File names in a profile after often relative paths, so
435
 // search them in each of the paths in searchPath (or CWD by default),
436
 // search them in each of the paths in searchPath (or CWD by default),
436
 // and their parents.
437
 // and their parents.
437
-func openSourceFile(path, searchPath string) (*os.File, string, error) {
438
-	path = trimPath(path)
439
-
438
+func openSourceFile(path, searchPath string) (*os.File, error) {
440
 	if filepath.IsAbs(path) {
439
 	if filepath.IsAbs(path) {
441
 		f, err := os.Open(path)
440
 		f, err := os.Open(path)
442
-		return f, path, err
441
+		return f, err
443
 	}
442
 	}
444
 
443
 
445
 	// Scan each component of the path
444
 	// Scan each component of the path
448
 		for {
447
 		for {
449
 			filename := filepath.Join(dir, path)
448
 			filename := filepath.Join(dir, path)
450
 			if f, err := os.Open(filename); err == nil {
449
 			if f, err := os.Open(filename); err == nil {
451
-				return f, filename, nil
450
+				return f, nil
452
 			}
451
 			}
453
 			parent := filepath.Dir(dir)
452
 			parent := filepath.Dir(dir)
454
 			if parent == dir {
453
 			if parent == dir {
458
 		}
457
 		}
459
 	}
458
 	}
460
 
459
 
461
-	return nil, "", fmt.Errorf("Could not find file %s on path %s", path, searchPath)
460
+	return nil, fmt.Errorf("Could not find file %s on path %s", path, searchPath)
462
 }
461
 }
463
 
462
 
464
 // trimPath cleans up a path by removing prefixes that are commonly
463
 // trimPath cleans up a path by removing prefixes that are commonly