Skip to content

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

@dsharlet

Description

@dsharlet
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions