46 ms·
new Thread('sampler') { run() { while (true) { samples.add(Thread.getAllStackTraces()); Thread.sleep(1ms); } } }.start();
by bgirard 9y ago
new 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.