Browse Source

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 years ago
parent
commit
39ed5b5f27

+ 1
- 1
internal/driver/driver_test.go View File

520
 			Address: 0x3002,
520
 			Address: 0x3002,
521
 			Line: []profile.Line{
521
 			Line: []profile.Line{
522
 				{Function: cpuF[5], Line: 5},
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 View File

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

+ 4
- 4
internal/driver/testdata/pprof.cpu.flat.addresses.disasm View File

1
 Total: 1.12s
1
 Total: 1.12s
2
 ROUTINE ======================== line1000
2
 ROUTINE ======================== line1000
3
      1.10s      1.10s (flat, cum) 98.21% of Total
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
          .          .       1001: instruction two
5
          .          .       1001: instruction two
6
          .          .       1002: instruction three
6
          .          .       1002: instruction three
7
          .          .       1003: instruction four
7
          .          .       1003: instruction four
8
 ROUTINE ======================== line3000
8
 ROUTINE ======================== line3000
9
       10ms      1.12s (flat, cum)   100% of Total
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
          .          .       3003: instruction four
13
          .          .       3003: instruction four
14
          .          .       3004: instruction five
14
          .          .       3004: instruction five

+ 4
- 4
internal/driver/testdata/pprof.cpu.flat.addresses.weblist View File

90
 <span class=line>      5</span> <span class=nop>           .          . line5 </span>
90
 <span class=line>      5</span> <span class=nop>           .          . line5 </span>
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>
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
 </span>
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
                    .          .     3003: instruction four                                 <span class=disasmloc></span>
97
                    .          .     3003: instruction four                                 <span class=disasmloc></span>
95
                    .          .     3004: instruction five                                 <span class=disasmloc></span>
98
                    .          .     3004: instruction five                                 <span class=disasmloc></span>
96
 </span>
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
 <span class=line>     10</span> <span class=nop>           .          . line0 </span>
100
 <span class=line>     10</span> <span class=nop>           .          . line0 </span>
101
 <span class=line>     11</span> <span class=nop>           .          . line1 </span>
101
 <span class=line>     11</span> <span class=nop>           .          . line1 </span>
102
 <span class=line>     12</span> <span class=nop>           .          . line2 </span>
102
 <span class=line>     12</span> <span class=nop>           .          . line2 </span>

+ 33
- 23
internal/report/report.go View File

368
 
368
 
369
 		function, file, line := "", "", 0
369
 		function, file, line := "", "", 0
370
 		for _, n := range ns {
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
 				fmt.Fprintf(w, "%10s %10s %10x: %s\n",
388
 				fmt.Fprintf(w, "%10s %10s %10x: %s\n",
375
-					flat, cum,
389
+					valueOrDot(n.flatValue(), rpt),
390
+					valueOrDot(n.cumValue(), rpt),
376
 					n.address, n.instruction,
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
 					n.address, n.instruction,
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
 	return nil
412
 	return nil