如何计算查询执行或存储过程的CPU时间?

问题描述 投票:0回答:2

我正在研究 SQL SERVER 2008 R2 性能调整部分,但我是新手。

如何计算:

  • CPU使用时间
  • 逻辑读取

等等。由查询或存储过程创建。

有人可以帮我吗?

sql-server-2008 sql-server-2008-r2
2个回答
3
投票

抓取Plan Explorer(免费),输入您的 EXEC 调用或查询,并生成实际的执行计划。您将获得各种有趣的指标,包括 CPU 和 I/O。除了比 Management Studio 中更可用的计划之外。

(免责声明:我曾经在 SQL Sentry 工作。)


3
投票

SET STATISTICS IO
SET STATISTICS TIME
是两个设置,可以帮助您测量存储过程查询的执行情况..

SET STATISTICS IO
显示查询生成的磁盘活动量的统计信息。
SET STATISTICS TIME
显示解析、编译和执行查询中每个语句所需的时间。

USE <Your Database>;
GO       
SET STATISTICS IO ON;
SET STATISTICS TIME ON;
GO
SELECT * 
FROM YourTable
WHERE KeyValue > 1200
GO
SET STATISTICS IO OFF;
SET STATISTICS TIME OFF;
GO

可能的结果

Table 'YourTable'. Scan count 1, logical reads 5, physical 
reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, 
lob read-ahead reads 0.


SQL Server parse and compile time: 
   CPU time = 0 ms, elapsed time = 1 ms.
SQL Server parse and compile time: 
   CPU time = 0 ms, elapsed time = 1 ms.

(269 row(s) affected)

SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 2 ms.
SQL Server parse and compile time: 
   CPU time = 0 ms, elapsed time = 1 ms.
© www.soinside.com 2019 - 2024. All rights reserved.