mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 12:56:46 +00:00
Initial hacky version of inspect source command
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func NewDump(filePath string) *Dump {
|
||||
@@ -14,14 +13,14 @@ func NewDump(filePath string) *Dump {
|
||||
// Dump contains all relevant data for a single heap dump.
|
||||
type Dump struct {
|
||||
FilePath string
|
||||
ByAddress map[string]*Object
|
||||
Objects map[string]*Object
|
||||
ByFile map[string][]*Object
|
||||
ByFileAndLine map[string][]*Object
|
||||
ByGeneration map[int][]*Object
|
||||
}
|
||||
|
||||
// Process processes the heap dump referenced in FilePath.
|
||||
func (s *Dump) Process() error {
|
||||
// Load processes the heap dump referenced in FilePath.
|
||||
func (s *Dump) Load() error {
|
||||
file, err := os.Open(s.FilePath)
|
||||
defer file.Close()
|
||||
|
||||
@@ -29,10 +28,7 @@ func (s *Dump) Process() error {
|
||||
return err
|
||||
}
|
||||
|
||||
s.ByAddress = map[string]*Object{}
|
||||
s.ByFile = map[string][]*Object{}
|
||||
s.ByFileAndLine = map[string][]*Object{}
|
||||
s.ByGeneration = map[int][]*Object{}
|
||||
s.Objects = map[string]*Object{}
|
||||
|
||||
reader := bufio.NewReader(file)
|
||||
for {
|
||||
@@ -54,21 +50,12 @@ func (s *Dump) Process() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Dump) Lookup(address string) (*Object, bool) {
|
||||
object, ok := s.Objects[address]
|
||||
return object, ok
|
||||
}
|
||||
|
||||
// AddObject adds a *Object to the Dump.
|
||||
func (s *Dump) AddObject(obj *Object) {
|
||||
s.ByAddress[obj.Address] = obj
|
||||
|
||||
if obj.File != "" {
|
||||
s.ByFile[obj.File] = append(s.ByFile[obj.File], obj)
|
||||
}
|
||||
|
||||
if obj.File != "" && obj.Line != 0 {
|
||||
key := obj.File + ":" + strconv.Itoa(obj.Line)
|
||||
s.ByFileAndLine[key] = append(s.ByFileAndLine[key], obj)
|
||||
}
|
||||
|
||||
if obj.Generation != 0 {
|
||||
s.ByGeneration[obj.Generation] =
|
||||
append(s.ByGeneration[obj.Generation], obj)
|
||||
}
|
||||
s.Objects[obj.Address] = obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user