Ms Sql扩展事件过程在程序中

问题描述 投票:0回答:1

我有一个程序,执行另外两个程序,如下所示:

ALTER PROCEDURE [tmp].[Test] (@SessionId INT)

BEGIN
    EXEC [tmp].[Test1] @SessionId = @SessionId

    EXEC [tmp].[Test2] @SessionId = @SessionId
END

然后,执行[tmp].[Test]程序,我想显示sys.fn_xe_file_target_read_file的信息也用于这些内部程序。

我创建了这样的东西:

SELECT event_name
    ,cpu_time
    ,duration
    ,logical_reads
    ,physical_reads
    ,writes
    ,statement
    ,plan_handle
    ,show_plan
    ,*
FROM (
    SELECT event_data.value('(event/@name)[1]', 'varchar(50)') AS event_name
        ,event_data.value('(event/action[@name="plan_handle"]/value)[1]', 'varchar(max)') AS plan_handle
        ,event_data.query('event/data[@name="showplan_xml"]/value/*') AS show_plan
        ,event_data.value('(event/data[@name="cpu_time"]/value)[1]', 'int') AS cpu_time
        ,event_data.value('(event/data[@name="duration"]/value)[1]', 'int') AS duration
        ,event_data.value('(event/data[@name="logical_reads"]/value)[1]', 'int') AS logical_reads
        ,event_data.value('(event/data[@name="physical_reads"]/value)[1]', 'int') AS physical_reads
        ,event_data.value('(event/data[@name="writes"]/value)[1]', 'int') AS writes
        ,event_data.value('(event/data[@name="statement"]/value)[1]', 'varchar(max)') AS statement
        ,event_data.value('(event/action[@name="sql_text"]/value)[1]', 'varchar(max)') AS sql_text
        ,*
    FROM (
        SELECT cast(event_data AS XML)
        FROM sys.fn_xe_file_target_read_file('E:\Pulpit\test_0_131645809565380000.xel', NULL, NULL, NULL)
        ) AS xevent(event_data)
    ) t

但它只返回[tmp].[Test]的结果。我怎样才能得到[tmp].[Test2][tmp].[Test1]的结果?

sql-server tsql extended-events
1个回答
0
投票
SELECT cast(event_data AS XML)
FROM sys.fn_xe_file_target_read_file('E:\Pulpit\test_0_131645809565380000.xel', NULL, NULL, NULL)

UNION

SELECT cast(event_data AS XML)
FROM sys.fn_xe_file_target_read_file('E:\Pulpit\test_1_131645809565380000.xel', NULL, NULL, NULL)

UNION

SELECT cast(event_data AS XML)
FROM sys.fn_xe_file_target_read_file('E:\Pulpit\test_2_131645809565380000.xel', NULL, NULL, NULL)
© www.soinside.com 2019 - 2024. All rights reserved.