Skip to content

Commit 2d104b1

Browse files
authored
Merge pull request #60 from rauls5382/disasm
Improve loc information of assembly listings
2 parents 8c31d10 + 39ed5b5 commit 2d104b1

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

internal/driver/driver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func cpuProfile() *profile.Profile {
520520
Address: 0x3002,
521521
Line: []profile.Line{
522522
{Function: cpuF[5], Line: 5},
523-
{Function: cpuF[3], Line: 7},
523+
{Function: cpuF[3], Line: 9},
524524
},
525525
},
526526
}

internal/driver/testdata/pprof.cpu.callgrind

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ calls=0 -8193 1
7272
ob=(1)
7373
fl=(3)
7474
fn=(5)
75-
+1 7 0
75+
+1 9 0
7676
cfl=(3)
7777
cfn=(3)
7878
calls=0 +1 5
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Total: 1.12s
22
ROUTINE ======================== line1000
33
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
55
. . 1001: instruction two
66
. . 1002: instruction three
77
. . 1003: instruction four
88
ROUTINE ======================== line3000
99
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
1313
. . 3003: instruction four
1414
. . 3004: instruction five

internal/driver/testdata/pprof.cpu.flat.addresses.weblist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ Duration: 10s, Total samples = 1.12s (11.20%)<br>Total: 1.12s</div><h1>line1000<
9090
<span class=line> 5</span> <span class=nop> . . line5 </span>
9191
<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>
9292
</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>
9497
. . 3003: instruction four <span class=disasmloc></span>
9598
. . 3004: instruction five <span class=disasmloc></span>
9699
</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>
100100
<span class=line> 10</span> <span class=nop> . . line0 </span>
101101
<span class=line> 11</span> <span class=nop> . . line1 </span>
102102
<span class=line> 12</span> <span class=nop> . . line2 </span>

internal/report/report.go

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -368,35 +368,45 @@ func printAssembly(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
368368

369369
function, file, line := "", "", 0
370370
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.
374388
fmt.Fprintf(w, "%10s %10s %10x: %s\n",
375-
flat, cum,
389+
valueOrDot(n.flatValue(), rpt),
390+
valueOrDot(n.cumValue(), rpt),
376391
n.address, n.instruction,
377392
)
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),
387407
n.address, n.instruction,
388-
n.function, n.file, line,
389408
)
390-
continue
391409
}
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-
)
400410
}
401411
}
402412
return nil

0 commit comments

Comments
 (0)