You've already forked go-profiler-notes
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:
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
|
Reference in New Issue
Block a user