1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-12 23:50:13 +02:00

pseudo code

This commit is contained in:
Felix Geisendörfer
2021-05-24 11:51:13 +02:00
parent ca63f541c3
commit 350a4ab46c
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,17 @@
func chansend(channel, msg):
// non-blocking send
if ready(channel):
send(channel, msg)
return
t0 = now()
// let scheduler run another goroutine
// until the channel is ready
wait_ready(channel)
duration = now() - t0
send(channel, msg)
// sample a fraction of blocking events
if random_sample(duration):
s = stacktrace()
profile[s].count++
profile[s].duration += duration

View File

@ -0,0 +1,20 @@
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