Showing posts with label performance. Show all posts
Showing posts with label performance. Show all posts
Saturday, 2 July 2016
Sunday, 19 June 2011
Silverlight Debugging Tools
Here’s some of the tools I use to debug my Silverlight Out of Browser applications and track memory consumption for Silverlight applications.
When the app starts up the user is shown the login screen. In the background, whilst the user logs in, various xap files are being downloaded asynchronously.
Here’s how the tools look on start up of the application, note no Xap optimisation tools or minifiers have been used.
HTTP Traffic
Fiddler (free)
This tool is pretty common among all web devs and tracks HTTP traffic. From this screenshot (tracking the startup of the application) we can see various external xap file requests are made to the localhost.
XAML and Resources
Silverlight Spy (commercial)
Memory Analysis
VMMap (free as part of SysInternals Tools Suite)
Select the process, in this case sllauncher.exe as it’s an out of browser application.
Here we can see the memory used by the application:
Heap – Native heap usage
Managed Heap – Silverlight and CLR heap memory usage
Image – Modules loaded
Stack – Silverlight and CLR stack memory usage
Visual Studio 2010 Profiling (Ultimate SKU)
Memory Profiling
CPU Profiling
WinDbg + SoS (Son of strike)
To be updated.
dotNet memory profiler (commercial)
To be updated.
CLR Profiler for Silverlight 4 and .NET 4 (free)
To be updated.
XPerf / HeapMonitor cmd –p %pid%
For native / unmanaged memory, to be updated.
Mike Cook is one of the leading authorities on Silverlight performance and someone to closely follow.
You can find his list of Silverlight best practises here:
Thursday, 19 May 2011
C# Dispose Pattern
Here is an example of how to correctly implement the C# Dispose pattern, ensuring all your unmanaged resources are efficiently cleared from memory.
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
internal class HowToImplementTheDisposePattern
{
private static void Main()
{
const string filename = "data.xml";
if (!File.Exists(filename))
CreateXmlFile(filename);
// the using statement implicitally calls the dispose on exit
using (var myDisposableObject = new MyDisposableClass(filename))
{
//do some work here with your object
}
}
public class MyDisposableClass : IDisposable
{
private XmlTextReader reader;
private bool disposed = false; // to detect redundant calls
public MyDisposableClass(string filename)
{
reader = new XmlTextReader(filename);
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
if (reader != null)
{
((IDisposable)reader).Dispose();
}
}
disposed = true;
}
}
~MyDisposableClass()
{
Dispose(false);
}
}
private static void CreateXmlFile(string filename)
{
var xml = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
new XElement("Child1", "data1"),
new XElement("Child2", "data2"),
new XElement("Child3", "data3"),
new XElement("Child2", "data4"),
new XElement("Info5", "info5"),
new XElement("Info6", "info6"),
new XElement("Info7", "info7"),
new XElement("Info8", "info8")
));
xml.Save(filename);
}
}
Subscribe to:
Posts (Atom)