@@ -221,16 +221,16 @@ type mallocProfiler struct {
221221 stack stackTrace
222222}
223223
224- func (p * mallocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) context. Context {
224+ func (p * mallocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) {
225225 p .size = api .DecodeU32 (params [0 ])
226226 p .stack = makeStackTrace (p .stack , si )
227- return ctx
228227}
229228
230- func (p * mallocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , err error , results []uint64 ) {
231- if err == nil {
232- p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .size , p .stack )
233- }
229+ func (p * mallocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , results []uint64 ) {
230+ p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .size , p .stack )
231+ }
232+
233+ func (p * mallocProfiler ) Abort (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ error ) {
234234}
235235
236236type callocProfiler struct {
@@ -240,17 +240,17 @@ type callocProfiler struct {
240240 stack stackTrace
241241}
242242
243- func (p * callocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) context. Context {
243+ func (p * callocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) {
244244 p .count = api .DecodeU32 (params [0 ])
245245 p .size = api .DecodeU32 (params [1 ])
246246 p .stack = makeStackTrace (p .stack , si )
247- return ctx
248247}
249248
250- func (p * callocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , err error , results []uint64 ) {
251- if err == nil {
252- p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .count * p .size , p .stack )
253- }
249+ func (p * callocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , results []uint64 ) {
250+ p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .count * p .size , p .stack )
251+ }
252+
253+ func (p * callocProfiler ) Abort (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ error ) {
254254}
255255
256256type reallocProfiler struct {
@@ -260,34 +260,35 @@ type reallocProfiler struct {
260260 stack stackTrace
261261}
262262
263- func (p * reallocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) context. Context {
263+ func (p * reallocProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) {
264264 p .addr = api .DecodeU32 (params [0 ])
265265 p .size = api .DecodeU32 (params [1 ])
266266 p .stack = makeStackTrace (p .stack , si )
267- return ctx
268267}
269268
270- func (p * reallocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , err error , results []uint64 ) {
271- if err == nil {
272- p .memory .observeFree (p .addr )
273- p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .size , p .stack )
274- }
269+ func (p * reallocProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , results []uint64 ) {
270+ p .memory .observeFree (p .addr )
271+ p .memory .observeAlloc (api .DecodeU32 (results [0 ]), p .size , p .stack )
272+ }
273+
274+ func (p * reallocProfiler ) Abort (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ error ) {
275275}
276276
277277type freeProfiler struct {
278278 memory * MemoryProfiler
279279 addr uint32
280280}
281281
282- func (p * freeProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) context. Context {
282+ func (p * freeProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) {
283283 p .addr = api .DecodeU32 (params [0 ])
284- return ctx
285284}
286285
287- func (p * freeProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , err error , results []uint64 ) {
288- if err == nil {
289- p .memory .observeFree (p .addr )
290- }
286+ func (p * freeProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ []uint64 ) {
287+ p .memory .observeFree (p .addr )
288+ }
289+
290+ func (p * freeProfiler ) Abort (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ error ) {
291+ p .After (ctx , mod , def , nil )
291292}
292293
293294type goRuntimeMallocgcProfiler struct {
@@ -296,7 +297,7 @@ type goRuntimeMallocgcProfiler struct {
296297 stack stackTrace
297298}
298299
299- func (p * goRuntimeMallocgcProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) context. Context {
300+ func (p * goRuntimeMallocgcProfiler ) Before (ctx context.Context , mod api.Module , def api.FunctionDefinition , params []uint64 , si experimental.StackIterator ) {
300301 imod := mod .(experimental.InternalModule )
301302 mem := imod .Memory ()
302303
@@ -309,13 +310,16 @@ func (p *goRuntimeMallocgcProfiler) Before(ctx context.Context, mod api.Module,
309310 } else {
310311 p .size = 0
311312 }
312- return ctx
313313}
314314
315- func (p * goRuntimeMallocgcProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , err error , results []uint64 ) {
316- if err == nil && p .size != 0 {
315+ func (p * goRuntimeMallocgcProfiler ) After (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ []uint64 ) {
316+ if p .size != 0 {
317317 // TODO: get the returned pointer
318318 addr := uint32 (0 )
319319 p .memory .observeAlloc (addr , p .size , p .stack )
320320 }
321321}
322+
323+ func (p * goRuntimeMallocgcProfiler ) Abort (ctx context.Context , mod api.Module , def api.FunctionDefinition , _ error ) {
324+ p .After (ctx , mod , def , nil )
325+ }
0 commit comments