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

Broken when tracing and using perf at the same time #2

Open
dsharlet opened this issue Nov 18, 2024 · 0 comments
Open

Broken when tracing and using perf at the same time #2

dsharlet opened this issue Nov 18, 2024 · 0 comments

Comments

@dsharlet
Copy link
Owner

PTHREAD_TRACE_PATH=trace.proto LD_PRELOAD=pthread_trace.so perf record program

This racily produces garbage results because both perf and program run pthread tracing, writing to the same file. We could open with O_EXCL to detect and report an error in this case (better than silently producing garbage data), but the combination of flags we are using means that the file needs to be deleted first, which is annoying.

Some other possibilities:

  • If we could use a system-wide atomic to track which buffer to write next in the file, then this might actually work: you'd get pthread_trace data from both perf and program. It would probably require some better method of getting thread IDs.
  • I think pthread_trace would be better as an executable that accepts a program (and arguments) to run in a child process (like perf). Not sure how to do this with the LD_PRELOAD-like behavior.

Somehow the combination of perf and pthread_trace really impacts program performance, so this isn't something that people should do anyways. But when working on pthread_trace it is useful to be able to profile it.

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

1 participant