I've just inherited a website (ASP.Net 2.0) written by someone else that I need to maintain.
The code is not horrible, but it has a number of things that make the website run incredibly slow.
I have an idea to monitor this, and I want to see what more experienced developers think of it.
My objective right now is to find out when pages take too long to load, to focus attention in those spots.
I'm thinking on hooking the PreRequestHandlerExecute and PostRequestHandlerExecute events in Global.asax, and create a StopWatch in "Pre", attach it to HttpContext.Items, and read it in "Post", and if the request took more than, say, 100ms, it'll report to me to let me know.
Some "pseudo code" for that would be:
protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) {
System.Diagnostics.Stopwatch theTimer = new Stopwatch();
theTimer.Start();
HttpContext.Current.Items.Add("RequestTimer", theTimer);
}
protected void Application_PostRequestHandlerExecute(Object sender, EventArgs e) {
Stopwatch theTimer = (Stopwatch) HttpContext.Current.Items["RequestTimer"];
System.Diagnostics.Debug.WriteLine(theTimer.ElapsedMilliseconds + "@: " + HttpContext.Current.Request.RawUrl)
}
What do you think of this approach?
Is it reasonable to do this?
Is it going to make my website crawl to its knees?
Is there a better way to do this?
Some thoughts:
- It may be better to grab DateTime.Now.Ticks and store that, which is probably going to be lighter than the StopWatch
- I know it'd be better to have all pages inherit from a page of my own, and time there, but I don't want to go through dozens of pages and change them all.
Any thoughts are greatly appreciated! Thanks!