Print verbose output to STDERR

This commit is contained in:
2018-07-13 11:45:32 +01:00
parent eff9aa36f6
commit bba2ee915e

View File

@@ -2,6 +2,7 @@ package leak
import (
"fmt"
"io"
"time"
)
@@ -16,17 +17,18 @@ func NewFinder(filePath1, filePath2, filePath3 string) *Finder {
// Finder helps with finding a memory leak across three different memory dumps
// from a Ruby process.
type Finder struct {
FilePaths [3]string
Dumps [3]*Dump
Leaks []*string
Verbose bool
FilePaths [3]string
Dumps [3]*Dump
Leaks []*string
Verbose bool
VerboseWriter io.Writer
}
// Process will will load and process each of the dump files.
func (s *Finder) Process() error {
for i, filePath := range s.FilePaths {
start := time.Now()
s.log(fmt.Sprintf("Parsing %s", filePath))
s.verbose(fmt.Sprintf("Parsing %s", filePath))
dump := NewDump(filePath)
err := dump.Process()
@@ -36,7 +38,7 @@ func (s *Finder) Process() error {
s.Dumps[i] = dump
elapsed := time.Now().Sub(start)
s.log(fmt.Sprintf(
s.verbose(fmt.Sprintf(
"Parsed %d objects in %.6f seconds",
len(dump.Index),
elapsed.Seconds(),
@@ -96,3 +98,15 @@ func (s *Finder) log(msg string) {
fmt.Println(msg)
}
}
func (s *Finder) verbose(msg string) {
if s.Verbose {
w := s.VerboseWriter
if w == nil {
w = os.Stderr
}
fmt.Fprintln(w, msg)
}
}