Skip to content

Commit 7988665

Browse files
jschwinger233brb
authored andcommitted
output: Print funcname with padding if caller is required
Signed-off-by: gray <[email protected]>
1 parent 75ca355 commit 7988665

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

internal/pwru/output.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,14 @@ func getOutFuncName(o *output, event *Event, addr uint64) string {
355355
}
356356

357357
var maxTupleLengthSeen int
358+
var maxFuncLengthSeen int
358359

359-
func fprintTupleData(writer *os.File, tupleData string) {
360-
if len(tupleData) > maxTupleLengthSeen {
361-
maxTupleLengthSeen = len(tupleData)
360+
func fprintWithPadding(writer *os.File, data string, maxLenSeen *int) {
361+
if len(data) > *maxLenSeen {
362+
*maxLenSeen = len(data)
362363
}
363-
formatter := fmt.Sprintf(" %%-%ds", maxTupleLengthSeen)
364-
fmt.Fprintf(writer, formatter, tupleData)
364+
formatter := fmt.Sprintf(" %%-%ds", *maxLenSeen)
365+
fmt.Fprintf(writer, formatter, data)
365366
}
366367

367368
func (o *output) Print(event *Event) {
@@ -393,12 +394,15 @@ func (o *output) Print(event *Event) {
393394
}
394395

395396
if o.flags.OutputTuple {
396-
fprintTupleData(o.writer, getTupleData(event))
397+
fprintWithPadding(o.writer, getTupleData(event), &maxTupleLengthSeen)
397398
}
398399

399-
fmt.Fprintf(o.writer, " %s", outFuncName)
400400
if o.flags.OutputCaller {
401+
fprintWithPadding(o.writer, outFuncName, &maxFuncLengthSeen)
401402
fmt.Fprintf(o.writer, " %s", o.addr2name.findNearestSym(event.CallerAddr))
403+
} else {
404+
405+
fmt.Fprintf(o.writer, " %s", outFuncName)
402406
}
403407

404408
if o.flags.OutputStack && event.PrintStackId > 0 {

0 commit comments

Comments
 (0)