How to get profiling data on cache misses in Unity? - windows

I'm searching for a way to get profiling data on cache misses for my Unity project.
I already searched for visual studio tools that do have these stats. I can see Visual studio has tools for .NET applications that shows cache misses (like what's described here https://learn.microsoft.com/en-us/visualstudio/profiling/cpu-and-windows-counters?view=vs-2017), like its Performance Wizard, but they are always grayed out for my Unity project.
I tried attaching Visual Studio's performance tools to my running Unity projects, but I can't seem to find the data I'm looking for.
Unfortunately, Unity's profiler doesn't seem to show the cache misses stats I'm looking for.
I’m using mono but am open to switching to IL2CPP if that can help, I’m mainly exploring unity performance at this point.
I would like to remove guess work from my optimisations. Is there anything I missed?
Edit 1:
Here's what I tested.
I created a build of my test project with IL2CPP selected in the player options
In visual studio, I went to Debug/Performance Profiler, I selected the "Executable" target and used the option "Performance Wizard".
After clicking "Start" I used the option "Instrumentation", clicked next, used "An executable" for the application I want to profile, clicked next, selected my created build's .exe, clicked next and finish.
I then get a failure saying:
Profiling started.
Instrumenting <my path to my exe> in place
Info VSP3049: Small functions will be excluded from instrumentation.
Microsoft (R) VSInstr Post-Link Instrumentation 15.8.18219.1 x86
Unable to obtain debug information. Link with the /PROFILE linker switch.
PRF0002: Instrumentation failed with these options: /u "<my path to exe> /excludesmallfuncs. Please check the output window for additional details.
Data written to <my path>200126(5).vsp.
Profiling finished.
Profiling complete.
I tried looking into Error VSP1011: Unable to obtain debug information. Link with the /Profile linker switch but I'm not sure it's relevant.
I installed VS2013 and tried the same steps and it gave me the same errors.

I finally found a good tool for this.
Looks like Intel's VTune is pretty easy to use and gives good info. For sure it's sampling and doesn't show the exact information, but it gives me hotspots of things to investigate.

Related

Debugging ASP .Net Core symbols and source don't match

I'm trying to track down an issue with MVC so I thought I would step into the ASP .NET Core source code. I've unchecked "Enable Just My Code" and I've checked "Enable .NET Framework source stepping" (although I guess that's not necessary). I've also checked "Enable source server support" and enabled the Microsoft symbol server.
I step into this line
app.UseMvc();
and eventually I get to this code in MvcApplicationBuilderExtensions.cs.
VerifyMvcIsRegistered(app);
var options = app.ApplicationServices.GetRequiredService<IOptions<MvcOptions>>();
if (options.Value.EnableEndpointRouting)
{
Stepping through this code the program counter starts to jump around and I receive an error that several of the local variables cannot obtain the value because it is not available or it's been optimized away. I assume this is because the source file and the symbol files don't match.
I'm running this on Visual Studio 2019. It's .net Core 2.2.203. I've deleted the symbol cache and the SourceServer cache. I'm trying to figure out what I've done wrong in my code and exactly why.
Actually, I've tried to debug .NET source code several times over the past several years and I always have the same issue. None of the online help seems to have an answer. Am I doing something wrong or is this just unreliable?
The message is accurate and explains exactly what happens. It has nothing to do with mismatched symbols.
The (non) problem as the message explains is that the IL has been optimized during compilation, those variables no longer exist. A Release build performs a lot of optimizations that usually end up eliminating parts of the code that aren't needed.
Functions can and quite often are inlined. A variable may be replaced by a register for example. A loop may be eliminated entirely. When that code runs the variables or functions are no longer there so they can't be displayed.
Debug symbols can still be generated in a Release build. They'll reflect the IL generated for a release build though. One would need assemblies compiled in a Debug configuration to get IL that matched the source without any optimizations.
That's true for the .NET Core runtime, our own code when run a Release build and all NuGet packages.
If you want to debug .NET Core source code you can download it from github (https://github.com/dotnet/corefx). It's very easy to debug, like your own project.
There is very good video, where explains how .NET Core MVC request life cycle works (https://app.pluralsight.com/library/courses/aspnet-core-mvc-request-life-cycle/table-of-contents), maybe there you can find information which you need.
P.S. you can get 3 months free in pluralsight with microsoft account.

VS Go to definition failing / source code not available

I've just started experimenting with Visual Studio in order to explore F# but I'm never able to navigate to third-party dependencies code through the "Go to definition" option.
I'm getting this error message:
"Cannot navigate to definition. Source code is not available."
My main language is Java and I'm used to IntelliJ IDEA source retrieval mechanism (usually done through the Maven repositories). I consider this an indispensable functionality when developing code. Isn't there anything similar for .NET?
EDIT
After reading the comments and answer, I went looking for some packages on SymbolSource and I found them (e.g. SymbolSource page for JSON.Net).
I've tried the PM commands shown and the page but they kept producing errors:
Install-Package : An error occurred while processing this request.
So I've downloaded NuGet.exe and by running the command in verbose mode I could obtain the URL it was requesting (e.g. SymbolSource FeedService URL for JSON.Net).
As you can see it is showing an error:
Gettting packages from the NuGet feed is temporarily disabled. But you don't need it for debugging!
Is this to be expected?
P.S.: I've also tried with the pre-authenticated links. Same problem.
P.S.2: Seems that I can step into source code of third party dependencies during debug, but I still can't access it through "Go to definition" (neither in Debug nor in Edit mode).
In Visual Studio, you might be able to Go to Definition to third-party source code if:
You are in Debugging mode
'Enable source server support' options are turned on (you seem to do that already)
The third-party assemblies have their pdb files in source servers
Go to Definition in Editing mode doesn't have that capability in either C# or F#. In F#, 'Navigate to Metadata' hasn't been implemented yet.
We haven't been able to add 'Navigate to Source' to Visual F# Power Tools because they have many tricky issues e.g. (1) The feature is unusable if source server support isn't enabled, which is unfortunate (2) It relies on external data source that might be slow or unavailable (3) There is a good chance that pdb contents are outdated or incorrect, etc.
That said, 'Navigate to Metadata' seems to be less tricky to handle. We have required information from FSharp.Compiler.Service, it requires some effort to filter what we need and present it to users. This feature may be available in a future version of Visual F# Power Tools.

How to generate shader debug information (pdb) in VS2012

I'm trying to debug my shaders in Directx 11 SDK application using graphics diagnostics tool in VS2012, however when I click Start Debugging on one of the shaders in Graphics Pixel History panel I'm getting Pixel Shader.pdb not loaded and I'm not able to find the pdb file anywhere.
I tried compiling shaders at runtime using D3DX11CompileFromFile with D3DCOMPILE_DEBUG flag as well as using the HLSL compiler with debugging information turned on (/Od /Zi) but none of these options is producing the pdb file I could use in graphics diagnostics tool.
How do I generate these files?
I think this "Pixel Shader.pdb not loaded" message is misleading. The is no any .pdb files generated by HLSL-compiler. All debug info are integrated into binary (either memory blob or .cso file).
Does your shader file named "Pixel Shader"? Maybe it says not about a shader, but some kind of Visual Studio's internal source files (shader debugger in VS2012 was somewhat unstable sometimes)
Some ideas that, probably, can help you to solve issue:
Make sure that your debug and release output binaries are not messed up. Check both debug and release configuration of project's properties and each shader's properties.
Make sure that you are loading right shader file. Check ten times all file paths.
Clean your project, eliminate all binaries by hand. Rebuild again.
IIRC, in graphics debugger you can only debug shaders, compiled offline (i.e. not by D3DX11CompileFromFile).
Try to compile using fxc.exe directly.
Use filenames that does not contains spaces and special characters.
Make sure your test shader is simple enough, so debugger will not crash. Thy to use default template.
If it's still doesn't works, write a minimal example project, check that it doesn't works, post it here so we can test it.
Try VS2013
Try your videocard vendor's debugging tool (such as NVIDIA nsight or AMD GPU PerfStudio), to see if it is problem with Microsoft tools or not.
Hope it helps somehow.

The Following Module was built either with optimizations enabled or without debug information after frame work is changed to 4.0 from 3.5

I am using VS2010.I was changed my project and its dependent projects .Net Framework to 4.0 from 3.5.Now I could not attach the process,due to this I am not able to debug the code.
I have cleaned all the bin folders and rebuild the projects ,but still I am having following error.
Please help me to resolve this..
I'm not sure what the question is here. The error message clearly tells you that you need to
Turn off (disable) optimizations
Turn on (enable) debug info
Rebuild your project so those changes take effect.
Apparently you only did step #3.
Also see vs2010 debugging module was built without debugging information?, which may provide more information.
I also received this error, and did all the right things as described above - those have been my settings all along anyway. I even went so far as deleting the assembly from the long C:\Users... path in the error message - it still didn't cause that message to go away.
Then I tried putting a breakpoint in the source, which should not be allowed if the module really WAS built without debug information. And then ran the program and it stopped at the break point and I could do all the usual debugging.
So right now I'm just ignoring the message. I could do as suggested and disable the 'Warn if no user code on launch' option as suggested in the message, but I'm not doing that until I can spend some time working out why the message comes up at all.
Uncheck this option in Visual Studio 2012.This would solve this issue

NVIDIA Visual Profiler, Debug and Release modes in Visual Studio 2010

I'm new to Visual Studio 2010, as I was used to compile my CUDA codes with nvcc using Linux as operating system. Incidentally in some posts of this and the NVIDIA Developer Zone forums, I have read warnings on proper compilation in Visual Studio (Debug/Release modes, see link for the difference between the two) to correctly use of the NVIDIA Visual Profiler. In my (poor) understanding, Visual Studio automatically compiles under a "Debug" mode, but for a successful profile the "Release" mode is necessary.
My (simple) questions are:
1) How do I switch from the "Debug" mode to the "Release" mode? Is it enough to use Properties -> Configuration Properties and select "Release" instead of "Active(Debug)"? Also, I noticed that I have to repeat the selection each time I want to Rebuild the project.
2) Is this enough for a correct usage of the Visual Profiler?
Thank you very much in advance.
1) You're switching from Debug to Release in the wrong place. The setting you're using is just for selecting which build settings to view or edit. You should use Build | Configuration Manager or (easier) the Solution Configurations dropdown box in the Standard toolbar. If you don't see the Standard toolbar, right click in the toolbar area by the menu, and select it there. You will find that you don't have to reselect the setting for each build now.
2) The CUDA compiler optimizes aggressively even in Debug mode. I don't know if it matters which configuration you use. Both should work. You can try and see if you get any different results.
See Roger Dahl's answer for how to set the configuration.
There are several forms of profiling.
Performance Profiling
This should definitely be done with optimizations enabled on the CUDA kernel. Disabling optimization and specifying debug information performs more operations than a CPU but it does do other modifications to the code (stack overflow checks) that will impact counters.
Source Level Profiling
This can be done on Debug or Release builds. Nsight 3.0 CUDA Profiler has source level experiments that will show statistics per C source, PTX, or SASS line. The CUDA 5.0 Visual Profiler supports code correlated experiments but will not show the results for every line (only problematic lines). Disabling optimizations will result in significantly more accurate line information for the SASS to PTX to C code mapping. For many analysis cases this is fine. However, if you want to understand the code generation per C line then you should enable full optimizations and heavily look at the SASS code and only use C source and PTX as a guide.
In order to get C source level correlation you need to use the default debug configuration which generates full debug information or use a custom configuration that enable -lineinfo. This option can be enabled using the following steps:
Open Solution Explorer
Right click on your .cu file or project file
Execute the Properties command
In the left pane select the tree node Configuration Properties | CUDA C/C++ | Device
In the right pane change Generate Line Number Information to Yes
In CUDA 5.0 -lineinfo has several small impacts on code generation so it is not advisable to keep this enabled in your Release configuration.

Resources