<p>In <a href="http://www.codinghorror.com/blog/archives/001152.html" rel="nofollow noreferrer">Maybe Normalizing Isn't Normal</a> Jeff Atwood says, "You're automatically measuring all the queries that flow through your software, right?"  I'm not but I'd like to.  </p>

<p>Some features of the application in question:</p>

<ul>
<li>ASP.NET</li>
<li>a data access layer which depends on the <a href="http://msdn.microsoft.com/en-us/library/cc309504.aspx" rel="nofollow noreferrer">MS Enterprise Library Data Access Application Block</a></li>
<li>MS SQL Server</li>
</ul>

[{'answer_id': 10605, 'author': 'Brad Leach', 'author_id': 708, 'author_profile': 'https://Stackoverflow.com/users/708', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms181091.aspx" rel="nofollow noreferrer">SQL Profiler</a> is the tool I use to monitor traffic flowing to my SQL Server. It allows you to gather detailed data about your SQL Server. SQL Profiler has been distributed with SQL Server since at least SQL Server 2000 (but probably before that also).</p>\n\n<p>Highly recommended.</p>\n'}, {'answer_id': 10617, 'author': 'Jeff Atwood', 'author_id': 1, 'author_profile': 'https://Stackoverflow.com/users/1', 'pm_score': 4, 'selected': True, 'text': "<p>In addition to Brad's mention of SQL Profiler, if you want to do this in code, then <strong>all your database calls need to funnelled through a common library</strong>. You insert the timing code there, and voila, you know how long every query in your system takes.</p>\n\n<p>A single point of entry to the database is a fairly standard feature of any ORM or database layer -- or at least it has been in any project I've worked on so far!</p>\n"}, {'answer_id': 10648, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>The <a href="http://www.codeplex.com/dropthings" rel="nofollow noreferrer">Dropthings</a> project on CodePlex has a class for timing blocks of code.\nThe class is named TimedLog.  It implements IDisposable. You wrap the block of code you wish to time in a using statement.</p>\n'}, {'answer_id': 10685, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 0, 'selected': False, 'text': "<p>If you use rails it automatically logs all the SQL queries, and the time they took to execute, in your development log file.</p>\n\n<p>I find this very useful because if you do see one that's taking a while, it's one step to just copy and paste it straight off the screen/logfile, and put 'explain' in front of it in mysql.</p>\n\n<p>You don't have to go digging through your code and reconstruct what's happening.</p>\n\n<p>Needless to say this doesn't happen in production as it'd run you out of disk space in about an hour.</p>\n"}, {'answer_id': 10783, 'author': 'Jon Galloway', 'author_id': 5, 'author_profile': 'https://Stackoverflow.com/users/5', 'pm_score': 1, 'selected': False, 'text': '<p>Take a look at this chapter Jeff Atwood and I wrote about performance optimizations for websites. We cover a lot of stuff, but there\'s a lot of stuff about database tracing and optimization:\n<a href="http://www.sitepoint.com/article/aspnet-performance-tips" rel="nofollow noreferrer">Speed Up Your Site: 8 ASP.NET Performance Tips</a></p>\n'}, {'answer_id': 556485, 'author': 'Sam Saffron', 'author_id': 17174, 'author_profile': 'https://Stackoverflow.com/users/17174', 'pm_score': 0, 'selected': False, 'text': '<p>If you define a factory that creates SqlCommands for you and always call it when you need a new command, you can return a <a href="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.proxies.realproxy.aspx" rel="nofollow noreferrer">RealProxy</a> to an SqlCommand. </p>\n\n<p>This proxy can then measure how long ExecuteReader / ExecuteScalar etc. take using a StopWatch and log it somewhere. The advantage to using this kind of method over Sql Server Profiler is that you can get full stack traces for each executed piece of SQL. </p>\n'}]
['https://Stackoverflow.com/questions/10604', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/150/']