mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 12:56:46 +00:00
Print verbose output to STDERR
This commit is contained in:
@@ -2,6 +2,7 @@ package leak
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,17 +17,18 @@ func NewFinder(filePath1, filePath2, filePath3 string) *Finder {
|
|||||||
// Finder helps with finding a memory leak across three different memory dumps
|
// Finder helps with finding a memory leak across three different memory dumps
|
||||||
// from a Ruby process.
|
// from a Ruby process.
|
||||||
type Finder struct {
|
type Finder struct {
|
||||||
FilePaths [3]string
|
FilePaths [3]string
|
||||||
Dumps [3]*Dump
|
Dumps [3]*Dump
|
||||||
Leaks []*string
|
Leaks []*string
|
||||||
Verbose bool
|
Verbose bool
|
||||||
|
VerboseWriter io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process will will load and process each of the dump files.
|
// Process will will load and process each of the dump files.
|
||||||
func (s *Finder) Process() error {
|
func (s *Finder) Process() error {
|
||||||
for i, filePath := range s.FilePaths {
|
for i, filePath := range s.FilePaths {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
s.log(fmt.Sprintf("Parsing %s", filePath))
|
s.verbose(fmt.Sprintf("Parsing %s", filePath))
|
||||||
dump := NewDump(filePath)
|
dump := NewDump(filePath)
|
||||||
|
|
||||||
err := dump.Process()
|
err := dump.Process()
|
||||||
@@ -36,7 +38,7 @@ func (s *Finder) Process() error {
|
|||||||
|
|
||||||
s.Dumps[i] = dump
|
s.Dumps[i] = dump
|
||||||
elapsed := time.Now().Sub(start)
|
elapsed := time.Now().Sub(start)
|
||||||
s.log(fmt.Sprintf(
|
s.verbose(fmt.Sprintf(
|
||||||
"Parsed %d objects in %.6f seconds",
|
"Parsed %d objects in %.6f seconds",
|
||||||
len(dump.Index),
|
len(dump.Index),
|
||||||
elapsed.Seconds(),
|
elapsed.Seconds(),
|
||||||
@@ -96,3 +98,15 @@ func (s *Finder) log(msg string) {
|
|||||||
fmt.Println(msg)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user