From b4dde18179b30f397a0b7562b883184dbf247fc5 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 7 Jul 2018 18:58:50 +0100 Subject: [PATCH] Rename HeapItem to HeapEntry --- heap_dump.go | 14 ++++++------- heap_entry.go | 9 +++++++++ ...item_easyjson.go => heap_entry_easyjson.go | 20 +++++++++---------- heap_item.go | 9 --------- main.go | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 heap_entry.go rename heap_item_easyjson.go => heap_entry_easyjson.go (72%) delete mode 100644 heap_item.go diff --git a/heap_dump.go b/heap_dump.go index d75d519..090451e 100644 --- a/heap_dump.go +++ b/heap_dump.go @@ -15,9 +15,9 @@ func NewHeapDump(file string) (*HeapDump, error) { // HeapDump contains all relevant data for a single heap dump. type HeapDump struct { - File string - Index []string - Items map[string]*HeapItem + File string + Index []string + Entries map[string]*HeapEntry } // Process processes the heap dump @@ -29,7 +29,7 @@ func (s *HeapDump) Process() error { return err } - s.Items = map[string]*HeapItem{} + s.Entries = map[string]*HeapEntry{} reader := bufio.NewReader(file) for { @@ -56,14 +56,14 @@ func (s *HeapDump) ProcessLine(line []byte) error { if len(item.Address) > 0 { index := item.Address + ":" + item.Type - s.Items[index] = item + s.Entries[index] = item s.Index = append(s.Index, index) } return nil } -func (s *HeapDump) Parse(itemJSON []byte) (*HeapItem, error) { - var i HeapItem +func (s *HeapDump) Parse(itemJSON []byte) (*HeapEntry, error) { + var i HeapEntry err := json.Unmarshal(itemJSON, &i) return &i, err diff --git a/heap_entry.go b/heap_entry.go new file mode 100644 index 0000000..0b26170 --- /dev/null +++ b/heap_entry.go @@ -0,0 +1,9 @@ +package main + +//go:generate easyjson -all heap_entry.go + +// HeapEntry is a parsed heap item object +type HeapEntry struct { + Address string `json:"address"` + Type string `json:"type"` +} diff --git a/heap_item_easyjson.go b/heap_entry_easyjson.go similarity index 72% rename from heap_item_easyjson.go rename to heap_entry_easyjson.go index 448e900..4fa57bd 100644 --- a/heap_item_easyjson.go +++ b/heap_entry_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson1c69144aDecodeGithubComJimehRbheapleak(in *jlexer.Lexer, out *HeapItem) { +func easyjson48125c2bDecodeGithubComJimehRbheapleak(in *jlexer.Lexer, out *HeapEntry) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -50,7 +50,7 @@ func easyjson1c69144aDecodeGithubComJimehRbheapleak(in *jlexer.Lexer, out *HeapI in.Consumed() } } -func easyjson1c69144aEncodeGithubComJimehRbheapleak(out *jwriter.Writer, in HeapItem) { +func easyjson48125c2bEncodeGithubComJimehRbheapleak(out *jwriter.Writer, in HeapEntry) { out.RawByte('{') first := true _ = first @@ -78,25 +78,25 @@ func easyjson1c69144aEncodeGithubComJimehRbheapleak(out *jwriter.Writer, in Heap } // MarshalJSON supports json.Marshaler interface -func (v HeapItem) MarshalJSON() ([]byte, error) { +func (v HeapEntry) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson1c69144aEncodeGithubComJimehRbheapleak(&w, v) + easyjson48125c2bEncodeGithubComJimehRbheapleak(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface -func (v HeapItem) MarshalEasyJSON(w *jwriter.Writer) { - easyjson1c69144aEncodeGithubComJimehRbheapleak(w, v) +func (v HeapEntry) MarshalEasyJSON(w *jwriter.Writer) { + easyjson48125c2bEncodeGithubComJimehRbheapleak(w, v) } // UnmarshalJSON supports json.Unmarshaler interface -func (v *HeapItem) UnmarshalJSON(data []byte) error { +func (v *HeapEntry) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson1c69144aDecodeGithubComJimehRbheapleak(&r, v) + easyjson48125c2bDecodeGithubComJimehRbheapleak(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *HeapItem) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson1c69144aDecodeGithubComJimehRbheapleak(l, v) +func (v *HeapEntry) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson48125c2bDecodeGithubComJimehRbheapleak(l, v) } diff --git a/heap_item.go b/heap_item.go deleted file mode 100644 index ee28721..0000000 --- a/heap_item.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -//go:generate easyjson -all heap_item.go - -// HeapItem is a parsed heap item object -type HeapItem struct { - Address string `json:"address"` - Type string `json:"type"` -} diff --git a/main.go b/main.go index 2db8469..94f40aa 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func diffsect(a, b, c *[]string) *[]string { func printHexDiff(leaked *[]string, dump *HeapDump) { for _, index := range *leaked { - if item, ok := dump.Items[index]; ok { + if item, ok := dump.Entries[index]; ok { fmt.Printf("%s\n", item.Address) } }