Skip to content

Commit

Permalink
Flush output file
Browse files Browse the repository at this point in the history
Flush output file before closing it.

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
  • Loading branch information
Asphaltt authored and brb committed Feb 26, 2024
1 parent 53e8f30 commit f539556
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/pwru/output.go
Expand Up @@ -7,7 +7,6 @@ package pwru
import (
"errors"
"fmt"
"io"
"log"
"net"
"os"
Expand Down Expand Up @@ -36,7 +35,7 @@ type output struct {
printSkbMap *ebpf.Map
printStackMap *ebpf.Map
addr2name Addr2Name
writer io.Writer
writer *os.File
kprobeMulti bool
kfreeReasons map[uint64]string
ifaceCache map[uint64]map[uint32]string
Expand Down Expand Up @@ -81,6 +80,13 @@ func NewOutput(flags *Flags, printSkbMap *ebpf.Map, printStackMap *ebpf.Map,
}, nil
}

func (o *output) Close() {
if o.writer != os.Stdout {
_ = o.writer.Sync()
_ = o.writer.Close()
}
}

func (o *output) PrintHeader() {
if o.flags.OutputTS == "absolute" {
fmt.Fprintf(o.writer, "%12s ", "TIME")
Expand Down
1 change: 1 addition & 0 deletions main.go
Expand Up @@ -299,6 +299,7 @@ func main() {
if err != nil {
log.Fatalf("Failed to create outputer: %s", err)
}
defer output.Close()
output.PrintHeader()

defer func() {
Expand Down

0 comments on commit f539556

Please sign in to comment.