proc

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

mapping to structs in `runtime` package

Link to unexported runtime.nanotime() copy from https://github.com/gavv/monotime/blob/master/monotime.go

Index

Constants

View Source
const (
	HEAP_BASE = 0xC000000000 // go runtime allocate heap starts at 0x00c000000000, ignore ASLR https://github.com/golang/go/issues/27583
)
View Source
const POINTER_SIZE = 8

amd64 pointer size

Variables

This section is empty.

Functions

This section is empty.

Types

type G

type G struct {
	Stack        stack          `name:"stack" binStrt:"runtime.stack"`
	ID           uint64         `name:"goid"`         // goid
	Status       gstatus        `name:"atomicstatus"` // atomicstatus
	WaitReason   gwaitReason    `name:"waitreason"`   // if Status ==Gwaiting
	Sched        Gobuf          `name:"sched" binStrt:"runtime.gobuf"`
	Startpc      uint64         `name:"startpc"`
	Gopc         uint64         `name:"gopc"`
	M            *M             `name:"m" binStrt:"runtime.m"` // hold worker thread info
	WaitingSudog *Sudog         `name:"waiting" binStrt:"runtime.sudog"`
	CurLoc       *gbin.Location // runtime location
	UserLoc      *gbin.Location // location of user code, a subset of CurLoc
	GoLoc        *gbin.Location // location of `go` statement that spawed this goroutine
	StartLoc     *gbin.Location // location of goroutine start function
	// contains filtered or unexported fields
}

G is runtime.g struct parsed from process memory and binary dwarf

func (*G) Addr

func (c *G) Addr() uint64

func (*G) BinStrt

func (c *G) BinStrt() *gbin.Strt

func (*G) Dead

func (g *G) Dead() bool

func (*G) GetLocation

func (g *G) GetLocation(pcType string) *gbin.Location

func (*G) GetWaitReason

func (g *G) GetWaitReason() (string, error)

func (*G) GetWaitingChan

func (g *G) GetWaitingChan() (string, error)

func (*G) Idle

func (g *G) Idle() bool

func (*G) Init

func (c *G) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*G) Parse

func (g *G) Parse(addr uint64) error

func (*G) ParsePtrSlice

func (g *G) ParsePtrSlice(addr uint64) ([]*G, error)

func (*G) Process

func (c *G) Process() *Process

func (*G) Running

func (g *G) Running() bool

func (*G) StackSize

func (g *G) StackSize() uint64

func (*G) Summary

func (g *G) Summary(pcType string) (*GSummary, error)

func (*G) Syscall

func (g *G) Syscall() bool

func (*G) ThreadID

func (g *G) ThreadID() uint64

func (*G) Waiting

func (g *G) Waiting() bool

type GSummary

type GSummary struct {
	ID         string
	Status     string
	WaitReason string
	Loc        string
}

type GoStructer

type GoStructer interface {
	Init(p *Process, binStrt *gbin.Strt, addr uint64)
	Parse(addr uint64) error
	BinStrt() *gbin.Strt
	Process() *Process
}

type Gobuf

type Gobuf struct {
	SP uint64 `name:"sp"`
	PC uint64 `name:"pc"`
	// contains filtered or unexported fields
}

func (*Gobuf) Addr

func (c *Gobuf) Addr() uint64

func (*Gobuf) BinStrt

func (c *Gobuf) BinStrt() *gbin.Strt

func (*Gobuf) Init

func (c *Gobuf) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*Gobuf) Parse

func (b *Gobuf) Parse(addr uint64) error

func (*Gobuf) Process

func (c *Gobuf) Process() *Process

type HChan

type HChan struct {
	QCount    uint   `name:"qcount"`
	DataqSize uint   `name:"dataqsiz"`
	ElemSize  uint16 `name:"elemsize"`
	ElemType  *Type  `name:"elemtype" binStrt:"internal/abi.Type"`
	Closed    uint32 `name:"closed"`
	Sendx     uint   `name:"sendx"`
	Recvx     uint   `name:"recvx"`
	// contains filtered or unexported fields
}

HChan is runtime.hchan, result of make(chan xx)

func (*HChan) Addr

func (c *HChan) Addr() uint64

func (*HChan) BinStrt

func (c *HChan) BinStrt() *gbin.Strt

func (*HChan) Init

func (c *HChan) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*HChan) Parse

