浏览代码

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
 	const objdump = "testdata/wrapper/objdump"
137
 	const objdump = "testdata/wrapper/objdump"
138
 
138
 
139
 	for _, tc := range testcases {
139
 	for _, tc := range testcases {
140
-		insns, err := disassemble([]byte(tc.asm))
140
+		insts, err := disassemble([]byte(tc.asm))
141
 		if err != nil {
141
 		if err != nil {
142
 			t.Fatalf("FunctionAssembly: %v", err)
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
 		flatSum, cumSum := sns.Sum()
303
 		flatSum, cumSum := sns.Sum()
304
 
304
 
305
 		// Get the function assembly.
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
 		if err != nil {
307
 		if err != nil {
308
 			return err
308
 			return err
309
 		}
309
 		}
310
 
310
 
311
-		ns := annotateAssembly(insns, sns, s.base)
311
+		ns := annotateAssembly(insts, sns, s.base)
312
 
312
 
313
 		fmt.Fprintf(w, "ROUTINE ======================== %s\n", s.sym.Name[0])
313
 		fmt.Fprintf(w, "ROUTINE ======================== %s\n", s.sym.Name[0])
314
 		for _, name := range s.sym.Name[1:] {
314
 		for _, name := range s.sym.Name[1:] {
473
 // annotateAssembly annotates a set of assembly instructions with a
473
 // annotateAssembly annotates a set of assembly instructions with a
474
 // set of samples. It returns a set of nodes to display. base is an
474
 // set of samples. It returns a set of nodes to display. base is an
475
 // offset to adjust the sample addresses.
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
 	// Add end marker to simplify printing loop.
477
 	// Add end marker to simplify printing loop.
478
-	insns = append(insns, plugin.Inst{
478
+	insts = append(insts, plugin.Inst{
479
 		Addr: ^uint64(0),
479
 		Addr: ^uint64(0),
480
 	})
480
 	})
481
 
481
 
483
 	samples.Sort(graph.AddressOrder)
483
 	samples.Sort(graph.AddressOrder)
484
 
484
 
485
 	s := 0
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
 		n := assemblyInstruction{
488
 		n := assemblyInstruction{
489
 			address:     in.Addr,
489
 			address:     in.Addr,
490
 			instruction: in.Text,
490
 			instruction: in.Text,
497
 
497
 
498
 		// Sum all the samples until the next instruction (to account
498
 		// Sum all the samples until the next instruction (to account
499
 		// for samples attributed to the middle of an instruction).
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
 			sample := samples[s]
501
 			sample := samples[s]
502
 			n.flatDiv += sample.FlatDiv
502
 			n.flatDiv += sample.FlatDiv
503
 			n.flat += sample.Flat
503
 			n.flat += sample.Flat

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

228
 	}
228
 	}
229
 
229
 
230
 	// Extract assembly for matched symbol
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
 	if err != nil {
232
 	if err != nil {
233
 		return assembly
233
 		return assembly
234
 	}
234
 	}
235
 
235
 
236
 	srcBase := filepath.Base(src)
236
 	srcBase := filepath.Base(src)
237
-	anodes := annotateAssembly(insns, rs, o.base)
237
+	anodes := annotateAssembly(insts, rs, o.base)
238
 	var lineno = 0
238
 	var lineno = 0
239
 	for _, an := range anodes {
239
 	for _, an := range anodes {
240
 		if filepath.Base(an.file) == srcBase {
240
 		if filepath.Base(an.file) == srcBase {
421
 func getMissingFunctionSource(filename string, asm map[int][]assemblyInstruction, start, end int) (graph.Nodes, string) {
421
 func getMissingFunctionSource(filename string, asm map[int][]assemblyInstruction, start, end int) (graph.Nodes, string) {
422
 	var fnodes graph.Nodes
422
 	var fnodes graph.Nodes
423
 	for i := start; i <= end; i++ {
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
 			continue
426
 			continue
427
 		}
427
 		}
428
 		var group assemblyInstruction
428
 		var group assemblyInstruction
429
-		for _, insn := range insns {
429
+		for _, insn := range insts {
430
 			group.flat += insn.flat
430
 			group.flat += insn.flat
431
 			group.cum += insn.cum
431
 			group.cum += insn.cum
432
 			group.flatDiv += insn.flatDiv
432
 			group.flatDiv += insn.flatDiv