MCPcopy Create free account
hub / github.com/google/pprof / line

Method line

internal/report/source.go:974–998  ·  view source on GitHub ↗

line returns the line numbered "lineno" in path, or _,false if lineno is out of range.

(path string, lineno int)

Source from the content-addressed store, hash-verified

972
973// line returns the line numbered "lineno" in path, or _,false if lineno is out of range.
974func (reader *sourceReader) line(path string, lineno int) (string, bool) {
975 lines, ok := reader.files[path]
976 if !ok {
977 // Read and cache file contents.
978 lines = []string{""} // Skip 0th line
979 f, err := openSourceFile(path, reader.searchPath, reader.trimPath)
980 if err != nil {
981 reader.errors[path] = err
982 } else {
983 s := bufio.NewScanner(f)
984 for s.Scan() {
985 lines = append(lines, s.Text())
986 }
987 f.Close()
988 if s.Err() != nil {
989 reader.errors[path] = err
990 }
991 }
992 reader.files[path] = lines
993 }
994 if lineno <= 0 || lineno >= len(lines) {
995 return "", false
996 }
997 return lines[lineno], true
998}
999
1000// openSourceFile opens a source file from a name encoded in a profile. File
1001// names in a profile after can be relative paths, so search them in each of

Callers 3

generateFileMethod · 0.80
makeWebListInstructionsFunction · 0.80
getSourceFromFileFunction · 0.80

Calls 2

openSourceFileFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected