|
@@ -19,7 +19,6 @@ package report
|
19
|
19
|
import (
|
20
|
20
|
"fmt"
|
21
|
21
|
"io"
|
22
|
|
- "math"
|
23
|
22
|
"path/filepath"
|
24
|
23
|
"regexp"
|
25
|
24
|
"sort"
|
|
@@ -425,7 +424,7 @@ func PrintAssembly(w io.Writer, rpt *Report, obj plugin.ObjTool, maxFuncs int) e
|
425
|
424
|
}
|
426
|
425
|
fmt.Fprintf(w, "%10s %10s (flat, cum) %s of Total\n",
|
427
|
426
|
rpt.formatValue(flatSum), rpt.formatValue(cumSum),
|
428
|
|
- percentage(cumSum, rpt.total))
|
|
427
|
+ measurement.Percentage(cumSum, rpt.total))
|
429
|
428
|
|
430
|
429
|
function, file, line := "", "", 0
|
431
|
430
|
for _, n := range ns {
|
|
@@ -704,7 +703,7 @@ func printTags(w io.Writer, rpt *Report) error {
|
704
|
703
|
for _, t := range graph.SortTags(tags, true) {
|
705
|
704
|
f, u := measurement.Scale(t.FlatValue(), o.SampleUnit, o.OutputUnit)
|
706
|
705
|
if total > 0 {
|
707
|
|
- fmt.Fprintf(tabw, " \t%.1f%s (%s):\t %s\n", f, u, percentage(t.FlatValue(), total), t.Name)
|
|
706
|
+ fmt.Fprintf(tabw, " \t%.1f%s (%s):\t %s\n", f, u, measurement.Percentage(t.FlatValue(), total), t.Name)
|
708
|
707
|
} else {
|
709
|
708
|
fmt.Fprintf(tabw, " \t%.1f%s:\t %s\n", f, u, t.Name)
|
710
|
709
|
}
|
|
@@ -789,9 +788,9 @@ func printText(w io.Writer, rpt *Report) error {
|
789
|
788
|
}
|
790
|
789
|
flatSum += item.Flat
|
791
|
790
|
fmt.Fprintf(w, "%10s %s %s %10s %s %s%s\n",
|
792
|
|
- item.FlatFormat, percentage(item.Flat, rpt.total),
|
793
|
|
- percentage(flatSum, rpt.total),
|
794
|
|
- item.CumFormat, percentage(item.Cum, rpt.total),
|
|
791
|
+ item.FlatFormat, measurement.Percentage(item.Flat, rpt.total),
|
|
792
|
+ measurement.Percentage(flatSum, rpt.total),
|
|
793
|
+ item.CumFormat, measurement.Percentage(item.Cum, rpt.total),
|
795
|
794
|
item.Name, inl)
|
796
|
795
|
}
|
797
|
796
|
return nil
|
|
@@ -1030,17 +1029,17 @@ func printTree(w io.Writer, rpt *Report) error {
|
1030
|
1029
|
inline = " (inline)"
|
1031
|
1030
|
}
|
1032
|
1031
|
fmt.Fprintf(w, "%50s %s | %s%s\n", rpt.formatValue(in.Weight),
|
1033
|
|
- percentage(in.Weight, cum), in.Src.Info.PrintableName(), inline)
|
|
1032
|
+ measurement.Percentage(in.Weight, cum), in.Src.Info.PrintableName(), inline)
|
1034
|
1033
|
}
|
1035
|
1034
|
|
1036
|
1035
|
// Print current node.
|
1037
|
1036
|
flatSum += flat
|
1038
|
1037
|
fmt.Fprintf(w, "%10s %s %s %10s %s | %s\n",
|
1039
|
1038
|
rpt.formatValue(flat),
|
1040
|
|
- percentage(flat, rpt.total),
|
1041
|
|
- percentage(flatSum, rpt.total),
|
|
1039
|
+ measurement.Percentage(flat, rpt.total),
|
|
1040
|
+ measurement.Percentage(flatSum, rpt.total),
|
1042
|
1041
|
rpt.formatValue(cum),
|
1043
|
|
- percentage(cum, rpt.total),
|
|
1042
|
+ measurement.Percentage(cum, rpt.total),
|
1044
|
1043
|
name)
|
1045
|
1044
|
|
1046
|
1045
|
// Print outgoing edges.
|
|
@@ -1051,7 +1050,7 @@ func printTree(w io.Writer, rpt *Report) error {
|
1051
|
1050
|
inline = " (inline)"
|
1052
|
1051
|
}
|
1053
|
1052
|
fmt.Fprintf(w, "%50s %s | %s%s\n", rpt.formatValue(out.Weight),
|
1054
|
|
- percentage(out.Weight, cum), out.Dest.Info.PrintableName(), inline)
|
|
1053
|
+ measurement.Percentage(out.Weight, cum), out.Dest.Info.PrintableName(), inline)
|
1055
|
1054
|
}
|
1056
|
1055
|
}
|
1057
|
1056
|
if len(g.Nodes) > 0 {
|
|
@@ -1083,23 +1082,6 @@ func printDOT(w io.Writer, rpt *Report) error {
|
1083
|
1082
|
return nil
|
1084
|
1083
|
}
|
1085
|
1084
|
|
1086
|
|
-// percentage computes the percentage of total of a value, and encodes
|
1087
|
|
-// it as a string. At least two digits of precision are printed.
|
1088
|
|
-func percentage(value, total int64) string {
|
1089
|
|
- var ratio float64
|
1090
|
|
- if total != 0 {
|
1091
|
|
- ratio = math.Abs(float64(value)/float64(total)) * 100
|
1092
|
|
- }
|
1093
|
|
- switch {
|
1094
|
|
- case math.Abs(ratio) >= 99.95 && math.Abs(ratio) <= 100.05:
|
1095
|
|
- return " 100%"
|
1096
|
|
- case math.Abs(ratio) >= 1.0:
|
1097
|
|
- return fmt.Sprintf("%5.2f%%", ratio)
|
1098
|
|
- default:
|
1099
|
|
- return fmt.Sprintf("%5.2g%%", ratio)
|
1100
|
|
- }
|
1101
|
|
-}
|
1102
|
|
-
|
1103
|
1085
|
// ProfileLabels returns printable labels for a profile.
|
1104
|
1086
|
func ProfileLabels(rpt *Report) []string {
|
1105
|
1087
|
label := []string{}
|
|
@@ -1131,7 +1113,7 @@ func ProfileLabels(rpt *Report) []string {
|
1131
|
1113
|
totalNanos, totalUnit := measurement.Scale(rpt.total, o.SampleUnit, "nanoseconds")
|
1132
|
1114
|
var ratio string
|
1133
|
1115
|
if totalUnit == "ns" && totalNanos != 0 {
|
1134
|
|
- ratio = "(" + percentage(int64(totalNanos), prof.DurationNanos) + ")"
|
|
1116
|
+ ratio = "(" + measurement.Percentage(int64(totalNanos), prof.DurationNanos) + ")"
|
1135
|
1117
|
}
|
1136
|
1118
|
label = append(label, fmt.Sprintf("Duration: %s, Total samples = %s %s", duration, rpt.formatValue(rpt.total), ratio))
|
1137
|
1119
|
}
|
|
@@ -1162,7 +1144,7 @@ func reportLabels(rpt *Report, g *graph.Graph, origCount, droppedNodes, droppedE
|
1162
|
1144
|
label = append(label, activeFilters...)
|
1163
|
1145
|
}
|
1164
|
1146
|
|
1165
|
|
- label = append(label, fmt.Sprintf("Showing nodes accounting for %s, %s of %s total", rpt.formatValue(flatSum), strings.TrimSpace(percentage(flatSum, rpt.total)), rpt.formatValue(rpt.total)))
|
|
1147
|
+ label = append(label, fmt.Sprintf("Showing nodes accounting for %s, %s of %s total", rpt.formatValue(flatSum), strings.TrimSpace(measurement.Percentage(flatSum, rpt.total)), rpt.formatValue(rpt.total)))
|
1166
|
1148
|
|
1167
|
1149
|
if rpt.total != 0 {
|
1168
|
1150
|
if droppedNodes > 0 {
|