Open yuand2022 opened 1 year ago
import threading import time import pyflamegraph
def calculate_factorial(n): if n == 0: return 1 else: return n * calculate_factorial(n - 1)
def worker(thread_id): for i in range(1, 5000): calculate_factorial(20)
def main():
with pyflamegraph.FlamegraphProfiler(output_file='flamegraph.svg'):
threads = []
for i in range(4): # Create 4 threads
thread = threading.Thread(target=worker, args=(i,))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
if name == 'main': main()
The command pipeline is as follows: perf record -g ./app perf script > app.perf cat app.perf | ./stackcollapse-perf.pl --all | ./flamegraph.pl > app.svg
My application is a multi-threaded application and the execution time is about 20 minutes. When I finished executing the above pipeline, I got an unexpected svg image, the flame graph does not truly reflect the actual situation。
ReadAlignChunk::mapChunk is a thread execution function, which should be a hotspot, and BarcodeMap::BarcodeMapping is a sub-function of a thread thread function, which should be a secondary hotspot. Another problem is that the call stack is too shallow, with less than 10 layers, far below expectations.