(rpt *Report)
| 104 | } |
| 105 | |
| 106 | func (s *StackSet) makeInitialStacks(rpt *Report) { |
| 107 | type key struct { |
| 108 | funcName string |
| 109 | fileName string |
| 110 | line int64 |
| 111 | column int64 |
| 112 | inlined bool |
| 113 | } |
| 114 | srcs := map[key]int{} // Sources identified so far. |
| 115 | seenFunctions := map[string]bool{} |
| 116 | unknownIndex := 1 |
| 117 | |
| 118 | getSrc := func(line profile.Line, inlined bool) int { |
| 119 | fn := line.Function |
| 120 | if fn == nil { |
| 121 | fn = &profile.Function{Name: fmt.Sprintf("?%d?", unknownIndex)} |
| 122 | unknownIndex++ |
| 123 | } |
| 124 | |
| 125 | k := key{fn.Name, fn.Filename, line.Line, line.Column, inlined} |
| 126 | if i, ok := srcs[k]; ok { |
| 127 | return i |
| 128 | } |
| 129 | |
| 130 | fileName := trimPath(fn.Filename, rpt.options.TrimPath, rpt.options.SourcePath) |
| 131 | x := StackSource{ |
| 132 | FileName: fileName, |
| 133 | Inlined: inlined, |
| 134 | Places: []StackSlot{}, // Ensure Places is non-nil |
| 135 | } |
| 136 | if fn.Name != "" { |
| 137 | x.FullName = addLineInfo(fn.Name, line) |
| 138 | x.Display = shortNameList(x.FullName) |
| 139 | x.Color = pickColor(packageName(fn.Name)) |
| 140 | } else { // Use file name, e.g., for file granularity display. |
| 141 | x.FullName = addLineInfo(fileName, line) |
| 142 | x.Display = fileNameSuffixes(x.FullName) |
| 143 | x.Color = pickColor(filepath.Dir(fileName)) |
| 144 | } |
| 145 | |
| 146 | if !seenFunctions[x.FullName] { |
| 147 | x.UniqueName = x.FullName |
| 148 | seenFunctions[x.FullName] = true |
| 149 | } else { |
| 150 | // Assign a different name so pivoting picks this function. |
| 151 | x.UniqueName = fmt.Sprint(x.FullName, "#", fn.ID) |
| 152 | } |
| 153 | |
| 154 | s.Sources = append(s.Sources, x) |
| 155 | srcs[k] = len(s.Sources) - 1 |
| 156 | return len(s.Sources) - 1 |
| 157 | } |
| 158 | |
| 159 | // Synthesized root location that will be placed at the beginning of each stack. |
| 160 | s.Sources = []StackSource{{ |
| 161 | FullName: "root", |
| 162 | Display: []string{"root"}, |
| 163 | Places: []StackSlot{}, |
no test coverage detected