I'm currently having a hard time driving down the peak memory consumption of my background agent below the 6MB limit. Are there any recommendations for WP7 capable memory profilers. I am not even asking for something along the lines of dotTrace but basically anything that offers some insight about what's going on.
The Windows Phone SDK comes with a profiler for both memory consumption, and other things, that's available in Visual Studio after installation of the SDK.
You can read more about it on MSDN
Also, try look isolated at the background agent code, and move it to a separate application, where you run it in the foreground. That could possible make it easier for you to nail where the problem is.
Related
According to this article on Diagnosing memory issues with the new Memory Usage Tool in Visual Studio:
1. Memory caps on Phone devices: In particular for Phone, there are specific memory limits enforced on an application based on the size of
the memory in the device. Allocating more than the specified limit
will cause an OutOfMemoryException and will result in app termination.
All well and good, and in Visual Studio you can use the Diagnostics tool to see memory usage during development.
Is there any way a UWP app running on a (Windows 10) phone can get an approximate idea of how much memory it's consuming? - I.e. within the app, not by leveraging visual studio.
Update - How I chose the 'Answer'
The key thing is that this has exposed a massive lack of understanding on my part regarding memory in general, and specifically how modern .net apps consume it. Both of these answers were of help to me, and even though I have experimented briefly with both its hard to say either one of them is the right answer as I'm finding both of them useful.
Also whilst I appreciate both the answers linking to the appropriate official documentation, that information is pretty thin (no disrespect to Romasz & Alexej).
In the end I've awarded the Answer to Romasz as the API seems a little deeper.
I think you can also make use of MemoryManager class. There you can subscribe to events informing about increase/decrease of memory, set limits, as well as check memory usage of app or read reports for app or for process:
var appMemory = MemoryManager.AppMemoryUsage;
var appMemoryReport = MemoryManager.GetAppMemoryReport();
var processMemoryReport = MemoryManager.GetProcessMemoryReport();
For UWP apps there is ProcessDiagnosticInfo class available.
ProcessMemoryUsageReport mu = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport();
I have two libraries which do exactly the same thing - generate a PNG file from a WriteableBitmap.
How do I know which one consumes less memory?
Visual Studio has great Performance and Diagnostics tools which you can find in the "Analyze" menu in the menu bar on top. Using these tools you can record CPU usage, memory usage, UI responsiveness and battery usage of your app. Interact with your app while recording and analyze it afterwards. This should be the most realistic way of finding out what behaves better.
I'm working on a scheduled background agent for Mango (7.1)
I've managed to cut my memory usage down from 10.5MB to 6.5MB using manual trace techniques based on DeviceStatus.ApplicationPeakMemoryUsage along with some intelligent guesswork about what to optimise.
However, now I need to get down to below 6MB - and the final 0.5MB is proving elusive.
I've managed to run the "Windows Phone Performance Analysis" tool on the main app, but can't seem to find a way to get it to run against the agent.
Are there any tools and/or techniques available to assist me in working out what is filling up my agent's memory? Ideally I'd like a way to investigate the entire memory space - including both code and data, and ideally it should work against a release build.
As has already been said, the debugger will add a non-negligible memory overhead. So the best way I found is:
Activate the emulator's console: http://nicksnettravels.builttoroam.com/post/2011/01/19/Windows-Phone-7-Console-Window-on-64-bit-machine.aspx
At strategic points of your code (beginning and end of the main functions for example, or after allocating a big object), display the memory consumption:
Console.WriteLine("Function {0}: {1}", "name of your function", DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"));
Start the application without attaching the debugger (Ctrl + F5), sit back and enjoy
Remember if you are running the background agent in Debug mode this adds about 2MB onto the memory footprint of the agent, so you might be OK.
You could probably use the ApplicationPeakMemoryUsage still and write the memory details out to a file in Isolated Storage when running the app directly, rather than from Visual Studio.
HTH - Rupert.
You may find the following blog post interesting, you may have already seen it but it describes both the debug memory addition as well as some tips to decrease the memory footprint.
http://www.pitorque.de/MisterGoodcat/post/Windows-Phone-Background-Agents-Pitfalls-(2-of-n).aspx
I have a WinForms application that uses XNA to animate 3D models in a control. The app have been doing just fine for months but recently I've started to experience periodic pauses in the animation. Setting out to investigate what is going on I have established these facts:
It happens on my machine only, other machines works fine
Removing everything from my render loop does not improve the problem
In 2. I didn't actually remove everything, I limited my loop to set the viewport on my GraphicsDevice and then do a GraphicsDevice.Present.
Trying to dig further I fired up PIX to capture some statistics. Screenshots of two PIX runs can be viewed here (Run6) and here (Run14). Run6 is using my original render loop and Run14 is using the bare-bones Present loop.
PIX tells me that the GPU is periodically doing something, and I assume this is causing the pauses. What could be the cause of this? Or how do I go about finding out what the GPU is actually doing?
Update: since I usually trust my code to be perfect (who's laughing?) I started a new XNA project from scratch to see if it exhibit the same behavior. So starting a new XNA 3.1 Windows Game project and running PIX I get this timeline. The same periodic pauses. So the problem must be lower in the stack, in XNA or Direct3D.
So PIX shows that the GPU is working on something, I can see the list of DX calls made within each frame and the timing calculations shows that the pause occurs during (or after) the IDirect3DDevice9::Present call.
Update 2: I had previously installed and uninstalled XNA 4.0 CTP on the problematic machine. I cannot be certain that this is related but I thought that perhaps a reinstall of the XNA Game Studio 3.1 bits could make a difference. Turns out it did.
The underlying question remains the same (and the bounty is still up): what could affect XNA 3.1 (or DirectX) to make it behave like this and is there any logging/tracing power tool for the DirectX and/or GPU level out there that could shed some light on what is going on?
Note: I'm using XNA 3.1 on a Windows 7 x64 dual-core machine with 8GB RAM.
Note2: also posted this question on the XNA Creators forums here.
You could try to see if you can find something with Xperf that is close to your periodically problem, do not run your application but keep the programs open that would normally run besides your application. You could also try to do it again with the application running but it could give a cluttered view.
Start the tracing, do this in an elevated prompt.
xperf -on BASE+LATENCY -stackWalk Profile
Wait for a fair amount of time to be sure that the problem is traced.
Stop the tracing and open it like this.
xperf -d trace.etl
xperfview trace.etl
Analyze by looking at the graphs and consulting tables of specific intervals and see if you can find something that is related to the problem, the highest chance on finding it would be in the DPC and Interrupts section. But it might as well be something odd at the CPU or I/O section. Good luck!
Also more information on Xperf and how to obtain it, hopefully this delivers results.
If not, you can alternatively try GPUView which has been used for improvements in DWM,
this is also included next to Xperf with the Windows Performance Toolkit so you can easily try both!
log v
... wait for a fair amount of time to be sure that the problem is traced ...
log
gpuview merged.etl
In the case that gpuview gets out of memory you can try to add "/limit 3" or remove the v.
Read the documentation of the tools if you are stuck somewhere.
Hmm ... this seems to be occurring on the GPU, however it sounds like a CPU garbage collection issue. Can you run the CLR profiler and see if you can see any spikes in GC activity that you can correlate to the slowdowns?
I agree that it sounds unlikely since you can clearly see it in PIX, but it might offer a clue as to the cause.
If it's only happening on your own machine, then could it be drivers? Forgive me for being skeptical, but it's a 64 bit machine after all :D
This looks like either a vsync issue or GPU in its last throes. Since going back to a different version fixed it, and the "bottleneck" is in IDirect3DDevice9::Present lets go with the former option.
I'm not familiar with XNA so I don't know how much of the workings of D3D are exposed, but do you know what your PresentationParameters are set to?
Specifically try setting the swap effect set to Discard.
I'm writing an app for a Pocket PC device which appears to be slowly leaking resources - after 24hrs the device slowly becomes unresponsive and eventually locks up altogether.
On XP/Vista I would at this point fire up trusty PerfMon and plot graphs of handles, threads, memory, mutexes etc - anything that could be leaking.
Can someone recommend an approach for this on Windows Mobile? What would be ideal would be a mobile agent that collects performance counters and reports them back to a PC-based instance of PerfMon.
I have seen this article, but it appears to be specific to .NET compact framework - I still work in C++/win32.
You could start out with App Verifier, but really the tool that I (and everyone I know) uses is Entrek's Codesnitch. That thing pays for itself in the first use, every time.
Embedded Visual C++ 4 contained "Remote Performance Monitor" that could do just that. Microsoft retracted EVC4 as free download some time ago, but it can still be downloaded from MSDN or found on the internet. It does not appear to work with Windows Embedded 6 and newer though and I am not sure which kernel Windows Mobile 6 are built on.