浏览代码

Merge pull request #52 from rauls5382/tagunit

Have unit= apply to numeric tags
Raul Silvera 8 年前
父节点
当前提交
a691cd088b

+ 5
- 1
internal/driver/driver_test.go 查看文件

65
 		{"dot,files,cum", "contention"},
65
 		{"dot,files,cum", "contention"},
66
 		{"tags", "cpu"},
66
 		{"tags", "cpu"},
67
 		{"tags,tagignore=tag[13],tagfocus=key[12]", "cpu"},
67
 		{"tags,tagignore=tag[13],tagfocus=key[12]", "cpu"},
68
+		{"tags", "heap"},
69
+		{"tags,unit=bytes", "heap"},
68
 		{"traces", "cpu"},
70
 		{"traces", "cpu"},
69
 		{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
71
 		{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
70
 		{"dot,alloc_space,flat,hide=line.*1?23?", "heap_alloc"},
72
 		{"dot,alloc_space,flat,hide=line.*1?23?", "heap_alloc"},
221
 		name = append(name, "ignore")
223
 		name = append(name, "ignore")
222
 	}
224
 	}
223
 	name = addString(name, f, []string{"hide", "show"})
225
 	name = addString(name, f, []string{"hide", "show"})
224
-
226
+	if f.strings["unit"] != "minimum" {
227
+		name = addString(name, f, []string{"unit"})
228
+	}
225
 	return strings.Join(name, ".")
229
 	return strings.Join(name, ".")
226
 }
230
 }
227
 
231
 

+ 6
- 0
internal/driver/testdata/pprof.heap.tags 查看文件

1
+bytes: Total 150
2
+        80 (53.33%): 400kB
3
+        40 (26.67%): 1.56MB
4
+        20 (13.33%): 200kB
5
+        10 ( 6.67%): 100kB
6
+

+ 6
- 0
internal/driver/testdata/pprof.heap.tags.unit 查看文件

1
+bytes: Total 150
2
+        80 (53.33%): 409600B
3
+        40 (26.67%): 1638400B
4
+        20 (13.33%): 204800B
5
+        10 ( 6.67%): 102400B
6
+

+ 14
- 8
internal/graph/dotgraph.go 查看文件

45
 	Title  string   // The title of the DOT graph
45
 	Title  string   // The title of the DOT graph
46
 	Labels []string // The labels for the DOT's legend
46
 	Labels []string // The labels for the DOT's legend
47
 
47
 
48
-	FormatValue func(int64) string // A formatting function for values
49
-	Total       int64              // The total weight of the graph, used to compute percentages
48
+	FormatValue func(int64) string         // A formatting function for values
49
+	FormatTag   func(int64, string) string // A formatting function for numeric tags
50
+	Total       int64                      // The total weight of the graph, used to compute percentages
50
 }
51
 }
51
 
52
 
52
 // Compose creates and writes a in the DOT format to the writer, using
53
 // Compose creates and writes a in the DOT format to the writer, using
258
 
259
 
259
 	// Collapse numeric labels into maxNumNodelets buckets, of the form:
260
 	// Collapse numeric labels into maxNumNodelets buckets, of the form:
260
 	// 1MB..2MB, 3MB..5MB, ...
261
 	// 1MB..2MB, 3MB..5MB, ...
