Skip to content

Commit

Permalink
output: Print funcname with padding if caller is required
Browse files Browse the repository at this point in the history
Signed-off-by: gray <[email protected]>
  • Loading branch information
jschwinger233 authored and brb committed Jun 11, 2024
1 parent 75ca355 commit 7988665
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/pwru/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,14 @@ func getOutFuncName(o *output, event *Event, addr uint64) string {
}

var maxTupleLengthSeen int
var maxFuncLengthSeen int

func fprintTupleData(writer *os.File, tupleData string) {
if len(tupleData) > maxTupleLengthSeen {
maxTupleLengthSeen = len(tupleData)
func fprintWithPadding(writer *os.File, data string, maxLenSeen *int) {
if len(data) > *maxLenSeen {
*maxLenSeen = len(data)
}
formatter := fmt.Sprintf(" %%-%ds", maxTupleLengthSeen)
fmt.Fprintf(writer, formatter, tupleData)
formatter := fmt.Sprintf(" %%-%ds", *maxLenSeen)
fmt.Fprintf(writer, formatter, data)
}

func (o *output) Print(event *Event) {
Expand Down Expand Up @@ -393,12 +394,15 @@ func (o *output) Print(event *Event) {
}

if o.flags.OutputTuple {
fprintTupleData(o.writer, getTupleData(event))
fprintWithPadding(o.writer, getTupleData(event), &maxTupleLengthSeen)
}

fmt.Fprintf(o.writer, " %s", outFuncName)
if o.flags.OutputCaller {
fprintWithPadding(o.writer, outFuncName, &maxFuncLengthSeen)
fmt.Fprintf(o.writer, " %s", o.addr2name.findNearestSym(event.CallerAddr))
} else {

fmt.Fprintf(o.writer, " %s", outFuncName)
}

if o.flags.OutputStack && event.PrintStackId > 0 {
Expand Down

0 comments on commit 7988665

Please sign in to comment.