Solved

SQL Server Query - Log Stats

Posted on 2014-10-14
4
129 Views
Last Modified: 2014-10-16
I want to come up with some way that I can collect and save certain statistics at both the start and end of a query.
I know I can query master.dbo.sysprocesses and get cpu time and physical_ios but I'd like to be able to break io into physical and logical and reads vs. writes. I would log results of whatever method is used to get a snapshot of the required data at the start of the query and the end.

For example, the value of cpu at the end of the query minus the value of cpu at the start should be the total cpu time used for my query. The stats I can think of that I would like to collect are cpu time, reads, writes (physical and logical), and perhaps total wait time.
0
Comment
Question by:dbbishop
  • 2
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
Comment Utility
You can get I/O statistics from
SET STATISTICS IO ON

Be aware, though, that physical I/O could vary because it depends on SQL buffer contents.

You could also capture results from
sys.dm_db_index_operational_stats
before and after the statement(s), and delta them, to get more detailed I/O.  Of course if other statements are using the same tables their I/O would be included in those totals also.
0
 
LVL 15

Author Comment

by:dbbishop
Comment Utility
This will be running on a development server and will be the only activity against the database, and likely on the server.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Then the stats in the view should accurately reflect your activity.
0
 
LVL 15

Author Closing Comment

by:dbbishop
Comment Utility
thx
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now