Kaynağa Gözat

Print numeric tags when printing the trace (#179)

* Print numeric tags when printing the trace
Margaret Nolan 7 yıl önce
ebeveyn
işleme
40f98f839b

+ 12
- 0
internal/driver/driver_test.go Dosyayı Görüntüle

@@ -80,6 +80,7 @@ func TestParse(t *testing.T) {
80 80
 		{"tags", "heap"},
81 81
 		{"tags,unit=bytes", "heap"},
82 82
 		{"traces", "cpu"},
83
+		{"traces", "heap_tags"},
83 84
 		{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
84 85
 		{"dot,alloc_space,flat,tagshow=[2]00", "heap_alloc"},
85 86
 		{"dot,alloc_space,flat,hide=line.*1?23?", "heap_alloc"},
@@ -398,6 +399,17 @@ func (testFetcher) Fetch(s string, d, t time.Duration) (*profile.Profile, string
398 399
 		for _, s := range p.Sample {
399 400
 			s.NumLabel["bytes"] = append(s.NumLabel["bytes"], tags...)
400 401
 		}
402
+	case "heap_tags":
403
+		p = heapProfile()
404
+
405
+		for i := 0; i < len(p.Sample); i += 2 {
406
+			s := p.Sample[i]
407
+			if s.Label == nil {
408
+				s.Label = make(map[string][]string)
409
+			}
410
+			s.NumLabel["request"] = s.NumLabel["bytes"]
411
+			s.Label["key1"] = []string{"tag"}
412
+		}
401 413
 
402 414
 	case "contention":
403 415
 		p = contentionProfile()

+ 32
- 0
internal/driver/testdata/pprof.heap_tags.traces Dosyayı Görüntüle

@@ -0,0 +1,32 @@
1
+Build ID: buildid
2
+comment
3
+Type: inuse_space
4
+-----------+-------------------------------------------------------
5
+      key1:  tag
6
+     bytes:  102400
7
+   request:  102400
8
+    1000kB   line1000
9
+             line2001
10
+             line2000
11
+             line3002
12
+             line3001
13
+             line3000
14
+-----------+-------------------------------------------------------
15
+     bytes:  204800
16
+    3.91MB   line1000
17
+             line3001
18
+             line3000
19
+-----------+-------------------------------------------------------
20
+      key1:  tag
21
+     bytes:  1638400
22
+   request:  1638400
23
+   62.50MB   line2001
24
+             line2000
25
+             line3002
26
+             line3000
27
+-----------+-------------------------------------------------------
28
+     bytes:  409600
29
+   31.25MB   line3002
30
+             line3001
31
+             line3000
32
+-----------+-------------------------------------------------------

+ 9
- 0
internal/report/report.go Dosyayı Görüntüle

@@ -755,6 +755,15 @@ func printTraces(w io.Writer, rpt *Report) error {
755 755
 		}
756 756
 		sort.Strings(labels)
757 757
 		fmt.Fprint(w, strings.Join(labels, ""))
758
+
759
+		// Print any numeric labels for the sample
760
+		var numLabels []string
761
+		for k, v := range sample.NumLabel {
762
+			numLabels = append(numLabels, fmt.Sprintf("%10s:  %s\n", k, strings.Trim(fmt.Sprintf("%d", v), "[]")))
763
+		}
764
+		sort.Strings(numLabels)
765
+		fmt.Fprint(w, strings.Join(numLabels, ""))
766
+
758 767
 		var d, v int64
759 768
 		v = o.SampleValue(sample.Value)
760 769
 		if o.SampleMeanDivisor != nil {