(g *graph.Graph)
| 185 | } |
| 186 | |
| 187 | func (rpt *Report) selectOutputUnit(g *graph.Graph) { |
| 188 | o := rpt.options |
| 189 | |
| 190 | // Select best unit for profile output. |
| 191 | // Find the appropriate units for the smallest non-zero sample |
| 192 | if o.OutputUnit != "minimum" || len(g.Nodes) == 0 { |
| 193 | return |
| 194 | } |
| 195 | var minValue int64 |
| 196 | |
| 197 | for _, n := range g.Nodes { |
| 198 | nodeMin := abs64(n.FlatValue()) |
| 199 | if nodeMin == 0 { |
| 200 | nodeMin = abs64(n.CumValue()) |
| 201 | } |
| 202 | if nodeMin > 0 && (minValue == 0 || nodeMin < minValue) { |
| 203 | minValue = nodeMin |
| 204 | } |
| 205 | } |
| 206 | maxValue := rpt.total |
| 207 | if minValue == 0 { |
| 208 | minValue = maxValue |
| 209 | } |
| 210 | |
| 211 | if r := o.Ratio; r > 0 && r != 1 { |
| 212 | minValue = int64(float64(minValue) * r) |
| 213 | maxValue = int64(float64(maxValue) * r) |
| 214 | } |
| 215 | |
| 216 | _, minUnit := measurement.Scale(minValue, o.SampleUnit, "minimum") |
| 217 | _, maxUnit := measurement.Scale(maxValue, o.SampleUnit, "minimum") |
| 218 | |
| 219 | unit := minUnit |
| 220 | if minUnit != maxUnit && minValue*100 < maxValue && o.OutputFormat != Callgrind { |
| 221 | // Minimum and maximum values have different units. Scale |
| 222 | // minimum by 100 to use larger units, allowing minimum value to |
| 223 | // be scaled down to 0.01, except for callgrind reports since |
| 224 | // they can only represent integer values. |
| 225 | _, unit = measurement.Scale(100*minValue, o.SampleUnit, "minimum") |
| 226 | } |
| 227 | |
| 228 | if unit != "" { |
| 229 | o.OutputUnit = unit |
| 230 | } else { |
| 231 | o.OutputUnit = o.SampleUnit |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // newGraph creates a new graph for this report. If nodes is non-nil, |
| 236 | // only nodes whose info matches are included. Otherwise, all nodes |
no test coverage detected