June 5, 2017 at 6:03 pm
Good Morning Experts,
I am finding top CPU queries using SSMS(Reports->Standard Reports->Performance-Top Queries by Total CPU Time) .This is giving me the queries, but not the SPID of the query. I want to know SPID of the query. How can I get the SPID?
June 5, 2017 at 6:51 pm
the items are from cache, and are not the currently running as of this moment queries; the users could have disconnected long ago. you also get an execution count, so you can see how many times it was executed, so it's not per user/spid.
all those items related to performance are what is in the cache, and were slow, or used the most CPU, etc according to the DMV's
Lowell
June 7, 2017 at 6:35 am
If you want to see what's currently happening, look to the Activity - All Sessions or Activity - Top Sessions reports. They're querying sys.dm_exec_requests (and other Dynamic Management Views) to retrieve active information. You can also learn how to query the DMVs yourself to gather this data. It's a very useful skill set to have.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 7, 2017 at 6:52 am
Why do you want the session_id?
The point of that report is to identify queries that need tuning to reduce their CPU usage.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 7, 2017 at 7:01 am
GilaMonster - Wednesday, June 7, 2017 6:52 AMWhy do you want the session_id?The point of that report is to identify queries that need tuning to reduce their CPU usage.
Hi Gail,
I want the SPID so that I can get to know the database name,login, program name etc.
June 7, 2017 at 7:17 am
coolchaitu - Wednesday, June 7, 2017 7:01 AMHi Gail,
I want the SPID so that I can get to know the database name,login, program name etc.
The query itself is going to show you which database is being used, so you can get that name from there.
Otherwise, as Lowell has already pointed out, that data is aggregated performance metrics taken from the queries that are currently in cache. It won't show individual calls including connection information.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 13, 2017 at 7:02 am
GilaMonster - Wednesday, June 7, 2017 6:52 AMWhy do you want the session_id?The point of that report is to identify queries that need tuning to reduce their CPU usage.
Hi Gail,
I am looking for queries that are consuming high CPU. I am getting confused. We have sysprocesses table, sys.dm_exec_requests DMV, sys.dm_exec_query_stats DMV that has cpu info. Which one to use? Which one returns correct information?
June 13, 2017 at 7:26 am
Depends whether you're interested in how long a single execution of a query takes, or in its total load on the processor over time. What's worse, the report that takes 10 minutes but only runs monthly, or the stored procedure that completes in half a second but runs 100 times a minute?
John
June 13, 2017 at 7:31 am
coolchaitu - Tuesday, June 13, 2017 7:16 AMJohn Mitchell-245523 - Tuesday, June 13, 2017 7:08 AMSee this. You'll want to order by total_worker_time.John
Shouldnt it be total_worker_time/execution_count?
No. The average CPU usage is not going to tell you what queries are consuming the most CPU.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 13, 2017 at 7:33 am
The DMV sys.dm_exec_requests will return one row for each active session / request. The column [total_elapsed_time] contains the total milliseconds since the request started, and by constrast the column [cpu_time] is the total milliseconds of CPU processing time consumed by the request. You can refer to [cpu_time] as an indicator for which currently running SPIDs are consuming the most CPU. For single threaded executions, CPU time will typically be less than elapsed time due to time spent in various wait states (ie: CXPACKET or blocking). For multi-threaded executions, CPU time may be greater than elapsed time, because there are 2 or more CPU doing work in parallel.
You can also join sys.dm_exec_sessions on [session_id] to get login name, client IP address, etc.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
June 13, 2017 at 7:39 am
John Mitchell-245523 - Tuesday, June 13, 2017 7:26 AMDepends whether you're interested in how long a single execution of a query takes, or in its total load on the processor over time. What's worse, the report that takes 10 minutes but only runs monthly, or the stored procedure that completes in half a second but runs 100 times a minute?John
Got it John. Thanks a lot.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply