mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 04:46:40 +00:00
Migrate leak related structs to leak package
This commit is contained in:
@@ -15,13 +15,12 @@ var leakOpts = struct {
|
||||
// leakCmd represents the leak command
|
||||
var leakCmd = &cobra.Command{
|
||||
Use: "leak [flags] <dump-A> <dump-B> <dump-C>",
|
||||
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)))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package obj
|
||||
package leak
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -1,4 +1,4 @@
|
||||
package obj
|
||||
package leak
|
||||
|
||||
// NewEntry returns a new *Entry instance initialized with a *Object of the
|
||||
// given input JSON data.
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package obj
|
||||
package leak
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
10
test/leak.rb
10
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__))
|
||||
|
||||
Reference in New Issue
Block a user