適用於:Analytics Platform System (PDW)
診斷會話允許您儲存詳細且由使用者定義的系統或查詢效能診斷資訊。
診斷會話通常用於除錯特定查詢的效能,或監控特定設備元件在運作期間的行為。
Note
你應該熟悉 XML 才能使用診斷會話。
Syntax
-- Creating a new diagnostics session:
CREATE DIAGNOSTICS SESSION diagnostics_name AS N' { <session_xml> } ';
<session_xml>::
<Session>
[ <MaxItemCount>max_item_count_num</MaxItemCount> ]
[ <Filter>
{ <Event Name = "event_name"/>
[ <Where><filter_property_name Name = "value" ComparisonType = "comp_type"/></Where> ] [ , ...n ]
} [ , ...n ]
</Filter> ]
<Capture>
<Property Name = "property_name"/> [ , ...n ]
</Capture>
<Session>
-- Retrieving results for a diagnostics session:
SELECT * FROM master.sysdiag.diagnostics_name ;
-- Removing results for a diagnostics session:
DROP DIAGNOSTICS SESSION diagnostics_name ;
引數
diagnostics_name
診斷會話的名稱。 診斷會話名稱僅包含 a-z、A-Z 及 0-9 字元。 此外,診斷會話名稱必須以角色開頭。 diagnostics_name 字元限制為127個字元。
max_item_count_num
一個視圖中要持續存在的事件數量。 例如,若指定 100,則最近符合篩選條件的 100 個事件會持續存在於診斷會話中。 若匹配事件少於 100 個,診斷會話中事件少於 100 個。 max_item_count_num 必須至少100且不等於100,000。
event_name
定義診斷會話中要收集的實際事件。
event_name 是 sys.pdw_diag_events 中列出的事件之一,其中 sys.pdw_diag_events.is_enabled='True'。
filter_property_name
限制結果的財產名稱。 例如,如果你想根據會話 ID 來限制, filter_property_name 應該是 SessionId。 請參閱 property_name 論證,列出 filter_property_name的潛在值。
價值
這是值得與 filter_property_name比較的價值。 價值類型必須與物業類型相符。 例如,若屬性類型為十進位, 則值 的類型必須為十進位。
comp_type
比較類型。 潛在值為:Equals、EqualsOrGreaterThan、EqualsOrLessThan、RegExGreaterThanLessThanNotEqualsContains和。
property_name
與該事件相關的房產。 屬性名稱可以作為擷取標籤的一部分,或作為篩選條件的一部分。
| 屬性名稱 | Description |
|---|---|
UserName |
一個使用者(登入)名稱。 |
SessionId |
一個會話ID。 |
QueryId |
查詢ID。 |
CommandType |
一種命令類型。 |
CommandText |
指令內的文字已處理。 |
OperationType |
該事件的操作類型。 |
Duration |
活動持續時間。 |
SPID |
會話識別碼。 |
Remarks
每位使用者最多可同時進行 10 次診斷會話。 請參閱sys.pdw_diag_sessions查看你目前的會話清單,並用 刪除任何不需要的會話。DROP DIAGNOSTICS SESSION
診斷會話會持續收集元資料直到被丟棄為止。
Permissions
需要 ALTER SERVER STATE 權限。
鎖定
這會讓診斷會議桌上有共用鎖。
Examples
A. 建立診斷會話
此範例建立診斷會話以記錄資料庫引擎效能的指標。 範例中會建立一個診斷會話,監聽引擎查詢的執行/結束事件以及阻擋 DMS 事件。 回傳的是指令文字、機器名稱、請求 ID(查詢 ID)以及事件所建立的會話。
CREATE DIAGNOSTICS SESSION MYDIAGSESSION AS N'
<Session>
<MaxItemCount>100</MaxItemCount>
<Filter>
<Event Name="EngineInstrumentation:EngineQueryRunningEvent" />
<Event Name="DmsCoreInstrumentation:DmsBlockingQueueEnqueueBeginEvent" />
<Where>
<SessionId Value="381" ComparisonType="NotEquals" />
</Where>
</Filter>
<Capture>
<Property Name="Query.CommandText" />
<Property Name="MachineName" />
<Property Name="Query.QueryId" />
<Property Name="Alias" />
<Property Name="Duration" />
<Property Name="Session.SessionId" />
</Capture>
</Session>';
建立診斷會話後,執行查詢。
SELECT COUNT(EmployeeKey)
FROM AdventureWorksPDW2012..FactSalesQuota;
然後從 sysdiag 架構中選擇診斷會話結果。
SELECT * FROM master.sysdiag.MYDIAGSESSION;
sysdiag 架構中有一個檢視,名稱為你的診斷會話名稱。
若要只看到你連線的活動,請新增 Session.SPID 屬性並加到 WHERE [Session.SPID] = @@spid; 查詢中。
診斷結束後,用指令 DROP DIAGNOSTICS 把它丟掉。
DROP DIAGNOSTICS SESSION MYDIAGSESSION;
B. 替代診斷會話
第二個例子性質略有不同。
-- Determine the session_id of your current session
SELECT TOP 1 session_id();
-- Replace <session_number> in the code below with the numbers in your session_id
CREATE DIAGNOSTICS SESSION PdwOptimizationDiagnostics AS N'
<Session>
<MaxItemCount>100</MaxItemCount>
<Filter>
<Event Name="EngineInstrumentation:MemoGenerationBeginEvent" />
<Event Name="EngineInstrumentation:MemoGenerationEndEvent" />
<Event Name="DSQLInstrumentation:OptimizationBeginEvent" />
<Event Name="DSQLInstrumentation:OptimizationEndEvent" />
<Event Name="DSQLInstrumentation:BuildRelOpContextTreeBeginEvent" />
<Event Name="DSQLInstrumentation:PostPlanGenModifiersEndEvent" />
<Where>
<SessionId Value="<session_number>" ComparisonType="Equals" />
</Where>
</Filter>
<Capture>
<Property Name="Session.SessionId" />
<Property Name="Query.QueryId" />
<Property Name="Query.CommandText" />
<Property Name="Name" />
<Property Name="DateTimePublished" />
<Property Name="DateTimePublished.Ticks" />
</Capture>
</Session>';
執行一個查詢,例如:
USE ssawPDW;
GO
SELECT * FROM dbo.FactFinance;
以下查詢會回傳授權時序:
SELECT *
FROM master.sysdiag.PdwOptimizationDiagnostics
ORDER BY DateTimePublished;
診斷結束後,用指令 DROP DIAGNOSTICS 把它丟掉。
DROP DIAGNOSTICS SESSION PdwOptimizationDiagnostics;