为什么在导入 speedscope 时跟踪 Linux 中的 C# 代码失败?

Why does tracing C# code in Linux fail when imported into speedscope?

背景:

我有一些代码 运行 非常慢,因此建议我分析代码以找出原因。

下图显示 Visual Studio 代码 运行 on Linux 我在下面使用了一些 dotnet 命令来创建 trace.nettracetrace.speedscope.json 文件:

然后我尝试将 trace.speedscope.json 文件导入 https://www.speedscope.app/,但出现以下错误:


命令:

我使用以下页面作为创建跟踪速度范围文件的指南:

https://github.com/jlfwong/speedscope/wiki/Importing-from-.NET-Core

具体来说,我使用的命令是:

dotnet trace collect -p <process id> --format speedscope


示例:

可在此处查看生成的 speedscope 跟踪文件示例:

https://pastebin.com/4WW2tbiF


问题:

如何创建与 https://www.speedscope.app/ 一起使用的 speedscope 跟踪文件?

您的命令(基于manual and screenshot:

$ dotnet tool install --global dotnet-trace
$ dotnet trace collect -p <process id> --format speedscope
No profile or providers specified, defaulting to trace profile 'cpu-sampling' 
Provider Name Level Enabled by 
Microsoft-DotNETCore-SampleProfiler Informational(4) --profile 
Microsoft-Windows-DotNETRuntime Informational(4) --profile 

Process: /Code/mysql-insert-1234/bin/Debug/netcoreapp3.1/mysql-insert-1234 
Output File: /Code/mysql-insert-1234/trace.nettrace

[00:00:00:02] Recording trace 2.0604 (MB) 

Press <Enter> or <Ctrl+C> to exit... Trace completed.
$ dotnet trace convert --format speedscope trace.nettrace 
Writing: /Code/mysql-insert-1234/trace.speedscope.json 
Conversion complete

来自 screenshot 的错误消息(从原始 json 文件中重现的类似错误):

speedscope v1.8.0  
Importing as speedscope json file 
Failed to load format error: Tried to leave frame "AppendExtraBuffer" while frame "TryGetValue" was at the top at 31.8
 at n._leaveFrame (160)
 at n.leaveFrame (160)
 at speedscope.js:166
 at a (166)
 at speedscope.js:166
 at Array.map (<anonymous>)
 at s (166)
 at import.js:111
 at Generator.next (<anonymous>)
 at s (import.js:111)

根据“错误:尝试离开框架”错误片段,我找到了两个类似错误的报告:

https://github.com/dotnet/diagnostics/issues/1206

dotnet-trace: Error in speedscope.app showing with Failed to load format Error: Tried to leave frame #1206 Closed mcraiha opened this issue Jun 6, 2020 ... josalem commented Jun 17, 2020

Looks like this is an error caused by a recent change in Speedscope (jlfwong/speedscope#273) that decided to change behavior and fail hard on some ordering constraints. I'll take a look at our logic for conversion over in Microsoft/PerfView and see if I can figure out what causes the ordering issue.

Issue in Microsoft/PerfView: microsoft/perfview#1178. Based on the comments here, it looks like we should be able to fix this by picking up the newest TraceEvent version.

adamsitnik commented Jun 18, 2020 I've provided a fix microsoft/perfview#1212

noahfalk closed this in #1313 Jul 6, 2020

https://github.com/microsoft/perfview/issues/1178

Export to speedscope sometimes has asymmetrical open/close frame event sequencing #1178 Open jlfwong opened this issue May 23, 2020 · 8 comments

所以据说错误与 https://github.com/jlfwong/speedscope/pull/273 update of speedscope ("jlfwong merged 2 commits into master from jlfwong/fail-unmatched-loudly May 23, 2020") which was included into v1.6.0 (May 31, 2020) version of speedscope.app. I can recommend you to try earlier version of speedscope to parse this file (v1.5.3 from Jan 16, 2020) or to get newer version of perfview (with https://github.com/microsoft/perfview/pull/1212 应用的提交有关。

speedscope 应用程序有预编译离线版本:https://github.com/jlfwong/speedscope/releases - get the version before pull/273 update from https://github.com/jlfwong/speedscope/releases/download/v1.5.3/speedscope-1.5.3.zip

解压它,用浏览器打开 index.html 并加载您的 json 跟踪文件。我能够使用旧版本的 speedscope

https://pastebin.com/4WW2tbiF 渲染您的示例

不知道如何使用 npm 或更新 microsoft/perfview 或使用未发布的版本 microsoft/perfview。