Skip to content

Commit 92c5ec8

Browse files
committed
Allow clients to specify whether they want the heap
typed or not.
1 parent 5e17bfc commit 92c5ec8

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

gocore/object.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (p *Program) Size(x Object) int64 {
180180

181181
// Type returns the type and repeat count for the object x.
182182
// x contains at least repeat copies of the returned type.
183+
// FlagTypes must have been passed to Core when p was constructed.
183184
func (p *Program) Type(x Object) (*Type, int64) {
184185
i, _ := p.findObjectIndex(core.Address(x))
185186
return p.types[i].Type, p.types[i].Repeat

gocore/parse.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
)
1010

1111
// Core takes a loaded core file and extracts Go information from it.
12-
func Core(proc *core.Process) (p *Program, err error) {
12+
// flags is a bitmask of data that should be extracted from the core.
13+
func Core(proc *core.Process, flags Flags) (p *Program, err error) {
1314
// Make sure we have DWARF info.
1415
if _, err := proc.DWARF(); err != nil {
1516
return nil, err
@@ -58,7 +59,9 @@ func Core(proc *core.Process) (p *Program, err error) {
5859
p.readGs()
5960
p.readStackVars()
6061
p.readObjects()
61-
p.typeHeap()
62+
if flags&FlagTypes != 0 {
63+
p.typeHeap()
64+
}
6265

6366
return p, nil
6467
}

gocore/types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66
"github.com/randall77/corelib/core"
77
)
88

9+
type Flags uint8
10+
11+
const (
12+
FlagTypes Flags = 1 << iota
13+
)
14+
915
type Program struct {
1016
proc *core.Process
1117

@@ -48,7 +54,8 @@ type Program struct {
4854

4955
globals []*Root
5056

51-
// Information about objects, indexed by Object
57+
// Types of each object, indexed by object index.
58+
// Only initialized if FlagTypes is passed to Core.
5259
types []typeInfo
5360
}
5461

main.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ func main() {
6363
defer pprof.StopCPUProfile()
6464
}
6565

66+
var flags gocore.Flags
67+
switch cmd {
68+
default:
69+
fmt.Fprintf(os.Stderr, "%s: unknown command %s\n", os.Args[0], cmd)
70+
fmt.Fprintf(os.Stderr, "Run 'corelib help' for usage.\n")
71+
os.Exit(2)
72+
case "overview":
73+
case "mappings":
74+
case "goroutines":
75+
case "histogram":
76+
flags = gocore.FlagTypes
77+
case "breakdown":
78+
case "objgraph":
79+
flags = gocore.FlagTypes
80+
case "objects":
81+
flags = gocore.FlagTypes
82+
case "reachable":
83+
flags = gocore.FlagTypes
84+
case "html":
85+
flags = gocore.FlagTypes
86+
}
87+
6688
// All commands other than "help" need a core file.
6789
if len(args) < 2 {
6890
fmt.Fprintf(os.Stderr, "%s: no core dump specified for command %s\n", os.Args[0], cmd)
@@ -75,7 +97,7 @@ func main() {
7597
fmt.Fprintf(os.Stderr, "%v\n", err)
7698
os.Exit(1)
7799
}
78-
c, err := gocore.Core(p)
100+
c, err := gocore.Core(p, flags)
79101
if err != nil {
80102
fmt.Fprintf(os.Stderr, "%v\n", err)
81103
os.Exit(1)

0 commit comments

Comments
 (0)