{"id":452511,"date":"2025-03-21T03:00:13","date_gmt":"2025-03-21T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=452511"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=452511","title":{"rendered":"<span>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 Flame Chart \u0434\u043b\u044f MSSQL<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 TSQL \u043c\u043d\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 stored procedures, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &#171;flame chart&#187; &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bd3\/c0b\/84c\/bd3c0b84c4a78a25aead9b3b15fca4b5.png\" width=\"511\" height=\"308\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bd3\/c0b\/84c\/bd3c0b84c4a78a25aead9b3b15fca4b5.png\"\/><\/figure>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u0432\u0441\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0435\u0439\u0441\u0430<\/h2>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 SQL profiler \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u0442\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>SP:Starting<\/p>\n<\/li>\n<li>\n<p>SP:Completed<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>ObjectName<\/p>\n<\/li>\n<li>\n<p>NestLevel<\/p>\n<\/li>\n<li>\n<p>StartTime<\/p>\n<\/li>\n<li>\n<p>EndTime<\/p>\n<\/li>\n<li>\n<p>Spid<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0445 \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u043e Spid \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e &#8212; \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e. \u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0438\u0441\u0430\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0442\u0440\u0435\u0439\u0441 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">create procedure flame   @trname sysname, @spname sysname, @start int=0 as   -- Trace must contain Sp:Start, Sp:Completed, StartTime, EndTime, Nestlevel, ObjectName   -- 1 SPID should be recorded   set nocount on   declare @r int, @b int, @e int, @t datetime, @class int, @lev int, @obj varchar(255), @prevt datetime,      @stack varchar(max)='', @prevstack varchar(max)='', @sql varchar(1000)   create table #trace (RowNumber int, EventClass int, StartTime datetime, EndTime datetime, NestLevel int, ObjectName nvarchar(255))   set @sql = 'insert into #trace select RowNumber,EventClass,StartTime,EndTime,Nestlevel,ObjectName from '+@trname+' where EventClass in (42,43)'   exec (@sql)   select (select max(RowNumber) from #trace I where I.EventClass=42 and I.ObjectName=@spname and I.Nestlevel=1 and I.RowNumber&lt;O.RowNumber) as [Start],     O.RowNumber as [End], StartTime, EndTime, datediff(ms, StartTime, endTime) as DurationMs     from #trace O where EventClass=43 and ObjectName=@spname and Nestlevel=1     order by 1   select @b=min(RowNumber) from #trace where EventClass=42 and ObjectName=@spname and NestLevel=1 and RowNumber&gt;=@start   if @b is null begin print 'procedure: start not found' return end   select @e=min(RowNumber) from #trace where EventClass=43 and ObjectName=@spname and RowNumber&gt;@b and Nestlevel=1   if @e is null begin print 'procedure: end not found' return end   select 'Selected', @b as [Start], @e as [End]   DECLARE my_cur CURSOR FOR SELECT RowNumber,EventClass,isnull(EndTime,StartTime),NestLevel,ObjectName      from #trace where RowNumber&gt;=@b and RowNumber&lt;=@e order by RowNumber   OPEN my_cur   FETCH NEXT FROM my_cur INTO @r, @class, @t, @lev, @obj   WHILE @@FETCH_STATUS = 0   BEGIN     if @class=42 set @stack = @stack + ';' + @obj else set @stack=reverse(substring(reverse(@stack),charindex(';', reverse(@stack))+1,100000)) if @prevt is not null print substring(@prevstack,2,100000)+' '+convert(varchar,datediff(ms,@prevt,@t)) set @prevt=@t set @prevstack=@stack     FETCH NEXT FROM my_cur INTO @r, @class, @t, @lev, @obj   END   CLOSE my_cur   DEALLOCATE my_cur GO<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 <strong>flame <\/strong>\u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0442\u0440\u0435\u0439\u0441\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0438\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b. \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 (NestLevel=1). \u0418\u043c\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a \u0438 \u0441\u0445\u0435\u043c\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e [dbo].[myProc] \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c myProc<\/p>\n<\/li>\n<li>\n<p>\u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u0435\u043d, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0438\u0445 \u043c\u043d\u043e\u0433\u043e<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df0\/284\/1c3\/df02841c35dd185115981e3c6df25113.png\" width=\"556\" height=\"398\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df0\/284\/1c3\/df02841c35dd185115981e3c6df25113.png\"\/><\/figure>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d RowNumber, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u0440\u0435\u043c\u0435\u043d \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 Start \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f 9\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 10574<\/p>\n<h2>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b<\/h2>\n<p>\u0423\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0443 <strong>Messages <\/strong>\u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b, \u0443\u0434\u0430\u043b\u0438\u0432 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e9a\/69b\/1c1\/e9a69b1c1b1ea8f70e8534bea2312615.png\" width=\"349\" height=\"46\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e9a\/69b\/1c1\/e9a69b1c1b1ea8f70e8534bea2312615.png\"\/><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 <a href=\"https:\/\/www.speedscope.app\" rel=\"noopener noreferrer nofollow\">https:\/\/www.speedscope.app<\/a> \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0444\u0430\u0439\u043b. \u0413\u043e\u0442\u043e\u0432\u043e.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f0d\/3dd\/fc7\/f0d3ddfc7cbcefd5d1509f5cd05e5d7a.png\" width=\"511\" height=\"308\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f0d\/3dd\/fc7\/f0d3ddfc7cbcefd5d1509f5cd05e5d7a.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/892876\/\"> https:\/\/habr.com\/ru\/articles\/892876\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 TSQL \u043c\u043d\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 stored procedures, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &#171;flame chart&#187; &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<figure class=\"\"><\/figure>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u043f\u043e \u0448\u0430\u0433\u0430\u043c \u0432\u0441\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0440\u0435\u0439\u0441\u0430<\/h2>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 SQL profiler \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u0442\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>SP:Starting<\/p>\n<\/li>\n<li>\n<p>SP:Completed<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>ObjectName<\/p>\n<\/li>\n<li>\n<p>NestLevel<\/p>\n<\/li>\n<li>\n<p>StartTime<\/p>\n<\/li>\n<li>\n<p>EndTime<\/p>\n<\/li>\n<li>\n<p>Spid<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0445 \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u043e Spid \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e &#8212; \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e. \u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0438\u0441\u0430\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0442\u0440\u0435\u0439\u0441 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">create procedure flame   @trname sysname, @spname sysname, @start int=0 as   -- Trace must contain Sp:Start, Sp:Completed, StartTime, EndTime, Nestlevel, ObjectName   -- 1 SPID should be recorded   set nocount on   declare @r int, @b int, @e int, @t datetime, @class int, @lev int, @obj varchar(255), @prevt datetime,      @stack varchar(max)='', @prevstack varchar(max)='', @sql varchar(1000)   create table #trace (RowNumber int, EventClass int, StartTime datetime, EndTime datetime, NestLevel int, ObjectName nvarchar(255))   set @sql = 'insert into #trace select RowNumber,EventClass,StartTime,EndTime,Nestlevel,ObjectName from '+@trname+' where EventClass in (42,43)'   exec (@sql)   select (select max(RowNumber) from #trace I where I.EventClass=42 and I.ObjectName=@spname and I.Nestlevel=1 and I.RowNumber&lt;O.RowNumber) as [Start],     O.RowNumber as [End], StartTime, EndTime, datediff(ms, StartTime, endTime) as DurationMs     from #trace O where EventClass=43 and ObjectName=@spname and Nestlevel=1     order by 1   select @b=min(RowNumber) from #trace where EventClass=42 and ObjectName=@spname and NestLevel=1 and RowNumber&gt;=@start   if @b is null begin print 'procedure: start not found' return end   select @e=min(RowNumber) from #trace where EventClass=43 and ObjectName=@spname and RowNumber&gt;@b and Nestlevel=1   if @e is null begin print 'procedure: end not found' return end   select 'Selected', @b as [Start], @e as [End]   DECLARE my_cur CURSOR FOR SELECT RowNumber,EventClass,isnull(EndTime,StartTime),NestLevel,ObjectName      from #trace where RowNumber&gt;=@b and RowNumber&lt;=@e order by RowNumber   OPEN my_cur   FETCH NEXT FROM my_cur INTO @r, @class, @t, @lev, @obj   WHILE @@FETCH_STATUS = 0   BEGIN     if @class=42 set @stack = @stack + ';' + @obj else set @stack=reverse(substring(reverse(@stack),charindex(';', reverse(@stack))+1,100000)) if @prevt is not null print substring(@prevstack,2,100000)+' '+convert(varchar,datediff(ms,@prevt,@t)) set @prevt=@t set @prevstack=@stack     FETCH NEXT FROM my_cur INTO @r, @class, @t, @lev, @obj   END   CLOSE my_cur   DEALLOCATE my_cur GO<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 <strong>flame <\/strong>\u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0442\u0440\u0435\u0439\u0441\u043e\u043c<\/p>\n<\/li>\n<li>\n<p>\u0438\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b. \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 (NestLevel=1). \u0418\u043c\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a \u0438 \u0441\u0445\u0435\u043c\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e [dbo].[myProc] \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c myProc<\/p>\n<\/li>\n<li>\n<p>\u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u0435\u043d, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0438\u0445 \u043c\u043d\u043e\u0433\u043e<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d RowNumber, \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u0440\u0435\u043c\u0435\u043d \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 Start \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f 9\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 10574<\/p>\n<h2>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b<\/h2>\n<p>\u0423\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0443 <strong>Messages <\/strong>\u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b, \u0443\u0434\u0430\u043b\u0438\u0432 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439:<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 <a href=\"https:\/\/www.speedscope.app\" rel=\"noopener noreferrer nofollow\">https:\/\/www.speedscope.app<\/a> \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0444\u0430\u0439\u043b. \u0413\u043e\u0442\u043e\u0432\u043e.<\/p>\n<figure class=\"\"><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/892876\/\"> https:\/\/habr.com\/ru\/articles\/892876\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-452511","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=452511"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452511\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=452511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=452511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=452511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}