diff --git a/examples/pseudo-code/pseudo-block.txt b/examples/pseudo-code/pseudo-block.txt new file mode 100644 index 0000000..0e4f572 --- /dev/null +++ b/examples/pseudo-code/pseudo-block.txt @@ -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 diff --git a/examples/pseudo-code/pseudo-heap.txt b/examples/pseudo-code/pseudo-heap.txt new file mode 100644 index 0000000..0663edf --- /dev/null +++ b/examples/pseudo-code/pseudo-heap.txt @@ -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