func (h *HChan) Parse(addr uint64) error

func (*HChan) Process

func (c *HChan) Process() *Process

func (*HChan) String

func (h *HChan) String() string

type M

type M struct {
	ID     uint64 `name:"id"`
	ProcID uint64 `name:"procid"`
	// contains filtered or unexported fields
}

M is runtime.m struct

func (*M) Addr

func (c *M) Addr() uint64

func (*M) BinStrt

func (c *M) BinStrt() *gbin.Strt

func (*M) Init

func (c *M) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*M) Parse

func (m *M) Parse(addr uint64) error

func (*M) Process

func (c *M) Process() *Process

type MCache

type MCache struct {
	TinyOffset  uint64 `name:"tinyoffset"`
	NTinyallocs uint64 `name:"local_tinyallocs"`

	Alloc [numSpanClasses]*MSpan `name:"alloc" binStrt:"runtime.mspan"`

	LargeFree  uint64 `name:"local_largefree"`  // bytes freed for large objects (>maxsmallsize)
	NLargeFree uint64 `name:"local_nlargefree"` // number of frees for large objects (>maxsmallsize)
	FlushGen   uint32 `name:"flushGen"`         // added on 1.12
	// contains filtered or unexported fields
}

func (*MCache) Addr

func (c *MCache) Addr() uint64

func (*MCache) BinStrt

func (c *MCache) BinStrt() *gbin.Strt

func (*MCache) Init

func (c *MCache) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*MCache) Parse

func (c *MCache) Parse(addr uint64) error

func (*MCache) Process

func (c *MCache) Process() *Process

func (*MCache) SmallSizeObjectSummary

func (c *MCache) SmallSizeObjectSummary() []smallsize

type MCentral

type MCentral struct {
	SpanClass spanClass `name:"spanclass"`
	NMalloc   uint64    `name:"nmalloc"`
	// contains filtered or unexported fields
}

func (*MCentral) Addr

func (c *MCentral) Addr() uint64

func (*MCentral) BinStrt

func (c *MCentral) BinStrt() *gbin.Strt

func (*MCentral) Init

func (c *MCentral) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*MCentral) Parse

func (c *MCentral) Parse(addr uint64) error

func (*MCentral) Process

func (c *MCentral) Process() *Process

type MHeap

type MHeap struct {
	Sweepgen    uint32   `name:"sweepgen"`  // used to compare with mspan.sweepgen
	SweepDone   uint32   `name:"sweepdone"` //all spans are swept
	Sweepers    uint32   `name:"sweepers"`  // number of active sweepone calls
	MSpans      []*MSpan `name:"allspans" binStrt:"runtime.mspan"`
	PagesInUse  uint64   `name:"pagesInUse"`  // pages of spans in stats mSpanInUse
	PagesSwept  uint64   `name:"pagesSwept"`  // pages swept this cycle
	LargeAlloc  uint64   `name:"largealloc"`  // bytes allocated for large objects
	NLargeAlloc uint64   `name:"nlargealloc"` // number of large object allocations
	Largefree   uint64   `name:"largefree"`   // bytes freed for large objects (>maxsmallsize)
	NLargefree  uint64   `name:"nlargefree"`  // number of frees for large objects (>maxsmallsize)
	Central     []*MCentral
	// contains filtered or unexported fields
}

MHeap hold process heap info (runtime/mheap.go:mheap)

func (*MHeap) Addr

func (c *MHeap) Addr() uint64

func (*MHeap) BinStrt

func (c *MHeap) BinStrt() *gbin.Strt

func (*MHeap) Init

func (c *MHeap) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*MHeap) Parse

func (h *MHeap) Parse(addr uint64) error

func (*MHeap) Process

func (c *MHeap) Process() *Process

type MSpan

type MSpan struct {
	StartAddr  uint64     `name:"startAddr"`
	Npages     uint64     `name:"npages"`
	SpanClass  spanClass  `name:"spanclass"`
	Sweepgen   uint32     `name:"sweepgen"`
	AllocCount uint16     `name:"allocCount"`
	ElemSize   uint8      `name:"elemsize"`
	State      mspanstate `name:"state"`
	// contains filtered or unexported fields
}

func (*MSpan) Active

func (s *MSpan) Active() bool

func (*MSpan) Addr

func (c *MSpan) Addr() uint64

func (*MSpan) BinStrt

func (c *MSpan) BinStrt() *gbin.Strt

func (*MSpan) Init

func (c *MSpan) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*MSpan) Parse

func (s *MSpan) Parse(addr uint64) error

func (*MSpan) Process

func (c *MSpan) Process() *Process

type MemStat

type MemStat struct {
	HeapInuse   uint64 `name:"heap_inuse"`   // bytes allocated and not yet freed
	HeapObjects uint64 `name:"heap_objects"` // total number of allocated objects
	HeapSys     uint64 `name:"heap_sys"`     // virtual address space obtained from system for GC'd heap
	HeapLive    uint64 `name:"heap_live"`    // HeapAlloc - (objects not sweeped)

	Nmalloc uint64 `name:"nmalloc"` // number of mallocs
	Nfree   uint64 `name:"nfree"`   // number of frees

	// gc related
	PauseTotalNs  uint64  `name:"pause_total_ns"`
	NumGC         uint32  `name:"numgc"`
	NumForcedGC   uint32  `name:"numforcedgc"`     // number of user-forced GCs
	LastGC        uint64  `name:"last_gc_unix"`    // last gc (in unix time)
	GCCPUFraction float64 `name:"gc_cpu_fraction"` // fraction of CPU time used by GC
	// contains filtered or unexported fields
}

MemStat hold memory usage and gc info (runtime/mstat.go)

func (*MemStat) Addr

func (c *MemStat) Addr() uint64

func (*MemStat) BinStrt

func (c *MemStat) BinStrt() *gbin.Strt

func (*MemStat) Init

func (c *MemStat) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*MemStat) Parse

func (m *MemStat) Parse(addr uint64) error

func (*MemStat) Process

func (c *MemStat) Process() *Process

type P

type P struct {
	ID          int32   `name:"id"`
	Status      pstatus `name:"status"`
	Schedtick   uint32  `name:"schedtick"`
	Syscalltick uint32  `name:"syscalltick"`
	M           *M      `name:"m" binStrt:"runtime.m"`
	MCache      *MCache `name:"mcache" binStrt:"runtime.mcache"`
	Runq        []byte  `name:"runq"`
	Runqsize    int
	// contains filtered or unexported fields
}

P (processor) is runtime.p struct

func (*P) Addr

func (c *P) Addr() uint64

func (*P) BinStrt

func (c *P) BinStrt() *gbin.Strt

func (*P) Dead

func (p *P) Dead() bool

func (*P) Gcstop

func (p *P) Gcstop() bool

func (*P) Idle

func (p *P) Idle() bool

func (*P) Init

func (c *P) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*P) Parse

func (p *P) Parse(addr uint64) error

func (*P) ParsePtrSlice

func (p *P) ParsePtrSlice(addr uint64) ([]*P, error)

func (*P) Process

func (c *P) Process() *Process

func (*P) Running

func (p *P) Running() bool

func (*P) Syscall

func (p *P) Syscall() bool

type PSummary

type PSummary struct {
	BinPath         string
	RuntimeInitTime int64
	Gs              []*G
	Ps              []*P
	Sched           *Sched
	MemStat         *MemStat
	ThreadsTotal    int
	ThreadsSleeping int
	ThreadsStopped  int
	ThreadsRunning  int
	ThreadsZombie   int
	GTotal          int
	GIdle           int
	GRunning        int
	GSyscall        int
	GWaiting        int
	GoVersion       string
	Gomaxprocs      int
}

PSummary holds process summary info

func (*PSummary) LastGC

func (s *PSummary) LastGC() time.Duration

func (PSummary) String

func (s PSummary) String() string

func (*PSummary) TotalPauseTime

func (s *PSummary) TotalPauseTime() time.Duration

func (*PSummary) Uptime

func (s *PSummary) Uptime() time.Duration

type Process

type Process struct {
	ID int
	// contains filtered or unexported fields
}

Process wrap operations on target process

func New

func New(pid int, bin string) (*Process, error)

New a Process struct for target pid

func (*Process) Attach

func (p *Process) Attach() error

Attach will attach to all threads

func (*Process) Detach

func (p *Process) Detach() error

func (*Process) DumpHeap

func (p *Process) DumpHeap(lock bool) error

func (*Process) DumpHeapObjs

func (p *Process) DumpHeapObjs(lock bool) error

func (*Process) DumpVar

func (p *Process) DumpVar(name string, lock bool) error

func (*Process) GetGs

func (p *Process) GetGs(lock bool) ([]*G, error)

GetGs return goroutines

func (*Process) GetPs

func (p *Process) GetPs(lock bool) ([]*P, error)

GetPs return P's in runtime.allp

func (*Process) GetThread

func (p *Process) GetThread(id int) (t *Thread, ok bool)

GetThread will return target thread on id

func (*Process) GoVersion

func (p *Process) GoVersion() (string, error)

func (*Process) Gomaxprocs

func (p *Process) Gomaxprocs() (int, error)

func (*Process) MemStat

func (p *Process) MemStat() (*MemStat, error)

func (*Process) ReadData

func (p *Process) ReadData(data []byte, addr uint64) error

func (*Process) ReadVMA

func (p *Process) ReadVMA(addr uint64) (uint64, error)

ReadVM will read virtual memory at addr TODO handle PIE?

func (*Process) RuntimeInitTime

func (p *Process) RuntimeInitTime() (int64, error)

func (*Process) SchedInfo

func (p *Process) SchedInfo() (*Sched, error)

func (*Process) Summary

func (p *Process) Summary(lock bool) (*PSummary, error)

Summary process info

type Sched

type Sched struct {
	Nmidle     int32  `name:"nmidle"` // number of idle m's waiting for work
	Nmspinning uint32 `name:"nmspinning"`
	Nmfreed    uint64 `name:"nmfreed"`  // cumulative number of freed m's
	Npidle     int32  `name:"npidle"`   // number of idle p's
	Ngsys      uint32 `name:"ngsys"`    // number of system goroutines
	Runqsize   int32  `name:"runqsize"` // global runnable queue size
	// contains filtered or unexported fields
}

Sched is the global goroutine scheduler

func (*Sched) Addr

func (c *Sched) Addr() uint64

func (*Sched) BinStrt

func (c *Sched) BinStrt() *gbin.Strt

func (*Sched) Init

func (c *Sched) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*Sched) Parse

func (s *Sched) Parse(addr uint64) error

func (*Sched) Process

func (c *Sched) Process() *Process

type Sudog

type Sudog struct {
	IsSelect    bool   `name:"isSelect"`
	Ticket      uint32 `name:"ticket"`
	AcquireTime int64  `name:"acquiretime"`
	ReleaseTime int64  `name:"releasetime"`
	C           *HChan `name:"c" binStrt:"runtime.hchan"`
	// contains filtered or unexported fields
}

Sudog is runtime.sudog, when a g entering waiting state, it's attached on sudog

func (*Sudog) Addr

func (c *Sudog) Addr() uint64

func (*Sudog) BinStrt

func (c *Sudog) BinStrt() *gbin.Strt

func (*Sudog) Init

func (c *Sudog) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*Sudog) Parse

func (s *Sudog) Parse(addr uint64) error

func (*Sudog) Process

func (c *Sudog) Process() *Process

type Thread

type Thread struct {
	ID int
	// contains filtered or unexported fields
}

Thread wrap operations on a system thread

func NewThread

func NewThread(tid int, proc *Process) (*Thread, error)

func (*Thread) Attach

func (t *Thread) Attach() error

func (*Thread) Detach

func (t *Thread) Detach() error

func (*Thread) Registers

func (t *Thread) Registers() (*syscall.PtraceRegs, error)

Registers will return thread register address via syscall PTRACE_GETREGS

func (*Thread) Running

func (t *Thread) Running() bool

func (*Thread) Sleeping

func (t *Thread) Sleeping() bool

func (*Thread) State

func (t *Thread) State() string

func (*Thread) Stopped

func (t *Thread) Stopped() bool

func (*Thread) Zombie

func (t *Thread) Zombie() bool

type Type

type Type struct {
	Kind uint8 `name:"kind"`
	Str  int32 `name:"str"`
	// contains filtered or unexported fields
}

runtime._type

func (*Type) Addr

func (c *Type) Addr() uint64

func (*Type) BinStrt

func (c *Type) BinStrt() *gbin.Strt

func (*Type) Init

func (c *Type) Init(p *Process, binStrt *gbin.Strt, addr uint64)

func (*Type) Parse

func (c *Type) Parse(addr uint64) error

func (*Type) Process

func (c *Type) Process() *Process

func (*Type) String

func (c *Type) String() string

Jump to

Keyboard shortcuts

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