简体   繁体   中英

How to analyze the performance of requests in ASP.NET MVC application?

I would like to capture the hit time, processing time, memory consumption and response time of requests in ASP.NET MVC application.

Is there any way or tool to perform this?

Check the miniprofiler , developed by the stackoverflow team

http://code.google.com/p/mvc-mini-profiler/

This helps you to do some analysis. There is a nuget pacakge available which you can use to add this to your project.

Scott has written a post about how to use that.

You can also look into Glimpse .

There are commerical products to do memory and performance profiling like telerik just trace . You can download their trial version and use that

You can create your own little performance test monitor. This is from page 670 of Steven Sanderson's book, Pro Asp.Net MVC 2 Framework:

public class PerformanceMonitorModule : IHttpModule
{
    public void Dispose() { /* Nothing to do */ }
    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += delegate(object sender, EventArgs e)
        {
            HttpContext requestContext = ((HttpApplication)sender).Context;
            Stopwatch timer = new Stopwatch();
            requestContext.Items["Timer"] = timer;
            timer.Start();
        };
        context.PostRequestHandlerExecute += delegate(object sender, EventArgs e)
        {
            HttpContext requestContext = ((HttpApplication)sender).Context;
            Stopwatch timer = (Stopwatch)requestContext.Items["Timer"];
            timer.Stop();

            if (requestContext.Response.ContentType == "text/html")
            {
                double seconds = (double)timer.ElapsedTicks / Stopwatch.Frequency;
                string result =
                string.Format("{0:F4} sec ({1:F0} req/sec)", seconds, 1 / seconds);
                requestContext.Response.Write("<hr/>Time taken: " + result);
            }
        };
    }
}

Then add to your web.config:

<add name="PerfModule" type="Namespace.PerformanceMonitorModule, AssemblyName"/>

Not free but it is really good:

http://www.jetbrains.com/profiler/

dotTrace is a family of performance and memory profilers for .NET applications.

Our latest release, dotTrace 5.2 Performance, helps .NET developers quickly find performance bottlenecks and optimize their applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM