Skip to content

Commit

Permalink
Allow clients to specify whether they want the heap
Browse files Browse the repository at this point in the history
typed or not.
  • Loading branch information
randall77 committed Oct 2, 2017
1 parent 5e17bfc commit 92c5ec8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions gocore/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (p *Program) Size(x Object) int64 {

// Type returns the type and repeat count for the object x.
// x contains at least repeat copies of the returned type.
// FlagTypes must have been passed to Core when p was constructed.
func (p *Program) Type(x Object) (*Type, int64) {
i, _ := p.findObjectIndex(core.Address(x))
return p.types[i].Type, p.types[i].Repeat
Expand Down
7 changes: 5 additions & 2 deletions gocore/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

// Core takes a loaded core file and extracts Go information from it.
func Core(proc *core.Process) (p *Program, err error) {
// flags is a bitmask of data that should be extracted from the core.
func Core(proc *core.Process, flags Flags) (p *Program, err error) {
// Make sure we have DWARF info.
if _, err := proc.DWARF(); err != nil {
return nil, err
Expand Down Expand Up @@ -58,7 +59,9 @@ func Core(proc *core.Process) (p *Program, err error) {
p.readGs()
p.readStackVars()
p.readObjects()
p.typeHeap()
if flags&FlagTypes != 0 {
p.typeHeap()
}

return p, nil
}
Expand Down
9 changes: 8 additions & 1 deletion gocore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"github.com/randall77/corelib/core"
)

type Flags uint8

const (
FlagTypes Flags = 1 << iota
)

type Program struct {
proc *core.Process

Expand Down Expand Up @@ -48,7 +54,8 @@ type Program struct {

globals []*Root

// Information about objects, indexed by Object
// Types of each object, indexed by object index.
// Only initialized if FlagTypes is passed to Core.
types []typeInfo
}

Expand Down
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ func main() {
defer pprof.StopCPUProfile()
}

var flags gocore.Flags
switch cmd {
default:
fmt.Fprintf(os.Stderr, "%s: unknown command %s\n", os.Args[0], cmd)
fmt.Fprintf(os.Stderr, "Run 'corelib help' for usage.\n")
os.Exit(2)
case "overview":
case "mappings":
case "goroutines":
case "histogram":
flags = gocore.FlagTypes
case "breakdown":
case "objgraph":
flags = gocore.FlagTypes
case "objects":
flags = gocore.FlagTypes
case "reachable":
flags = gocore.FlagTypes
case "html":
flags = gocore.FlagTypes
}

// All commands other than "help" need a core file.
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "%s: no core dump specified for command %s\n", os.Args[0], cmd)
Expand All @@ -75,7 +97,7 @@ func main() {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
c, err := gocore.Core(p)
c, err := gocore.Core(p, flags)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand Down

0 comments on commit 92c5ec8

Please sign in to comment.