mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 12:56:46 +00:00
Ensure all exported functions and types have descriptive comments
This commit is contained in:
@@ -7,12 +7,16 @@ import (
|
||||
"github.com/jimeh/rbheap/obj"
|
||||
)
|
||||
|
||||
// NewFinder returns a new *Finder instance, populated with the three given file
|
||||
// paths.
|
||||
func NewFinder(filePath1, filePath2, filePath3 string) *Finder {
|
||||
return &Finder{
|
||||
FilePaths: [3]string{filePath1, filePath2, filePath3},
|
||||
}
|
||||
}
|
||||
|
||||
// Finder helps with finding a memory leak across three different memory dumps
|
||||
// from a Ruby process.
|
||||
type Finder struct {
|
||||
FilePaths [3]string
|
||||
Dumps [3]*obj.Dump
|
||||
@@ -20,6 +24,7 @@ type Finder struct {
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
// 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()
|
||||
@@ -43,16 +48,23 @@ func (s *Finder) Process() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrintLeakedAddresses prints the memory addresses in hex (0x...) format for
|
||||
// all objects which are likely to be leaked memory.
|
||||
func (s *Finder) PrintLeakedAddresses() {
|
||||
s.log("\nLeaked Addresses:")
|
||||
s.Dumps[1].PrintEntryAddress(s.FindLeaks())
|
||||
}
|
||||
|
||||
// PrintLeakedObjects prints the full JSON blobs for all objects which are
|
||||
// likely to be memory leaks.
|
||||
func (s *Finder) PrintLeakedObjects() error {
|
||||
s.log("\nLeaked Objects:")
|
||||
return s.Dumps[1].PrintEntryJSON(s.FindLeaks())
|
||||
}
|
||||
|
||||
// FindLeaks finds potential memory leaks by removing all objects in heap dump
|
||||
// #1 from heap dump #2, and then also removing all entries from heap dump #2
|
||||
// which are not present in heap dump #3.
|
||||
func (s *Finder) FindLeaks() []*string {
|
||||
if s.Leaks != nil {
|
||||
return s.Leaks
|
||||
|
||||
Reference in New Issue
Block a user