3 ms·
Could you please share a really high level psuedo code example of what kind of data a sample-based profiler collects/how it does it?
by MuffinFlavored 9y ago
Could you please share a really high level psuedo code example of what kind of data a sample-based profiler collects/how it does it?
- bgirard 9y agonew Thread('sampler') { run() { while (true) { samples.add(Thread.getAllStackTraces()); Thread.sleep(1ms); } } }.start(); Then you export all the stacks to a visualizer. The real java version of this is actually usable to find quick problems but will be inferior to real profilers because the 'getAllStackTraces' API wasn't designed for this. For C/C++ program you can use signals to implement the above. That's how the Firefox profiler works.
- amorphid 9y agoIn Ruby, check out https://apidock.com/ruby/Kernel/set_trace_func https://apidock.com/ruby/Kernel/set_trace_func. I believe Python has something similar, too.
- ekimekim 9y agoI'm referring to a sampling profiler - as mentioned in the article, these generally work on a timer (either a thread with a loop, or a recurring signal), not by a per-function callback.