Warning: Constant WP_TEMP_DIR already defined in /var/www/html/blogs/glenn/wp-config.php on line 94

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/feed-rss2-comments.php on line 8
Comments on: SQL Server Diagnostic Information Queries for February 2019 https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/ Semi-random musings about SQL Server performance Tue, 26 Feb 2019 19:56:00 +0000 hourly 1 https://wordpress.org/?v=6.9.4 By: Grzegorz Wołoszyn https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/#comment-265099 Tue, 26 Feb 2019 19:56:00 +0000 http://3.209.169.194/blogs/glenn/?p=1487#comment-265099 In reply to Glenn Berry.

WITH DB_CPU_Stats
AS
(SELECT pa.DatabaseID, DB_Name(pa.DatabaseID) AS [Database Name], SUM(qs.total_worker_time/1000) AS [CPU_Time_Ms]
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY (SELECT CONVERT(int, value) AS [DatabaseID]
FROM sys.dm_exec_plan_attributes(qs.plan_handle)
WHERE attribute = N’dbid’) AS pa
GROUP BY DatabaseID)
SELECT ROW_NUMBER() OVER(ORDER BY [CPU_Time_Ms] DESC) AS [CPU Rank],
[Database Name], [CPU_Time_Ms] AS [CPU Time (ms)],
CAST([CPU_Time_Ms] * 1.0 / SUM([CPU_Time_Ms]) OVER() * 100.0 AS DECIMAL(5, 2)) AS [CPU Percent]
FROM DB_CPU_Stats
WHERE DatabaseID 32767 — ResourceDB
ORDER BY [CPU Rank] OPTION (RECOMPILE);

on SQL Server 2012.

Example query return:

1 4122760 48.12
2 698825 8.16
3 366716 4.28
4 225181 2.63
5 189481 2.21
6 168764 1.97
7 165586 1.93
8 162245 1.89
9 160038 1.87
10 125754 1.47
11 117338 1.37
12 112374 1.31
13 101302 1.18
14 77422 0.90
15 75807 0.88
16 69983 0.82
17 68913 0.80
18 62744 0.73
19 60981 0.71
20 58789 0.69
21 52464 0.61
22 43531 0.51
23 42549 0.50
24 41085 0.48
25 39204 0.46
26 37351 0.44
27 36043 0.42
28 31864 0.37
29 31555 0.37
30 31202 0.36
31 29249 0.34
32 28182 0.33
33 27638 0.32
34 26152 0.31
35 25743 0.30
36 25332 0.30
37 25205 0.29
38 25008 0.29
39 23854 0.28
40 23353 0.27
41 22938 0.27
42 22406 0.26
43 22113 0.26
44 21788 0.25
45 20785 0.24
46 20611 0.24
47 20595 0.24
48 19367 0.23
49 18894 0.22
50 18767 0.22
51 18468 0.22
52 16354 0.19
53 15043 0.18
54 14877 0.17
55 14780 0.17
56 13837 0.16
57 13736 0.16
58 12843 0.15
59 12745 0.15
60 12020 0.14
61 11893 0.14
62 11709 0.14
63 11511 0.13
64 11177 0.13
65 11090 0.13
66 10956 0.13
67 10296 0.12
68 10096 0.12
69 9909 0.12
70 9773 0.11
71 9579 0.11
72 9355 0.11
73 8571 0.10
74 8558 0.10
75 8403 0.10
76 8111 0.09
77 7935 0.09
78 7682 0.09
79 7543 0.09
80 7360 0.09
81 7322 0.09
82 7005 0.08
83 6587 0.08
84 6238 0.07
85 6196 0.07
86 5331 0.06
87 5273 0.06
88 5011 0.06
89 4966 0.06
90 4382 0.05
91 4113 0.05
92 3787 0.04
93 3768 0.04
94 3761 0.04
95 3754 0.04
96 3520 0.04
97 3478 0.04
98 3434 0.04
99 3335 0.04
100 3135 0.04
101 3113 0.04
102 2996 0.03
103 2643 0.03
104 2569 0.03
105 2393 0.03
106 2277 0.03
107 2265 0.03
108 2243 0.03
109 2046 0.02
110 1961 0.02
111 1906 0.02
112 1870 0.02
113 1710 0.02
114 1697 0.02
115 1624 0.02
116 1598 0.02
117 1478 0.02
118 1459 0.02
119 1441 0.02
120 1395 0.02
121 1388 0.02
122 1362 0.02
123 1339 0.02
124 1302 0.02
125 1268 0.01
126 1218 0.01
127 1211 0.01
128 1198 0.01
129 1123 0.01
130 1119 0.01
131 1012 0.01
132 997 0.01
133 969 0.01
134 960 0.01
135 941 0.01
136 887 0.01
137 879 0.01
138 839 0.01
139 836 0.01
140 759 0.01
141 756 0.01
142 730 0.01
143 729 0.01
144 695 0.01
145 642 0.01
146 621 0.01
147 601 0.01
148 600 0.01
149 595 0.01
150 578 0.01
151 560 0.01
152 528 0.01
153 513 0.01
154 477 0.01
155 459 0.01
156 458 0.01
157 449 0.01
158 446 0.01
159 437 0.01
160 436 0.01

(without DB name) where sum of CPU usage column is about 100% and Windows task manager is showing about 30-50%. I’ve started wondering if somehow this 100% of query return is this 30% of current usage in system somehow (so 1% in CPU query is somehow 1/3 of % in task manager – 100% in query 30% in task manager)

]]>
By: Glenn Berry https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/#comment-265067 Tue, 26 Feb 2019 15:45:11 +0000 http://3.209.169.194/blogs/glenn/?p=1487#comment-265067 Which diagnostic query are you looking at to get “CPU usage generated by query”? Also, which version of SQL Server are you using?

]]>
By: Grzegorz Wołoszyn https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/#comment-265045 Tue, 26 Feb 2019 11:43:59 +0000 http://3.209.169.194/blogs/glenn/?p=1487#comment-265045 Hello,

I’m wondering how CPU usage generated by query can be connected with sql server process CPU usage in system (CPU usage visible in Task Manager). For example I have database which CPU usage generated by query shows almost 80% but CPU usage of SQL Server process is about 17-20%. Any suggestions?

Thanks

]]>
By: Glenn Berry https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/#comment-264983 Mon, 25 Feb 2019 23:43:34 +0000 http://3.209.169.194/blogs/glenn/?p=1487#comment-264983 In reply to Gopalakrishnan Arthanarisamy.

I am glad that you find them useful!

]]>
By: Gopalakrishnan Arthanarisamy https://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-february-2019/#comment-261674 Sat, 02 Feb 2019 09:39:03 +0000 http://3.209.169.194/blogs/glenn/?p=1487#comment-261674 Thanks a lot Glenn Berry for continuously updating these scripts.

Regards,
Gopal

]]>