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