Bladeren bron

Improve loc information of assembly listings

Previous loc information on assembly listing was being printed for
every line, while the intent was to print it only when it changes.

Also update the tests to expose and test that case, and remaster
other tests to match.
Raul Silvera 8 jaren geleden
bovenliggende
commit
39ed5b5f27

+ 1
- 1
internal/driver/driver_test.go Bestand weergeven

@@ -520,7 +520,7 @@ func cpuProfile() *profile.Profile {
520 520
 			Address: 0x3002,
521 521
 			Line: []profile.Line{
522 522
 				{Function: cpuF[5], Line: 5},
523
-				{Function: cpuF[3], Line: 7},
523
+				{Function: cpuF[3], Line: 9},
524 524
 			},
525 525
 		},
526 526
 	}

+ 1
- 1
internal/driver/testdata/pprof.cpu.callgrind Bestand weergeven

@@ -72,7 +72,7 @@ calls=0 -8193 1
72 72
 ob=(1)
73 73
 fl=(3)
74 74
 fn=(5)
75
-+1 7 0
75
++1 9 0
76 76
 cfl=(3)
77 77
 cfn=(3)
78 78
 calls=0 +1 5

+ 4
- 4
internal/driver/testdata/pprof.cpu.flat.addresses.disasm Bestand weergeven

@@ -1,14 +1,14 @@
1 1
 Total: 1.12s
2 2
 ROUTINE ======================== line1000
3 3
      1.10s      1.10s (flat, cum) 98.21% of Total
4
-     1.10s      1.10s       1000: instruction one                         ; line1000 file1000.src:1
4
+     1.10s      1.10s       1000: instruction one                         ;line1000 file1000.src:1
5 5
          .          .       1001: instruction two
6 6
          .          .       1002: instruction three
7 7
          .          .       1003: instruction four
8 8
 ROUTINE ======================== line3000
9 9
       10ms      1.12s (flat, cum)   100% of Total
10
-      10ms      1.01s       3000: instruction one                         ; line3000 file3000.src:6
11
-         .      100ms       3001: instruction two                         ; line3000 file3000.src:9
12
-         .       10ms       3002: instruction three                       ; line3000 file3000.src:7
10
+      10ms      1.01s       3000: instruction one                         ;line3000 file3000.src:6
11
+         .      100ms       3001: instruction two                         ;line3000 file3000.src:9
12
+         .       10ms       3002: instruction three
13 13
          .          .       3003: instruction four
14 14
          .          .       3004: instruction five

+ 4
- 4
internal/driver/testdata/pprof.cpu.flat.addresses.weblist Bestand weergeven

@@ -90,13 +90,13 @@ Duration: 10s, Total samples = 1.12s (11.20%)<br>Total: 1.12s</div><h1>line1000<
90 90
 <span class=line>      5</span> <span class=nop>           .          . line5 </span>
91 91
 <span class=line>      6</span> <span class=deadsrc>        10ms      1.01s line6 </span><span class=asm>                10ms      1.01s     3000: instruction one                                  <span class=disasmloc>file3000.src:6</span>
92 92
 </span>
93
-<span class=line>      7</span> <span class=deadsrc>           .       10ms line7 </span><span class=asm>                   .       10ms     3002: instruction three                                <span class=disasmloc>file3000.src:7</span>
93
+<span class=line>      7</span> <span class=nop>           .          . line7 </span>
94
+<span class=line>      8</span> <span class=nop>           .          . line8 </span>
95
+<span class=line>      9</span> <span class=deadsrc>           .      110ms line9 </span><span class=asm>                   .      100ms     3001: instruction two                                  <span class=disasmloc>file3000.src:9</span>
96
+                   .       10ms     3002: instruction three                                <span class=disasmloc>file3000.src:9</span>
94 97
                    .          .     3003: instruction four                                 <span class=disasmloc></span>
95 98
                    .          .     3004: instruction five                                 <span class=disasmloc></span>
96 99
 </span>
97
-<span class=line>      8</span> <span class=nop>           .          . line8 </span>
98
-<span class=line>      9</span> <span class=deadsrc>           .      100ms line9 </span><span class=asm>                   .      100ms     3001: instruction two                                  <span class=disasmloc>file3000.src:9</span>
99
-</span>
100 100
 <span class=line>     10</span> <span class=nop>           .          . line0 </span>
101 101
 <span class=line>     11</span> <span class=nop>           .          . line1 </span>
102 102
 <span class=line>     12</span> <span class=nop>           .          . line2 </span>

+ 33
- 23
internal/report/report.go Bestand weergeven

@@ -368,35 +368,45 @@ func printAssembly(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
368 368
 
369 369
 		function, file, line := "", "", 0
370 370
 		for _, n := range ns {
371
-			flat := valueOrDot(n.flatValue(), rpt)
372
-			cum := valueOrDot(n.cumValue(), rpt)
373
-			if n.function == function && n.file == file && n.line == line {
371
+			locStr := ""
372
+			// Skip loc information if it hasn't changed from previous instruction.
373
+			if n.function != function || n.file != file || n.line != line {
374
+				function, file, line = n.function, n.file, n.line
375
+				if n.function != "" {
376
+					locStr = n.function + " "
377
+				}
378
+				if n.file != "" {
379
+					locStr += n.file
380
+					if n.line != 0 {
381
+						locStr += fmt.Sprintf(":%d", n.line)
382
+					}
383
+				}
384
+			}
385
+			switch {
386
+			case locStr == "":
387
+				// No location info, just print the instruction.
374 388
 				fmt.Fprintf(w, "%10s %10s %10x: %s\n",
375
-					flat, cum,
389
+					valueOrDot(n.flatValue(), rpt),
390
+					valueOrDot(n.cumValue(), rpt),
376 391
 					n.address, n.instruction,
377 392
 				)
378
-				continue
379
-			}
380
-			line := ""
381
-			if n.line > 0 {
382
-				line = fmt.Sprintf(":%d", n.line)
383
-			}
384
-			if len(n.instruction) <= 40 {
385
-				fmt.Fprintf(w, "%10s %10s %10x: %-40s; %s %s%s\n",
386
-					flat, cum,
393
+			case len(n.instruction) < 40:
394
+				// Short instruction, print loc on the same line.
395
+				fmt.Fprintf(w, "%10s %10s %10x: %-40s;%s\n",
396
+					valueOrDot(n.flatValue(), rpt),
397
+					valueOrDot(n.cumValue(), rpt),
398
+					n.address, n.instruction,
399
+					locStr,
400
+				)
401
+			default:
402
+				// Long instruction, print loc on a separate line.
403
+				fmt.Fprintf(w, "%74s;%s\n", "", locStr)
404
+				fmt.Fprintf(w, "%10s %10s %10x: %s\n",
405
+					valueOrDot(n.flatValue(), rpt),
406
+					valueOrDot(n.cumValue(), rpt),
387 407
 					n.address, n.instruction,
388
-					n.function, n.file, line,
389 408
 				)
390
-				continue
391 409
 			}
392
-			fmt.Fprintf(w, "%75s; %s %s%s\n",
393
-				"",
394
-				n.function, n.file, line,
395
-			)
396
-			fmt.Fprintf(w, "%10s %10s %10x: %s\n",
397
-				flat, cum,
398
-				n.address, n.instruction,
399
-			)
400 410
 		}
401 411
 	}
402 412
 	return nil