mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2026-06-21 00:46:51 +08:00
pseudo code
This commit is contained in:
parent
ca63f541c3
commit
350a4ab46c
2 changed files with 37 additions and 0 deletions
17
examples/pseudo-code/pseudo-block.txt
Normal file
17
examples/pseudo-code/pseudo-block.txt
Normal 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
|
||||
20
examples/pseudo-code/pseudo-heap.txt
Normal file
20
examples/pseudo-code/pseudo-heap.txt
Normal 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
|
||||
Loading…
Reference in a new issue