Reputation: 28
I would like to check the load speed of each page in a particular asp.net website (based on C#). I thought of creating a class for timing the loading and execution of a certain element. I'd like to create a stopwatch
object on each user control and on the page itself to get diagnostics on how long the page takes to load altogether. When debug
is enabled, we could then see the load times of each of the pages, as well as each of the elements.
I don't want to save it in session
, but I really can't think of a way around it.
I was thinking that a nice implementation would be to include a class that I write which will track the stopwatch
values for each of the master page, page, and user controls as they load, but where could I save each execution time
when it was done? I suppose I could use Session
, but is this the only way to save data across user controls and pages?
What would be the best way to do this?
Upvotes: 0
Views: 137
Reputation: 7200
If this is an MVC site, you could check out the MVC Mini Profiler. It is available as a Nuget package.
Upvotes: 0
Reputation: 1089
I would agree with other answers in that leveraging a logging implementation would be sufficient while doing related logic, such as writing to the log, on page Unload().
Upvotes: 0
Reputation: 13571
Besides using a logging framework you could use the tracing you need by using the ASP.nets out of the box tracing and diagnostic features [http://msdn.microsoft.com/en-us/library/bb386420.aspx] or you could use something like elmah for other needs. Try not to re-invent the wheel but make a car out of it that flies. Good luck!!
Upvotes: 1
Reputation: 39248
I would use a logging framework like log4net etc... Especially since you're only doing it for debug mode. You can define warning levels to match your loading speeds if something is slower than expected...
Upvotes: 1