Jawaban:
Anda bisa mendapatkan ini (dan lebih banyak lagi) dari Dynamic Management Views (DMVs). Untuk mendapatkan statistik untuk prosedur tersimpan tertentu, coba kueri berikut.
SELECT
OBJECT_NAME(qt.objectid)
, qs.execution_count AS [Execution Count]
, qs.execution_count / DATEDIFF(Second, qs.creation_time, GETDATE()) AS [Calls/Second]
, qs.total_worker_time / qs.execution_count AS [AvgWorkerTime]
, qs.total_worker_time AS [TotalWorkerTime]
, qs.total_elapsed_time / qs.execution_count AS [AvgElapsedTime]
, qs.max_logical_reads
, qs.max_logical_writes
, qs.total_physical_reads
, DATEDIFF(Minute, qs.creation_time, GETDATE()) AS [Age in Cache]
FROM
sys.dm_exec_query_stats AS qs
CROSS APPLY
sys.dm_exec_sql_text(qs.[sql_handle]) AS qt
WHERE
qt.[dbid] = DB_ID()
AND qt.objectid = OBJECT_ID('StoredProcedureName')
OPTION (RECOMPILE);
Untuk melihat prosedur yang paling sering dilakukan:
SELECT
OBJECT_NAME(qt.objectid)
, qs.execution_count AS [Execution Count]
, qs.execution_count / DATEDIFF(Second, qs.creation_time, GETDATE()) AS [Calls/Second]
, qs.total_worker_time / qs.execution_count AS [AvgWorkerTime]
, qs.total_worker_time AS [TotalWorkerTime]
, qs.total_elapsed_time / qs.execution_count AS [AvgElapsedTime]
, qs.max_logical_reads
, qs.max_logical_writes
, qs.total_physical_reads
, DATEDIFF(Minute, qs.creation_time, GETDATE()) AS [Age in Cache]
FROM
sys.dm_exec_query_stats AS qs
CROSS APPLY
sys.dm_exec_sql_text(qs.[sql_handle]) AS qt
WHERE
qt.[dbid] = DB_ID()
ORDER BY
qs.execution_count DESC
OPTION (RECOMPILE);
Nilai yang dilaporkan adalah kumulatif sejak restart terakhir. Jika Anda ingin mengukur selama periode yang tetap, gunakan perintah di bawah ini untuk mengatur ulang statistik tunggu.
DBCC SQLPERF("sys.dm_os_wait_stats",CLEAR);
Jika Anda ingin mengukur rentang waktu tetap sepanjang hari, Anda bisa mengumpankan output permintaan ke tabel melalui pekerjaan agen dan baik a) menghitung nilai antara dua berjalan atau b) mengeluarkan statistik tunggu direset sebagai langkah terakhir dalam pekerjaan agen .
Atau, ambil jejak profiler dan jalankan melalui Clear Trace .