<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57985>57985</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            OpenMP offload built-in profiler doesn't produce data for multiple threads
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          markdewing
      </td>
    </tr>
</table>

<pre>
    The built-in profiler (described here: https://openmp.llvm.org/design/Runtimes.html#libomptarget-profile) only produces trace information for a single thread from the calling application.

The implementation uses LLVM's TimeTraceProfiler: 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/TimeProfiler.h

According to the docs, each thread needs to call `timeTraceProfilerInitialize` and `timeTraceProfilerFinishThread` (for threads other than the main thread).

The difficulty with the the finish thread call is the library doesn't know when the application threads will be done.

One possible prototype solution:
1. In each TIMESCOPE macro, check if the profiler is initialized on that thread.
2. If not, call `timeTraceProfilerInitialize`.  Get the newly created instance and save it on a list.
3. At shutdown, just before `timeTraceProfilerWriter` is called, run through the list (from 2) and call a modified version of `timeTraceProfilerFinishThread` that accepts a `timeTraceProfiler` argument.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE1v2zgQ_TXSZVBBpj8UH3TI9gsBGiTYGt0zRY4sNhQpkKMY7q_fIa047TaHLmBblEnOe_PezHRen9vDgNDNxtI742AKvjcWAxTiRmNUwXSoYcCAxfoWBqIp8qIQn_jjJ3TjVFn7PFY-HPkfvmGOjhd_z47MiLEaaLSFWFvT-XEiGY5I7xaMQuzBO3tOmHpWGIGCVAjG9T6Mkox3wCuQEI07WgQaAkoNffAjrxGUtJZ3QE6TNSpfqIr6Q1HfXn5TYmacLI7o6BJvjgzz5cu3-0I0EQ5M8ZAwH5esU46Xu79mejQ0zF2l_MgvKd_lkVL5jor4tbO-48cojXs9Y5yys8bXP77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