Scott Hanselman

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

September 17, '20 Comments [2] 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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Cross-platform diagnostic tools for .NET Core

September 15, '20 Comments [4] Posted in DotNetCore
Sponsored By

.NET Core is cross-platform and open-source. Tell someone, maybe your boss.

A good reminder. It's been this way for a half decade but I'm still bumping into folks who have never heard this. Moving forward, .NET 5 will be a unification of the .NET Framework you may have heard for years, and the new .NET Core I like talking about, PLUS great goodness, tools and libraries from Mono and Xamarin. It's one cross-platform .NET with a number greater than 4. Because 5 > 4, natch.

NOTE: If you like, you can learn all about What is .NET? over on my YouTube.

Now you've made some software, maybe for Windows, maybe Mac, maybe Linux. There's a lot of ways to diagnose your apps in .NET Core, from the Docs:

  • Logging and tracing are related techniques. They refer to instrumenting code to create log files. The files record the details of what a program does. These details can be used to diagnose the most complex problems. When combined with time stamps, these techniques are also valuable in performance investigations.
  • Unit testing is a key component of continuous integration and deployment of high-quality software. Unit tests are designed to give you an early warning when you break something.
  • Debug Linux dumps explains how to collect and analyze dumps on Linux.

But I want to talk about the...

.NET Core Diagnostic Global Tools

First, let's start with...

dotnet-counters

dotnet tool install --global dotnet-counters

Now that I've installed it, I can see what .NET Core apps I'm running, like a local version of my Hanselminutes podcast site.

dotnet counters ps
18996 hanselminutes.core D:\github\hanselminutes-core\hanselminutes.core\bin\Debug\netcoreapp3.1\hanselminutes.core.exe
14376 PowerLauncher C:\Program Files\PowerToys\modules\launcher\PowerLauncher.exe
24276 pwsh C:\Program Files\PowerShell\7\pwsh.exe

I also see PowerShell 7 in there that I'm running in Windows Terminal. Pwsh is also written in cross platform .NET Core.

I'll run it again with a process id, in this case that of my podcast site:

dotnet counters monitor --process-id 18996

Here I'll get a nice constantly refreshing taskman/processmonitor of sorts in the form of dotnet-countersperformance counters:

dotnet-monitor

Again this works outside Visual Studio and it works everywhere. You can watch them and react, or collect them to a file.

dotnet-dump

The dotnet-dump tool is a way to collect and analyze Windows and Linux core dumps without a native debugger. Although it's not yet supported on macOS, it works on Windows and Linux.

With a similar syntax, I'll dump the process:

dotnet dump collect -p 18996
Writing full to D:\github\hanselminutes-core\hanselminutes.core\dump_20200918_224648.dmp
Complete

Then I'll start an interactive analysis shell session. You can run SOS (Son of Strike) commands to analyze crashes and the garbage collector (GC), but it isn't a native debugger so things like displaying native stack frames aren't supported.

dotnet dump analyze .\dump_20200918_224648.dmp
Loading core dump: .\dump_20200918_224648.dmp ...
Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command.
Type 'quit' or 'exit' to exit the session.
>

There's tons to explore. Debugging production dumps like this is a lost art.

Exploring in dotnet dump

You can also do live Garbage Collector dumps with

dotnet-gcdump

GCDump is:

"a way to collect GC (Garbage Collector) dumps of live .NET processes. It uses the EventPipe technology, which is a cross-platform alternative to ETW on Windows. GC dumps are created by triggering a GC in the target process, turning on special events, and regenerating the graph of object roots from the event stream. This process allows for GC dumps to be collected while the process is running and with minimal overhead."

Once you have a dump you can analyze it in Visual Studio or PerfView on GitHub.

PerfView

Sometimes you may capture a dump from one machine and analyze it on another. For that you may want to download the right symbols to debug your core dumps or minidumps. For that you'll use

dotnet-symbol

This is great for Linux debugging with lldb.

"Running dotnet-symbol against a dump file will, by default, download all the modules, symbols, and DAC/DBI files needed to debug the dump including the managed assemblies. Because SOS can now download symbols when needed, most Linux core dumps can be analyzed using lldb with only the host (dotnet) and debugging modules."

Interesting in some real tutorials on how to use these tools? Why not learn:

In the next blog post I'll look at dotnet trace and flame graphs!


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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

What is the cloud? Explained

September 10, '20 Comments [3] Posted in Musings
Sponsored By

I'm continuing my "Computer Stuff They Didn't Teach You" series on YouTube. Please subscribe! I've set a personal goal to get to 100k subs by Christmas.

