瀏覽代碼

Replace insns with insts for list of assembly instructions

Raul Silvera 8 年之前
父節點
當前提交
8f46b46449
共有 3 個檔案被更改,包括 18 行新增18 行删除
  1. 6
    6
      internal/binutils/disasm_test.go
  2. 7
    7
      internal/report/report.go
  3. 5
    5
      internal/report/source.go

+ 6
- 6
internal/binutils/disasm_test.go 查看文件

@@ -137,17 +137,17 @@ func TestFunctionAssembly(t *testing.T) {
137 137
 	const objdump = "testdata/wrapper/objdump"
138 138
 
139 139
 	for _, tc := range testcases {
140
-		insns, err := disassemble([]byte(tc.asm))
140
+		insts, err := disassemble([]byte(tc.asm))
141 141
 		if err != nil {
142 142
 			t.Fatalf("FunctionAssembly: %v", err)
143 143
 		}
144 144
 
145
-		if len(insns) != len(tc.want) {
146
-			t.Errorf("Unexpected number of assembly instructions %d (want %d)\n", len(insns), len(tc.want))
145
+		if len(insts) != len(tc.want) {
146
+			t.Errorf("Unexpected number of assembly instructions %d (want %d)\n", len(insts), len(tc.want))
147 147
 		}
148
-		for i := range insns {
149
-			if insns[i] != tc.want[i] {
150
-				t.Errorf("Expected symbol %v, got %v\n", tc.want[i], insns[i])
148
+		for i := range insts {
149
+			if insts[i] != tc.want[i] {
150
+				t.Errorf("Expected symbol %v, got %v\n", tc.want[i], insts[i])
151 151
 			}
152 152
 		}
153 153
 	}

+ 7
- 7
internal/report/report.go 查看文件

@@ -303,12 +303,12 @@ func printAssembly(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
303 303
 		flatSum, cumSum := sns.Sum()
304 304
 
305 305
 		// Get the function assembly.
306
-		insns, err := obj.Disasm(s.sym.File, s.sym.Start, s.sym.End)
306
+		insts, err := obj.Disasm(s.sym.File, s.sym.Start, s.sym.End)
307 307
 		if err != nil {
308 308
 			return err
309 309
 		}
310 310
 
311
-		ns := annotateAssembly(insns, sns, s.base)
311
+		ns := annotateAssembly(insts, sns, s.base)
312 312
 
313 313
 		fmt.Fprintf(w, "ROUTINE ======================== %s\n", s.sym.Name[0])
314 314
 		for _, name := range s.sym.Name[1:] {
@@ -473,9 +473,9 @@ func (a *assemblyInstruction) cumValue() int64 {
473 473
 // annotateAssembly annotates a set of assembly instructions with a
474 474
 // set of samples. It returns a set of nodes to display. base is an
475 475
 // offset to adjust the sample addresses.
476
-func annotateAssembly(insns []plugin.Inst, samples graph.Nodes, base uint64) []assemblyInstruction {
476
+func annotateAssembly(insts []plugin.Inst, samples graph.Nodes, base uint64) []assemblyInstruction {
477 477
 	// Add end marker to simplify printing loop.
478
-	insns = append(insns, plugin.Inst{
478
+	insts = append(insts, plugin.Inst{
479 479
 		Addr: ^uint64(0),
480 480
 	})
481 481
 
@@ -483,8 +483,8 @@ func annotateAssembly(insns []plugin.Inst, samples graph.Nodes, base uint64) []a
483 483
 	samples.Sort(graph.AddressOrder)
484 484
 
485 485
 	s := 0
486
-	asm := make([]assemblyInstruction, 0, len(insns))
487
-	for ix, in := range insns[:len(insns)-1] {
486
+	asm := make([]assemblyInstruction, 0, len(insts))
487
+	for ix, in := range insts[:len(insts)-1] {
488 488
 		n := assemblyInstruction{
489 489
 			address:     in.Addr,
490 490
 			instruction: in.Text,
@@ -497,7 +497,7 @@ func annotateAssembly(insns []plugin.Inst, samples graph.Nodes, base uint64) []a
497 497
 
498 498
 		// Sum all the samples until the next instruction (to account
499 499
 		// for samples attributed to the middle of an instruction).
500
-		for next := insns[ix+1].Addr; s < len(samples) && samples[s].Info.Address-base < next; s++ {
500
+		for next := insts[ix+1].Addr; s < len(samples) && samples[s].Info.Address-base < next; s++ {
501 501
 			sample := samples[s]
502 502
 			n.flatDiv += sample.FlatDiv
503 503
 			n.flat += sample.Flat

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

@@ -228,13 +228,13 @@ func assemblyPerSourceLine(objSyms []*objSymbol, rs graph.Nodes, src string, obj
228 228
 	}
229 229
 
230 230
 	// Extract assembly for matched symbol
231
-	insns, err := obj.Disasm(o.sym.File, o.sym.Start, o.sym.End)
231
+	insts, err := obj.Disasm(o.sym.File, o.sym.Start, o.sym.End)
232 232
 	if err != nil {
233 233
 		return assembly
234 234
 	}
235 235
 
236 236
 	srcBase := filepath.Base(src)
237
-	anodes := annotateAssembly(insns, rs, o.base)
237
+	anodes := annotateAssembly(insts, rs, o.base)
238 238
 	var lineno = 0
239 239
 	for _, an := range anodes {
240 240
 		if filepath.Base(an.file) == srcBase {
@@ -421,12 +421,12 @@ func getSourceFromFile(file, sourcePath string, fns graph.Nodes, start, end int)
421 421
 func getMissingFunctionSource(filename string, asm map[int][]assemblyInstruction, start, end int) (graph.Nodes, string) {
422 422
 	var fnodes graph.Nodes
423 423
 	for i := start; i <= end; i++ {
424
-		insns := asm[i]
425
-		if len(insns) == 0 {
424
+		insts := asm[i]
425
+		if len(insts) == 0 {
426 426
 			continue
427 427
 		}
428 428
 		var group assemblyInstruction
429
-		for _, insn := range insns {
429
+		for _, insn := range insts {
430 430
 			group.flat += insn.flat
431 431
 			group.cum += insn.cum
432 432
 			group.flatDiv += insn.flatDiv