Profiler generate invalid separator path inside JSON using tensorboard_trace_handler

Mole_m7b5: <p>I’m trying to use <code>torch.profiler.profile()</code> to investigate potential bottlenecks in my pipeline. When trying to generate a JSON file either with <code>tensorboard_trace_handler()</code> or with <code>profile.export_chrome_trace()</code> the subsequent JSON file, when being read by either tensorboard or Chrome trace viewer results in an stating <code>json.decoder.JSONDecodeError: Invalid \escape: line 1748355 column 56 (char 160536060)</code></p>
<p>I know this error means there is a <code>\</code> rather than a <code>\\</code> or <code>/</code> - is this a known issue?</p>

arogozhnikov: <p>seemingly issue is old, and was patched</p><aside class="onebox githubissue" data-onebox-src="https://github.com/pytorch/pytorch/issues/60187">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/issues/60187" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/60187" target="_blank" rel="noopener nofollow ugc">Pytorch 1.9 Profiler generate invalid separator path inside JSON using tensorboard_trace_handler.</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-06-17" data-time="17:54:02" data-timezone="UTC">05:54PM - 17 Jun 21 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2021-06-30" data-time="22:33:20" data-timezone="UTC">10:33PM - 30 Jun 21 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/BurguerJohn" target="_blank" rel="noopener nofollow ugc">
          <img alt="BurguerJohn" src="https://avatars.githubusercontent.com/u/32472975?v=4" class="onebox-avatar-inline" width="20" height="20">
          BurguerJohn
        </a>
      </div>
    </div>

    <div class="labels">
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          high priority
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          module: windows
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          triaged
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          oncall: profiler
        </span>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">## 🐛 Bug

On windows, tensorboard_trace_handler use the separador \  in the fi<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">le path instead of / or \\\ breaking the json file.


## To Reproduce

Steps to reproduce the behavior:

1. Setup the Profiler. Example:
`with torch.profiler.profile(
    activities=[
        torch.profiler.ProfilerActivity.CPU,
        torch.profiler.ProfilerActivity.CUDA],
    schedule=torch.profiler.schedule(
        wait=2,
        warmup=3,
        active=6),
    on_trace_ready=torch.profiler.tensorboard_trace_handler('./result', worker_name='worker0'),
    record_shapes=True,
    profile_memory=True,
    with_stack=True
  ) as p:`

2. Use Kineto to try to profile the file `tensorboard --logdir=./result`
3. It throw the error on windows: `json.decoder.JSONDecodeError: Invalid \escape: line 12 column 64 (char 371)`


## Expected behavior

To escape the separator correctly on the json file. Ex: \\\

## Environment

```
PyTorch version: 1.9.0+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Home Single Language
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.9 (64-bit runtime)
Python platform: Windows-10-10.0.19041-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.20.3
[pip3] pytorch-lightning==1.3.5
[pip3] torch==1.9.0+cu111
[pip3] torch-tb-profiler==0.2.0
[pip3] torchaudio==0.9.0
[pip3] torchmetrics==0.3.2
[pip3] torchvision==0.10.0+cu111
[conda] Could not collect
```



cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @ilia-cher @gdankel @ngimel @nbcsm @guotuofeng @guyang3532 @gaoteng-git @peterjc123 @mszhanyi @skyline75489</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>but I get this error again in 2.2</p>