Skip to content

Commit

Permalink
feat: add missing mem usage functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabri3l committed Jun 12, 2024
1 parent 22e8d7c commit 4786200
Show file tree
Hide file tree
Showing 2 changed files with 359 additions and 7 deletions.
102 changes: 99 additions & 3 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,22 @@ func (f *funcObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
}
ctx.VisitObj(f)

memUsage, err = f.baseObject.MemUsage(ctx)
return f.baseJsFuncObject.MemUsage(ctx)
}

func (b *baseJsFuncObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) {
if b == nil || ctx.IsObjVisited(b) {
return SizeEmptyStruct, nil
}
ctx.VisitObj(b)

memUsage, err = b.baseFuncObject.MemUsage(ctx)
if err != nil {
return memUsage, err
}

if f.stash != nil {
inc, err := f.stash.MemUsage(ctx)
if b.stash != nil {
inc, err := b.stash.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
Expand All @@ -520,3 +529,90 @@ func (f *funcObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)

return memUsage, nil
}

func (c *classFuncObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) {
if c == nil || ctx.IsObjVisited(c) {
return SizeEmptyStruct, nil
}
ctx.VisitObj(c)

memUsage, err = c.baseJsFuncObject.MemUsage(ctx)
if err != nil {
return memUsage, err
}

if c.initFields != nil {
inc, err := c.initFields.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
}

for _, v := range c.computedKeys {
inc, err := v.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
}

for _, v := range c.privateMethods {
inc, err := v.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
}

return memUsage, err
}

func (m *methodFuncObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) {
if m == nil || ctx.IsObjVisited(m) {
return SizeEmptyStruct, nil
}
ctx.VisitObj(m)

memUsage, err = m.baseJsFuncObject.MemUsage(ctx)
if err != nil {
return memUsage, err
}

inc, err := m.homeObject.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}

return memUsage, err
}

func (a *arrowFuncObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) {
if a == nil || ctx.IsObjVisited(a) {
return SizeEmptyStruct, nil
}
ctx.VisitObj(a)

memUsage, err = a.baseJsFuncObject.MemUsage(ctx)
if err != nil {
return memUsage, err
}

inc, err := a.funcObj.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}

if a.newTarget != nil {
inc, err = a.newTarget.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}

}

return memUsage, err
}
Loading

0 comments on commit 4786200

Please sign in to comment.