261
-	for j, t := range collapsedTags(nts, maxNumNodelets, flatTags) {
262
+	for j, t := range b.collapsedTags(nts, maxNumNodelets, flatTags) {
262
 		w, attr := t.CumValue(), ` style="dotted"`
263
 		w, attr := t.CumValue(), ` style="dotted"`
263
 		if flatTags || t.FlatValue() == t.CumValue() {
264
 		if flatTags || t.FlatValue() == t.CumValue() {
264
 			w, attr = t.FlatValue(), ""
265
 			w, attr = t.FlatValue(), ""
399
 }
400
 }
400
 
401
 
401
 // collapsedTags trims and sorts a slice of tags.
402
 // collapsedTags trims and sorts a slice of tags.
402
-func collapsedTags(ts []*Tag, count int, flatTags bool) []*Tag {
403
+func (b *builder) collapsedTags(ts []*Tag, count int, flatTags bool) []*Tag {
403
 	ts = SortTags(ts, flatTags)
404
 	ts = SortTags(ts, flatTags)
404
 	if len(ts) <= count {
405
 	if len(ts) <= count {
405
 		return ts
406
 		return ts
421
 
422
 
422
 	var nts []*Tag
423
 	var nts []*Tag
423
 	for _, g := range tagGroups {
424
 	for _, g := range tagGroups {
424
-		l, w, c := tagGroupLabel(g)
425
+		l, w, c := b.tagGroupLabel(g)
425
 		nts = append(nts, &Tag{
426
 		nts = append(nts, &Tag{
426
 			Name: l,
427
 			Name: l,
427
 			Flat: w,
428
 			Flat: w,
439
 	return v - float64(t.Value)
440
 	return v - float64(t.Value)
440
 }
441
 }
441
 
442
 
442
-func tagGroupLabel(g []*Tag) (label string, flat, cum int64) {
443
+func (b *builder) tagGroupLabel(g []*Tag) (label string, flat, cum int64) {
444
+	formatTag := b.config.FormatTag
445
+	if formatTag == nil {
446
+		formatTag = measurement.Label
447
+	}
448
+
443
 	if len(g) == 1 {
449
 	if len(g) == 1 {
444
 		t := g[0]
450
 		t := g[0]
445
-		return measurement.Label(t.Value, t.Unit), t.FlatValue(), t.CumValue()
451
+		return formatTag(t.Value, t.Unit), t.FlatValue(), t.CumValue()
446
 	}
452
 	}
447
 	min := g[0]
453
 	min := g[0]
448
 	max := g[0]
454
 	max := g[0]
466
 	if dc != 0 {
472
 	if dc != 0 {
467
 		c = c / dc
473
 		c = c / dc
468
 	}
474
 	}
469
-	return measurement.Label(min.Value, min.Unit) + ".." + measurement.Label(max.Value, max.Unit), f, c
475
+	return formatTag(min.Value, min.Unit) + ".." + formatTag(max.Value, max.Unit), f, c
470
 }
476
 }
471
 
477
 
472
 func min64(a, b int64) int64 {
478
 func min64(a, b int64) int64 {

+ 2
- 1
internal/graph/dotgraph_test.go 查看文件

263
 
263
 
264
 	for _, tc := range tagWant {
264
 	for _, tc := range tagWant {
265
 		var got, want []*Tag
265
 		var got, want []*Tag
266
-		got = collapsedTags(tagSource, len(tc), true)
266
+		b := builder{nil, &DotAttributes{}, &DotConfig{}}
267
+		got = b.collapsedTags(tagSource, len(tc), true)
267
 		want = SortTags(tc, true)
268
 		want = SortTags(tc, true)
268
 
269
 
269
 		if !reflect.DeepEqual(got, want) {
270
 		if !reflect.DeepEqual(got, want) {

+ 16
- 5
internal/report/report.go 查看文件

199
 		s.NumLabel = numLabels
199
 		s.NumLabel = numLabels
200
 	}
200
 	}
201
 
201
 
202
+	formatTag := func(v int64, key string) string {
203
+		return measurement.ScaledLabel(v, key, o.OutputUnit)
204
+	}
205
+
202
 	gopt := &graph.Options{
206
 	gopt := &graph.Options{
203
 		SampleValue:       o.SampleValue,
207
 		SampleValue:       o.SampleValue,
204
 		SampleMeanDivisor: o.SampleMeanDivisor,
208
 		SampleMeanDivisor: o.SampleMeanDivisor,
218
 	return graph.New(rpt.prof, gopt)
222
 	return graph.New(rpt.prof, gopt)
219
 }
223
 }
220
 
224
 
221
-func formatTag(v int64, key string) string {
222
-	return measurement.Label(v, key)
223
-}
224
-
225
 func printTopProto(w io.Writer, rpt *Report) error {
225
 func printTopProto(w io.Writer, rpt *Report) error {
226
 	p := rpt.prof
226
 	p := rpt.prof
227
 	o := rpt.options
227
 	o := rpt.options
473
 func printTags(w io.Writer, rpt *Report) error {
473
 func printTags(w io.Writer, rpt *Report) error {
474
 	p := rpt.prof
474
 	p := rpt.prof
475
 
475
 
476
+	o := rpt.options
477
+	formatTag := func(v int64, key string) string {
478
+		return measurement.ScaledLabel(v, key, o.OutputUnit)
479
+	}
480
+
476
 	// Hashtable to keep accumulate tags as key,value,count.
481
 	// Hashtable to keep accumulate tags as key,value,count.
477
 	tagMap := make(map[string]map[string]int64)
482
 	tagMap := make(map[string]map[string]int64)
478
 	for _, s := range p.Sample {
483
 	for _, s := range p.Sample {
489
 		}
494
 		}
490
 		for key, vals := range s.NumLabel {
495
 		for key, vals := range s.NumLabel {
491
 			for _, nval := range vals {
496
 			for _, nval := range vals {
492
-				val := measurement.Label(nval, key)
497
+				val := formatTag(nval, key)
493
 				if valueMap, ok := tagMap[key]; ok {
498
 				if valueMap, ok := tagMap[key]; ok {
494
 					valueMap[val] = valueMap[val] + s.Value[0]
499
 					valueMap[val] = valueMap[val] + s.Value[0]
495
 					continue
500
 					continue
826
 	rpt.selectOutputUnit(g)
831
 	rpt.selectOutputUnit(g)
827
 	labels := reportLabels(rpt, g, origCount, droppedNodes, droppedEdges, true)
832
 	labels := reportLabels(rpt, g, origCount, droppedNodes, droppedEdges, true)
828
 
833
 
834
+	o := rpt.options
835
+	formatTag := func(v int64, key string) string {
836
+		return measurement.ScaledLabel(v, key, o.OutputUnit)
837
+	}
838
+
829
 	c := &graph.DotConfig{
839
 	c := &graph.DotConfig{
830
 		Title:       rpt.options.Title,
840
 		Title:       rpt.options.Title,
831
 		Labels:      labels,
841
 		Labels:      labels,
832
 		FormatValue: rpt.formatValue,
842
 		FormatValue: rpt.formatValue,
843
+		FormatTag:   formatTag,
833
 		Total:       rpt.total,
844
 		Total:       rpt.total,
834
 	}
845
 	}
835
 	graph.ComposeDot(w, g, &graph.DotAttributes{}, c)
846
 	graph.ComposeDot(w, g, &graph.DotAttributes{}, c)