rubyobj

package module
v0.0.0-...-00e9126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2014 License: MIT Imports: 10 Imported by: 1

README

rubyobj

Provides an encoder and a decoder for Ruby ObjectSpace heap dumps.

Docs

Godoc!

Usage

go get github.com/aybabtme/robjspace

Then in your Go code (this shows the slow decoder):

r := yourFavoriteReader() // say a file, or stdin

rubyObj := rubyobj.RubyObject{}
var err error

for dec := rubyobj.NewDecoder(r); err == nil; err = dec.Decode(&rubyObj) {
  fmt.Printf("%v\n", &rubyObj)
}

if err != io.EOF {
  perror(err)
}

Performance

Using the fast ParallelDecode (using NumCPU cores and goroutines, and fatherhood):

$ go run loadall.go parallel --filename ../testdata/huge.json
loading 549MB from 'huge.json'
2489364 heap objects in 4.699698607s

In comparison, the NewDecoder (using encoding/json):

$ go run loadall.go trivial --filename ../testdata/huge.json
loading 549MB from 'huge.json'
2489364 heap objects in 2m44.960795009s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParallelDecode

func ParallelDecode(r io.Reader, para uint) (<-chan RubyObject, <-chan error)

ParallelDecode will use many goroutines to decode io.Reader. io.Reader MUST present JSON objects seperated by \n characters.

Decoding will use para + 1 goroutines:

   1 x goroutines to read all the lines in the io.Reader
para x goroutines to decode the lines

The decoding will continue until it reaches EOF in the io.Reader, and return all the errors it encountered on the error channel, including Read errors, unmarshalling errors and loading errors.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes RubyObjects from an io.Reader. It wraps a json.Decoder and is pretty slow, but simple to use for those acustomed to the json.Decoder from the stdlib.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a trivial decoder wrapping a json.Decoder of the stdlib. It is pretty slow but simple to use.

For performance, prefer ParallelDecode.

func (*Decoder) Decode

func (d *Decoder) Decode(rObj *RubyObject) (err error)

Decode decodes a ruby object from the underlying io.Reader.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder encodes RubyObjects to an io.Writer. It wraps a json.Encoder and is pretty slow, but simple to use for those acustomed to the json.Encoder from the stdlib.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a trivial encoder wrapping a json.Encoder of the stdlib. It is pretty slow but simple to use.

func (*Encoder) Encode

func (e *Encoder) Encode(rObj *RubyObject) (err error)

Encode encodes the object onto the underlying io.Writer.

type RubyObject

type RubyObject struct {
	Type  RubyType
	Value interface{}
	Name  string

	NodeType string

	Address    uint64
	Class      uint64
	References []uint64

	Default    uint64
	Generation uint64

	Bytesize uint64

	Fd       int
	File     string
	Encoding string

	Method string

	Ivars    uint64
	Length   uint64
	Line     uint64
	Memsize  uint64
	Capacity uint64
	Size     uint64

	Struct string
	// contains filtered or unexported fields
}

RubyObject is the deserialized form of an object in an ObjectSpace dump.

func (RubyObject) Broken

func (ro RubyObject) Broken() bool

func (RubyObject) Embedded

func (ro RubyObject) Embedded() bool

func (RubyObject) Frozen

func (ro RubyObject) Frozen() bool

func (RubyObject) Fstring

func (ro RubyObject) Fstring() bool

func (RubyObject) GcMarked

func (ro RubyObject) GcMarked() bool

func (RubyObject) GcOld

func (ro RubyObject) GcOld() bool

func (RubyObject) GcWbProtected

func (ro RubyObject) GcWbProtected() bool

func (RubyObject) Shared

func (ro RubyObject) Shared() bool

type RubyType

type RubyType uint8

RubyType for RubyObjects

const (
	Array RubyType = iota
	Bignum
	Class
	Complex
	Data
	False
	File
	Fixnum
	Float
	Hash
	Iclass
	Match
	Module
	Nil
	Node
	None
	Object
	Rational
	Regexp
	Root
	String
	Struct
	Symbol
	True
	Undef
	Zombie
)

Possible types taken by a RubyObject.

func (RubyType) Name

func (rt RubyType) Name() string

Name is the string repesentation of this type in an ObjectSpace dump.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL