PrintAssembly prints annotated disassembly of rpt to w.
(w io.Writer, rpt *Report, obj plugin.ObjTool, maxFuncs int)
| 389 | |
| 390 | // PrintAssembly prints annotated disassembly of rpt to w. |
| 391 | func PrintAssembly(w io.Writer, rpt *Report, obj plugin.ObjTool, maxFuncs int) error { |
| 392 | o := rpt.options |
| 393 | prof := rpt.prof |
| 394 | |
| 395 | g := rpt.newGraph(nil) |
| 396 | |
| 397 | // If the regexp source can be parsed as an address, also match |
| 398 | // functions that land on that address. |
| 399 | var address *uint64 |
| 400 | if hex, err := strconv.ParseUint(o.Symbol.String(), 0, 64); err == nil { |
| 401 | address = &hex |
| 402 | } |
| 403 | |
| 404 | fmt.Fprintln(w, "Total:", rpt.formatValue(rpt.total)) |
| 405 | symbols := symbolsFromBinaries(prof, g, o.Symbol, address, obj) |
| 406 | symNodes := nodesPerSymbol(g.Nodes, symbols) |
| 407 | |
| 408 | // Sort for printing. |
| 409 | var syms []*objSymbol |
| 410 | for s := range symNodes { |
| 411 | syms = append(syms, s) |
| 412 | } |
| 413 | byName := func(a, b *objSymbol) bool { |
| 414 | if na, nb := a.sym.Name[0], b.sym.Name[0]; na != nb { |
| 415 | return na < nb |
| 416 | } |
| 417 | return a.sym.Start < b.sym.Start |
| 418 | } |
| 419 | if maxFuncs < 0 { |
| 420 | sort.Sort(orderSyms{syms, byName}) |
| 421 | } else { |
| 422 | byFlatSum := func(a, b *objSymbol) bool { |
| 423 | suma, _ := symNodes[a].Sum() |
| 424 | sumb, _ := symNodes[b].Sum() |
| 425 | if suma != sumb { |
| 426 | return suma > sumb |
| 427 | } |
| 428 | return byName(a, b) |
| 429 | } |
| 430 | sort.Sort(orderSyms{syms, byFlatSum}) |
| 431 | if len(syms) > maxFuncs { |
| 432 | syms = syms[:maxFuncs] |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if len(syms) == 0 { |
| 437 | // The symbol regexp case |
| 438 | if address == nil { |
| 439 | return fmt.Errorf("no matches found for regexp %s", o.Symbol) |
| 440 | } |
| 441 | |
| 442 | // The address case |
| 443 | if len(symbols) == 0 { |
| 444 | return fmt.Errorf("no matches found for address 0x%x", *address) |
| 445 | } |
| 446 | return fmt.Errorf("address 0x%x found in binary, but the corresponding symbols do not have samples in the profile", *address) |
| 447 | } |
| 448 |
searching dependent graphs…