SELECT
dxo.name,
'Category' = camv.map_value,
'Channel' = chmv.map_value
FROM sys.dm_xe_objects AS dxo
LEFT JOIN sys.dm_xe_object_columns AS cac ON 1=1
AND cac.object_package_guid = dxo.package_guid
AND cac.object_name = dxo.name
AND cac.name = 'KEYWORD'
LEFT JOIN sys.dm_xe_map_values AS camv ON 1=1
AND camv.object_package_guid = cac.type_package_guid
AND camv.name = cac.type_name
AND camv.map_key = cac.column_value
JOIN sys.dm_xe_object_columns AS chc ON 1=1
AND chc.object_package_guid = dxo.package_guid
AND chc.object_name = dxo.name
AND chc.name = 'CHANNEL'
JOIN sys.dm_xe_map_values AS chmv ON 1=1
AND chmv.object_package_guid = chc.type_package_guid
AND chmv.name = chc.type_name
AND chmv.map_key = chc.column_value
WHERE 1=1
AND dxo.object_type = 'event'
AND chmv.map_value <> 'Debug'
ORDER BY
dxo.name
DMV中提供了该信息
sys.dm_xe_*
,但我很难找到它。sys.dm_xe_object_columns
每个事件在DMV中都有一个特殊的只读列,称为“CHANNEL” 。该列的类型为“etw_channel”,其值在column_value
DMV 的列中。可以在 DMV 中查找该列的值sys.dm_xe_map_values
以获取频道名称。可以用类似的方式检索类别,但有两个问题:只读列称为“KEYWORD”,并且 27 列(至少在 SQL Server 2014 中)没有该列。
下面的查询演示了如何获取信息。特别是,它返回的信息与您在第一次选择事件时在 GUI 中看到的信息相同。事件按名称排序,“调试”频道的事件被过滤掉,其中 27 个事件属于 NULL 类别。