1

So I have a WPF application which contains lots of real time effects - drawing directly to bitmaps, shader effects, etc. - and it all works great.

However, GPU usage is a bit higher than I would like, It hovers around 20%. I during the process of optimising, I tried attaching the Visual Studio profiler. When this is attached, and GPU Usage is selected as one of the profiling tools, when my WPF application runs....... the same app, with the same content....... GPU usage hovers around 5%!!!

After a heck of a lot of messing around, it does indeed seem that yes, when the profiler is attached (specifically GPU Usage, doesn't happen e.g. with just CPU usage selected) then yes the GPU usage plummets.

Please note the following (and I reference 5% and 20% as being if the profiler is attached or not)

  • I monitored GPU usage in task manager, and cross checked in Windows Performance Monitor/perfmon with the gpu are showing the same thing, I do not believe it is being misreported
  • You can look at system power monitoring and physically see more power being used under higher load level
  • If pushed my applications content, you can visually see in certain cases that at 5%, things run a bit smoother than at 20% (less frame drops), though in general...
  • Frame rate at both 20% and 5% usage is same 60fps
  • Happens if run directly in visual studio as debug, release, optimisation on or not, whatever
  • Happens if published and run stand alone
  • You can attach visual studio at run time with it's profiler (GPU tool) - starting and stopping the profiler literally toggles between 5% and 20% usage when you do it - no restarting my App or anything
  • Profiling everything in detail using visual studio, jetbrains dotTrace etc. does not identify any noticeable differences in the running app during 5% and 20% usage. E.g. jetbrains output showing call trees, time spent processing, call rates, etc. - 5% and 20% produce the same outputs. Good old WPF Performance Suite/wpfperf shows no difference between 20% and 5% usage of number of calls being made etc. (though the visual profiler doesn't seem to work with latest .net core unfortunately)
  • GPU profiling is not showing any difference in VS
  • Nvidia CUDA toolkit - well it didn't want to work trying to profile this. Nor did RenderDoc - so did look at those.
  • I can scale the usage of gfx used in my app up and down, to vary the 20%/5%, but there is always a difference between profiler attached or not
  • Playing with the windows timer, just in case - Windows low level system timer resolution running at a consistant 1ms for both 20% and 5% - and confirmed no other known power saving settings are being changed. This was confirmed both at run time, and variants where I manually set things in code.

My app is a .net core 3.1 app. GFX is an nvidia GTX 2060s.

Of note, I have seen similar before in a separate WPF app (lots of 3D inside it, running .net 4.x framework) - where running the gpu profiler as above would make the 3D rendering run more smoothly. Tested on different pc's with different GFX hardware. It is also the same across different versions of GFX drivers.

Absolutely stumped what might be causing this.... I wouldn't mind if it was the other way around and was 4 times faster when no profiler was attached!

I am aware that when profiling, various things might get set in the background. I would have no clue at all what these might be.

Does anyone have any ideas at all?

Many thanks

Martin

Extra: I found something similar, which is when the debugger is not attached in visual studio then performance is better - but my case here doesn't require any debugger, and appears to be GPU profiler specific, so don't believe it is anything like that. Why does my program run way faster when I enable profiling?

Example screenshot of performance on system demonstrating this...

High usage = no profiler attached. When everything drops, the profiler is attached and running (from around 15-38 seconds). Big red arrows = my task. Note there is other activity going on, including visual studio starting up the profiler, detatching it, etc.

Windows performance analyser

Example project (source + built) you can see this happening...

https://1drv.ms/u/s!As6cQRoZ5gU5x8FzXdwcYS1qEFqjdg?e=98o64j

...note this is a new WPF project, created 15 minutes ago independently of my original project, with a test 3d object loaded into it - and also shows a performance difference - almost 50% less on my pc when visual studio gpu profiler attached

Martin B
  • 61
  • 6
  • Updated original post with a performance screenshot and some extra notes – Martin B Apr 03 '20 at 11:26
  • Just to clarify - Visual Studio -> Debug -> Performance Profiler -> Available Tools -> GPU Usage and NOT Debug -> Graphics ->Start Graphics Debugging, that does not speed things up! – Martin B Apr 07 '20 at 14:13
  • Managed to get someone to test this completely independently to me - they saw the same thing. – Martin B Apr 07 '20 at 16:19
  • So I also posted this directly to MS, who got back to me, and sent me some screenshots showing the same kind of GPU usage drop with VS attached when they tried things out. (They were running ATI hardware, all my tests are on NVidia). Unfortunately took them weeks to get back and I suspect will take weeks to even feasibly progress. Anyone else able to look at the example project and see if it happens for you too? :) – Martin B Apr 22 '20 at 09:49
  • 1
    I am seeing this same behavior. Implementing a WPF control in WinForms app for image processing to take advantage of hardware-acceleration. When VS Profiler is not on, GPU is at 16%. With VS Profiler on, GPU drops to 1.7%. I get the same reading in Task Manager and Alienware Command Center. Specs: Bitmap - 640x480 scaling to ~2132x1600 Framerate - 30 Hz Graphics card - NVidia GeForce RTX 2080 Super If the GPU usage without the Profiler was as low as it is with the Profiler on, I would be happy. – Nick Nolan Jun 19 '20 at 17:57
  • Thanks for the response Nick! I think its a bigger thing that is affecting more people than realise. MS have an open ticket for me on this, but its `under consideration` and has been for weeks :/ – Martin B Jun 23 '20 at 12:42
  • If anyone else is following this, still `under consideration` by MS. They did reproduce the issue back in January so I can confirm it's not just me, but something MS has actual eyes on now. I still think that potentially vast numbers of WPF apps are potentially being throttled in their performance potential, or can use less resource to do what they do. And the months tick by.... :( – Martin B Jun 02 '21 at 09:42
  • Been chasing this so long. MS closed the issue as an automated `closing old issues` thing, GRRRRRRRRRRRRRRRRRRRRRRRRR. What a load of rubbish! Am re-opening it again in a new call. Ridiculous! – Martin B Aug 19 '21 at 16:12

0 Answers0