mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2026-06-21 00:46:51 +08:00
20 lines
405 B
Text
20 lines
405 B
Text
func malloc(size):
|
|
object = ... // alloc magic
|
|
|
|
if random_sample():
|
|
s = stacktrace()
|
|
profile[s].allocs++
|
|
profile[s].alloc_bytes += sizeof(object)
|
|
track_profiled(object, s)
|
|
|
|
return object
|
|
|
|
func sweep(object):
|
|
// do gc stuff to free object
|
|
|
|
if is_profiled(object)
|
|
s = alloc_stacktrace(object)
|
|
profile[s].frees++
|
|
profile[s].free_bytes += sizeof(object)
|
|
|
|
return object
|