瀏覽代碼

Merge remote-tracking branch 'upstream/master'

Raul Silvera 9 年之前
父節點
當前提交
3c947c38ad
共有 2 個檔案被更改,包括 14 行新增7 行删除
  1. 8
    0
      internal/driver/commands.go
  2. 6
    7
      internal/report/source.go

+ 8
- 0
internal/driver/commands.go 查看文件

@@ -68,6 +68,14 @@ func AddCommand(cmd string, format int, post PostProcessor, desc, usage string)
68 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 79
 // PostProcessor is a function that applies post-processing to the report output
72 80
 type PostProcessor func(input []byte, output io.Writer, ui plugin.UI) error
73 81
 

+ 6
- 7
internal/report/source.go 查看文件

@@ -339,7 +339,8 @@ func printPageClosing(w io.Writer) {
339 339
 // file and annotates it with the samples in fns. Returns the sources
340 340
 // as nodes, using the info.name field to hold the source code.
341 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 344
 	if err != nil {
344 345
 		return nil, file, err
345 346
 	}
@@ -434,12 +435,10 @@ func getMissingFunctionSource(filename string, asm map[int]graph.Nodes, start, e
434 435
 // profile. File names in a profile after often relative paths, so
435 436
 // search them in each of the paths in searchPath (or CWD by default),
436 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 439
 	if filepath.IsAbs(path) {
441 440
 		f, err := os.Open(path)
442
-		return f, path, err
441
+		return f, err
443 442
 	}
444 443
 
445 444
 	// Scan each component of the path
@@ -448,7 +447,7 @@ func openSourceFile(path, searchPath string) (*os.File, string, error) {
448 447
 		for {
449 448
 			filename := filepath.Join(dir, path)
450 449
 			if f, err := os.Open(filename); err == nil {
451
-				return f, filename, nil
450
+				return f, nil
452 451
 			}
453 452
 			parent := filepath.Dir(dir)
454 453
 			if parent == dir {
@@ -458,7 +457,7 @@ func openSourceFile(path, searchPath string) (*os.File, string, error) {
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 463
 // trimPath cleans up a path by removing prefixes that are commonly