Profile only one thread with corresponding gpu tasks among multithreads

FizzHerbert: <p>I am trying to build a server which process streaming input.<br>
I should load model weight once and handle multiple inputs in separate threads.<br>
Now I want to profile only one thread that handle with just one query with the profiler kineto.<br>
However, my test shows that profiler kineto will record the events of all threads. Is there any chance to make the profiler kineto thread local just like profile legacy?<br>
Downside is the test code:</p>
<pre><code>TEST_F(ProfilerTest, testMultiThreads) {

  torch::inductor::AOTIModelPackageLoader loader("xxxx.pt2");
  torch::inductor::AOTIModelContainerRunner* runner = loader.get_runner();

  auto inference_worker_with_profiler = [&amp;runner]() {
      torch::profiler::impl::ProfilerConfig config_ = torch::profiler::impl::ProfilerConfig(torch::profiler::impl::ProfilerState::KINETO);
      std::set&lt;torch::profiler::impl::ActivityType&gt; activities_{torch::profiler::impl::ActivityType::CUDA, torch::profiler::impl::ActivityType::CPU};
      torch::autograd::profiler::prepareProfiler(config_, activities_);
      torch::autograd::profiler::enableProfiler(config_, activities_);
      std::vector&lt;torch::Tensor&gt; inputs = {torch::rand({300, 1024}, torch::kFloat32).to(torch::kCUDA)};
      std::vector&lt;torch::Tensor&gt; outputs = runner-&gt;run(inputs);
      std::unique_ptr&lt;torch::autograd::profiler::ProfilerResult&gt; res = torch::autograd::profiler::disableProfiler();
      std::string file_name = "xxx.json";
      res-&gt;save(file_name);
  };

  auto inference_worker_without_profiler = [&amp;runner]() {
      std::vector&lt;torch::Tensor&gt; inputs = {torch::rand({300, 1024}, torch::kFloat32).to(torch::kCUDA)};
      std::vector&lt;torch::Tensor&gt; outputs = runner-&gt;run(inputs);
  };

  std::thread thread_a(inference_worker_with_profiler);
  std::thread thread_b(inference_worker_without_profiler);
  std::thread thread_c(inference_worker_without_profiler);
  std::thread thread_d(inference_worker_without_profiler);
  std::thread thread_e(inference_worker_without_profiler);

  thread_a.join();
  thread_b.join();
  thread_c.join();
  thread_d.join();
  thread_e.join();
}
</code></pre>
<p>The profile result is similar as bellow:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/1/d142200e8753eae615fb592a61b54d3403c52641.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/d142200e8753eae615fb592a61b54d3403c52641" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d142200e8753eae615fb592a61b54d3403c52641_2_690x247.jpeg" alt="image" data-base62-sha1="tRbsLsak0MJZPUvIctJ4LMw6odH" width="690" height="247" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d142200e8753eae615fb592a61b54d3403c52641_2_690x247.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d142200e8753eae615fb592a61b54d3403c52641_2_1035x370.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/1/d142200e8753eae615fb592a61b54d3403c52641_2_1380x494.jpeg 2x" data-dominant-color="ECEBED"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1920×688 80.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>