views:

363

answers:

2

I have a web app that creates a DataContext at the beginning of the request and lets go at the end.

I would like to have some handy stats for each page like
- number of inserts and time spent
- number of deletes and time spent
- number of updates and time spent
- number of selects and time spent

I have it all set for inserts/updates/deletes by implementing the partial methods InsertXXX/UpdateXXX/DeleteXXX and keeping track of counts and time spent.

But, how do I count and time the SELECTs ???

I am not sure there is a hook anywhere in Linq to SQL to be able to insert some measuring?

Thanks

+1  A: 

If you're interesting in the db-side statistics; time spent compiling and executing queries, I/O, execution plans etc - take a look at my Linq-to-SQL profiler: http://www.huagati.com/L2SProfiler/

KristoferA - Huagati.com
A: 

To get an idea of how long each of the queries you are running is taking, you can run the SQL Profiler on the database you are working with. You can use the Query Execution Plan to narrow down any performance iussues.

If you need to integrate this more closely with your repository/data access code, you could use the Stopwatch class to time the execution of your Linq-to-SQL methods.

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

Rhys Jones