Scott Hanselman

dotnet-trace for .NET Core tracing in PerfView, SpeedScope, Chromium Event Trace Profiling, Flame graphs and more!

September 17, 2020 Comment on this post [12] Posted in DotNetCore | Open Source
Sponsored By

Speedscope.app is an online "flamegraph visualizer" that you can also install offline. It's open source and on GitHub. It will allow you to view flamegraphs that have been generated by diagnostic tools, but Speedscope is good at dealing with large files without issues or crashing. There's lots of choices in viewers of flamegraphs, but this is a good one.

Adam Sitnik has a great blog about how he implemented flamegraphs for .NET.

Speedscope has a simple file format in JSON, and PerfView already exists is free and open source. PerfView is something you should download now and throw in your PATH. You'll need it someday.

We saw in the last blog post that I did a GC Dump of my running podcast site, free command line tools. Now I'll do a live running trace with

dotnet-trace

So I'll just dotnet trace ps and then

dotnet trace collect -p 18996

Which gives me this live running trace until I stop it:

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000000000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

Process : D:\github\hanselminutes-core\hanselminutes.core\bin\Debug\netcoreapp3.1\hanselminutes.core.exe
Output File : C:\Users\scott\trace.nettrace

[00:00:00:15] Recording trace 866.708 (KB)
Stopping the trace. This may take up to minutes depending on the application being traced.

Trace completed.

Even though this ran for just 15 seconds I collected many thousands of traces. If I need to, I can now find out EXACTLY what's happening in even short timeframes OR I can visualize what's happening over longer timeframes.

Ah, but check out this switch for dotnet trace!

 --format <Chromium|NetTrace|Speedscope>

That's a useful game changer! Let's try a few, maybe Speedcope and that interestingly named Chromium format. ;)

NOTE: If you have any errors with Speedscope format, make sure to "dotnet tool update -g dotnet-trace"

Now you'll get a something.speedscope.json that you can open and view in SpeedScope. You'll see a WEALTH of info. Remember that these formats aren't .NET specific. They aren't language specific at all. If you have a stack trace and can sample what's going on then you can make a trace that can be presented as a number of visualizations, most notably a flamegraph. This is 'how computers work' stuff, not '.NET stuff." It's great that these tools can interoperate so nicely.

There is so much info that you'll want to make you own with dotnet trace and explore. Be sure to scroll and CTRL-scroll to zoom around. Also be sure to look at the thread picker at the top center in the black title area of SpeedScope.

Speedscope.app

Remember how I pushed that this isn't language specific? Try going to edge://tracing/ in new Edge or in chrome://tracing in Chrome and load up a dotnet trace created with --format Chromium! Now you can use the Trace Event Profiling Tool!

Same data, different perspective! But this time you're using the tracing format that Chromium uses to analyze your .NET Core traces! The dotnet-trace tool is very very powerful.

image

Be sure to go read about Analysing .NET start-up time with Flamegraphs at Matt Warren's lovely blog.


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 19, 2020 14:05
Never used Flamegraphs, but certainly will play with it. Looks like it's very useful.
September 26, 2020 13:18
Good post!
September 26, 2020 13:25
Hey! I have gone from being on the precipice of giving up everything to the threshold of new beginnings that have the potential to sustain me for years to come. And with continued support of https://calmerry.com/blog/depression/why-do-i-feel-sad-for-no-reason/ therapists I will be certain that I will have the tools and resources to deal with any emotional struggle that comes my way.
October 09, 2020 13:24
Heya just wanted to give you a brief heads up and let you know a few of the images aren't loading correctly. I'm not sure why but I think its a linking issue. I've tried it in two different web browsers and both show the same results.
October 09, 2020 23:13
My brother recommended I might like this web site. He was entirely right. This post actually made my day. You cann't imagine just how much time I had spent for this info! Thanks!
October 10, 2020 0:39
Your means of explaining everything in this article is truly nice, all be able to without difficulty understand it, Thanks a lot.
October 11, 2020 5:46
When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove me from that service? Thank you!
October 12, 2020 17:17
Cialis generic jocialisrl.com generic cialis
October 12, 2020 17:25
Loan online https://loanus24online.com/ installment loans online
October 12, 2020 18:16
Loan online same day payday loan online same day online loan
October 12, 2020 23:34
May I simply say what a relief to uncover someone that really knows what they're talking about on the internet. You actually realize how to bring a problem to light and make it important. A lot more people really need to check this out and understand this side of your story. It's surprising you're not more popular since you definitely possess the gift.
October 13, 2020 0:57
Online payday loans online payday loans direct lenders payday loans online same day

(will show your gravatar icon)
2+5=?
Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, li, ol, pre, strike, strong, sub, super, u, ul) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Live Comment Preview

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.