This episode is very special as it features a Surface Duo *AND* a 1U Rack-Mounted Azure Stack Edge! It's a gentle and clear explanation of cloud computing.

This 20 min video talks about the components of a computer, starting with a Raspberry Pi, Laptops, Phones, Desktops, then moving up to a massively powerful Azure Stack Edge rack mounted device, until finally talking about the Cloud itself. It consists of millions and millions of computers all working together to make the world turn.

You may know all these things BUT you may also enjoy some of the analogies to explain to non-technical partner how the cloud works as well as "what exactly it is you do!?"

I hope you enjoy watching it as much as I enjoyed making it! Go subscribe now!


Sponsor: Never miss a beat with Seq. Live application logs and health checks. Download the Windows installer or pull the Docker image now.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

How to use a Raspberry Pi 4 as a Minecraft Java Server

September 7, '20 Comments [12] Posted in Gaming
Sponsored By

imageMy 14 year old got tired of paying $7.99 for Minecraft Realm so he could host his friends in their world. He was just hosting on his laptop and then forwarding a port but that means his friends can't connect unless he's actively running. I was running a Minecraft Server in a Docker container on my Synology NAS but I thought teaching him how to run Minecraft Server on a Raspberry Pi 4 we had lying around would be a good learning moment.

First, set up your Raspberry Pi. I like NOOBS as it's super easy to setup. If you want to make things faster for setup and possibly set up your Pi without having to connect a monitor, mouse, or keyboard, mount your SSD card and create a new empty file named ssh, without any extension, inside the boot directory to enable ssh on boot. Remember the default user name is pi and the password is raspberry.

SSH over to your Raspberry Pi. You can use Putty, but I like using Windows 10's built-in SSH. Do your standard update stuff, and also install a JDK:

sudo apt update
sudo apt upgrade
sudo apt install default-jdk

There are other Minecraft 3rd party Java Servers you can use, the most popular being Spigot, but the easiest server you can run is the one from Minecraft themselves.

Go to https://www.minecraft.net/en-us/download/server in a browser. It'll say something like "Download minecraft_server.1.16.2.jar and run it with the following command." That version number and URL will change in the future. Right-click and copy link into your clipboard We are going to PASTE it (right click with your mouse) after the "wget" below. So we'll make a folder, download the server.jar, then run it.

cd ~
mkdir MinecraftServer
cd MinecraftServer
wget https://launcher.mojang.com/v1/objects/c5f6fb23c3876461d46ec380421e42b289789530/server.jar
java -Xmx2500M -Xms2500M -jar server.jar nogui

You'll get a warning that you didn't accept the EULA, so now open "pico eula.txt" and set eula=true, then hit Ctrl-X and Yes to save the new file. Press the up key and run your command again.

java -Xmx2500M -Xms2500M -jar server.jar nogui

You could also make a start.sh text file with pico then chmod +x to make it an easier single command way to start your server. Since I have a Raspberry Pi 4 with 4g gigs of RAM and it'll be doing just this one server, I felt 2500 megs of RAM was a sweet spot. Java ran out of memory at 3 gigs.

You can then run ifconfig at and command line and get your Pi's IP address, or type hostname to get its name. Then you can connect to your world with that name or ip.

Running Minecraft Servers

Performance Issues with Complex Worlds

With very large Minecraft worlds or worlds like my son's with 500+ Iron Golems and Chickens, you may get an error like

[Server Watchdog/FATAL]: A single server tick took 60.00 seconds (should be max 0.05)

You can workaround this in a few ways. You can gently overclock your Pi4 if it has a fan by adding this to the end of your /boot/config.txt (read articles on overclocking a Pi to be safe)

over_voltage=3
arm_freq=1850

And/or you can disable the Minecraft internal watchdog for ticks by setting max-tick-time to -1 in your server's server.properties file.

We solved our issue by killing about 480+ Iron Golems with

/kill @e[type=minecraft:iron_golem]

but that's up to you. Just be aware that the Pi is fast but not thousands of moving entities in Minecraft fast. For us this works great though and is teaching my kids about the command line, editing text files, and ssh'ing into things.


Sponsor: Never miss a beat with Seq. Live application logs and health checks. Download the Windows installer or pull the Docker image now.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Synology DS1520+ is the sweet spot for a home NAS and a private cloud

September 4, '20 Comments [13] Posted in Reviews
Sponsored By

61fje6GaYKLMy long love of Synology products is well-documented. I checked my Amazon history, and I bought my Synology DS1511+ NAS in May of 2011! I have blogged about the joy of having a home server over these last nearly 10 years in a number of posts.

It's great to have a home server - it's a little slice of the cloud, in your home. I like home servers because while I trust the cloud, I trust a computer I can touch about 1% more than someone else's computer.

NOTE: When I review gadgets and products, I often use Amazon Affiliate Links. I donate the small amount I make from you using these links, Dear Reader, to my kids' charter school. Thanks for using and clicking these links to support!

Anyway, my Synology DS1511+ is about ten years old and it's working great but I am using it more and more and throwing more and more at it. It did have some challenges running a Minecraft Server recently, on top of all its other responsibilities.

I use Seagate 2TB disks and I run 4 of them in the 5 bay device, with a fifth drive as a hot spare. If a drive goes bad - which happens about every 2 to 3 years - the Synology will rebuild with the spare, then I pull the dead drive. I have two additional 2TB unopened Seagate Drives ready to go, so when this happens it's as close to a non-event as possible.

Synology is amazing

I have every digital photo and digital video and family document we've created since 1998. I've also got local backups of my Gmail from hanselman.com which goes back to before Gmail started when I was running my own POP3 mail server. It's all easily less than 5TB. Remember also that Google Takeout can get you Zips of all your data! Back. It. All. Up!

Twenty years of photographs

Fast forward to today and Synology came out with the Synology 5 Bay NAS DiskStation DS1520+. It's basically a ten year's newer clone of my 1511+ workhorse, updated and refreshed! It's WAY faster. It was immediately noticeable on startup. File access is faster, indexing is faster, my Docker images start faster.

Now, a little more money would get you a 6 bay NAS and just $150 will get you a 2 bay, but I love the size and power of a 5 bay for our home and my office. Four disks are for my array and 1 is that hot swap drive. I think that for small businesses or home offices five bays is the perfect size and price - about $600-700 USD.

The Synology 1520+ has 4 GbE network ports (which is nice with Link Aggregation in a busy house), supports two eSATA externals (I use one to backup the backup to a single disk, as I believe in the Backup Rule of Three and you should, too!) and works with any SATA drives, 2.5" or 3.5". One of the big reasons that attracted me to this update is that there's slots for 2 x M.2 2280 NVMe SSDs for caching. I put a 512G M.2 drive in there to accelerate file system access.

5 Drives in a Synology

If you want, you can have up to 15 drives using two DX517 drive expanders up to 240TB, but with just 4 slots and large drives like Seagate Ironwolf drives in the 10TB to 18TB range, storage is really a non-issue. I use Seagate 2TB drives because they're plentiful and like $50. We treat it like a massive infinite local disk in the house that everyone can talk to. We named it SERVER, so it's just \\SERVsynoER for everyone.

The Synology OS software is deep and broad and runs entirely in your browser. You'll figure it out very quickly as it's all windows and wizards. I am a fan of the Cloud Sync feature that I use to backup my Google Drive, Dropbox, and One Drive. Again, this is a level of paranoia, but damned if I'm gonna get locked out of my own data.

Synology Cloud Sync

The Synology HyperBackup goes in any direction using whatever cloud and whatever tools you are familiar with. You want Rsync? Cool. Want to backup to Azure or AWS? Cool.

Backup to Azure from a Synology

I was concerned that migrating would be hard or involved basically starting over from scratch, but since I was moving between two models in the same family (I was moving from a 1511+ to a 1520+, even 10 years later) It was literally just move the drives in order and boot up. Took 10 minutes. For movement between device families or to new drives there's at least three good options.

It was actually scarily simple, given there's ten years of history here. I moved the drives (maintaining order) and booted up the new 1520+ and was greeted with this screen:

Migrate your Synology

I clicked Migrate twice and was all set.

image

If you are migrating and upgrading, I'd be sure to read the section on HDD Migration and look closely at the table, considering your Source and Destination NAS models.

So far this new Synology is WAY snappier, runs Docker faster, can run Virtual Machines now (although in 8 gigs, only small utility ones), and the SSD cache has made browsing family photos whip fast. All in all, it feels like a 10 year refresh BUT it's the same size.

SSD Cache in a Synology

My home NAS is sitting quietly on a shelf in my office. The kids and spouse are having their PCs backed up in the background, family photos and DVD backups are all available easily (and there are Synology iPhone apps as well to view the files).

Synology devices specifically - and home NAS devices generally - are a great addition to techie homes. There's a bunch of 1st and 3rd party packages you can run on it to make it as much or little a part of your Home IT setup as you like. It can run DHCP and DNS, iTunes Servers, Mail, Chat Servers, or even their own web-based Office clients. Take a look at the Synology 1520+ if you're in the market for a home or business NAS. I'm looking forward to another 10 years with this NAS.


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

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