Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flamegraph handles multi-thread program abnormality #296

Open
yuand2022 opened this issue Nov 17, 2022 · 1 comment
Open

Flamegraph handles multi-thread program abnormality #296

yuand2022 opened this issue Nov 17, 2022 · 1 comment

Comments

@yuand2022
Copy link

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。

out

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.

@yuand2022 yuand2022 changed the title Flamegraph handles multi -threaded program abnormality Flamegraph handles multi-thread program abnormality Nov 17, 2022
@HarrySidhuz0008
Copy link

import threading
import time
import pyflamegraph

Function to calculate factorial

def calculate_factorial(n):
if n == 0:
return 1
else:
return n * calculate_factorial(n - 1)

Function that simulates multi-threading

def worker(thread_id):
for i in range(1, 5000):
calculate_factorial(20)

def main():
# Start profiling
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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants