diff --git a/cmd/leak.go b/cmd/leak.go index 5ecbc26..1ee5811 100644 --- a/cmd/leak.go +++ b/cmd/leak.go @@ -15,13 +15,12 @@ var leakOpts = struct { // leakCmd represents the leak command var leakCmd = &cobra.Command{ Use: "leak [flags] ", - Short: "Find objects which are likely leaked memory.", + Short: "Find objects which are likely leaked memory", Long: `Find objects which are likely leaked memory. Compares the objects in three different dumps (A, B, C), to identify which objects are present in both B and C, and not present in A.`, - // Args: cobra.ExactArgs(3), Run: func(cmd *cobra.Command, args []string) { if len(args) != 3 { usage_er(cmd, fmt.Sprintf("requires 3 args, received %d", len(args))) diff --git a/obj/dump.go b/leak/dump.go similarity index 99% rename from obj/dump.go rename to leak/dump.go index 8e863e2..90493d1 100644 --- a/obj/dump.go +++ b/leak/dump.go @@ -1,4 +1,4 @@ -package obj +package leak import ( "bufio" diff --git a/obj/entry.go b/leak/entry.go similarity index 97% rename from obj/entry.go rename to leak/entry.go index 60179d9..7e355b2 100644 --- a/obj/entry.go +++ b/leak/entry.go @@ -1,4 +1,4 @@ -package obj +package leak // NewEntry returns a new *Entry instance initialized with a *Object of the // given input JSON data. diff --git a/leak/finder.go b/leak/finder.go index c0b7f64..a824686 100644 --- a/leak/finder.go +++ b/leak/finder.go @@ -3,8 +3,6 @@ package leak import ( "fmt" "time" - - "github.com/jimeh/rbheap/obj" ) // NewFinder returns a new *Finder instance, populated with the three given file @@ -19,7 +17,7 @@ func NewFinder(filePath1, filePath2, filePath3 string) *Finder { // from a Ruby process. type Finder struct { FilePaths [3]string - Dumps [3]*obj.Dump + Dumps [3]*Dump Leaks []*string Verbose bool } @@ -29,7 +27,7 @@ func (s *Finder) Process() error { for i, filePath := range s.FilePaths { start := time.Now() s.log(fmt.Sprintf("Parsing %s", filePath)) - dump := obj.NewDump(filePath) + dump := NewDump(filePath) err := dump.Process() if err != nil { diff --git a/obj/object.go b/leak/object.go similarity index 97% rename from obj/object.go rename to leak/object.go index ae4aa3e..874b2d4 100644 --- a/obj/object.go +++ b/leak/object.go @@ -1,4 +1,4 @@ -package obj +package leak import "encoding/json" diff --git a/obj/object_easyjson.go b/leak/object_easyjson.go similarity index 81% rename from obj/object_easyjson.go rename to leak/object_easyjson.go index 02a218e..3cdfc2d 100644 --- a/obj/object_easyjson.go +++ b/leak/object_easyjson.go @@ -1,6 +1,6 @@ // Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. -package obj +package leak import ( json "encoding/json" @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjsonE44bcf2dDecodeGithubComJimehRbheapObj(in *jlexer.Lexer, out *Object) { +func easyjsonE44bcf2dDecodeGithubComJimehRbheapLeak(in *jlexer.Lexer, out *Object) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -50,7 +50,7 @@ func easyjsonE44bcf2dDecodeGithubComJimehRbheapObj(in *jlexer.Lexer, out *Object in.Consumed() } } -func easyjsonE44bcf2dEncodeGithubComJimehRbheapObj(out *jwriter.Writer, in Object) { +func easyjsonE44bcf2dEncodeGithubComJimehRbheapLeak(out *jwriter.Writer, in Object) { out.RawByte('{') first := true _ = first @@ -80,23 +80,23 @@ func easyjsonE44bcf2dEncodeGithubComJimehRbheapObj(out *jwriter.Writer, in Objec // MarshalJSON supports json.Marshaler interface func (v Object) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjsonE44bcf2dEncodeGithubComJimehRbheapObj(&w, v) + easyjsonE44bcf2dEncodeGithubComJimehRbheapLeak(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Object) MarshalEasyJSON(w *jwriter.Writer) { - easyjsonE44bcf2dEncodeGithubComJimehRbheapObj(w, v) + easyjsonE44bcf2dEncodeGithubComJimehRbheapLeak(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Object) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjsonE44bcf2dDecodeGithubComJimehRbheapObj(&r, v) + easyjsonE44bcf2dDecodeGithubComJimehRbheapLeak(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Object) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjsonE44bcf2dDecodeGithubComJimehRbheapObj(l, v) + easyjsonE44bcf2dDecodeGithubComJimehRbheapLeak(l, v) } diff --git a/test/leak.rb b/test/leak.rb index 0e243b2..f99e845 100644 --- a/test/leak.rb +++ b/test/leak.rb @@ -1,5 +1,7 @@ require 'objspace' +ObjectSpace.trace_object_allocations_start + class Leaky def self.leak @leak ||= [] @@ -8,7 +10,7 @@ class Leaky def doit noleak = [] - 50.times do + 100.times do self.class.leak << 'leaked memory' noleak << 'not leaked' end @@ -21,8 +23,8 @@ def dump_heap(filename) end Leaky.new.doit -dump_heap('heap1.jsonl') +dump_heap(File.expand_path('./heap1.jsonl', __dir__)) Leaky.new.doit -dump_heap('heap2.jsonl') +dump_heap(File.expand_path('./heap2.jsonl', __dir__)) Leaky.new.doit -dump_heap('heap3.jsonl') +dump_heap(File.expand_path('./heap3.jsonl', __dir__))