Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Created December 2, 2014 14:49
Show Gist options
  • Save sheldonhull/2f0c53641421a9825e6b to your computer and use it in GitHub Desktop.
Save sheldonhull/2f0c53641421a9825e6b to your computer and use it in GitHub Desktop.
obtain information on traces running
------------------------- obtain information on traces running -------------------------
select
trace_id = id
,is_rowset
,trace_name = reverse(left(reverse(path),
charindex('\', reverse(path),
1) - 1))
,trace_duration =
case
when stop_time is not null then 'Duration (min): ' + convert(varchar(10), datediff(minute, start_time, stop_time), 120)
else 'No duration limit'
end
,status =
case status
when 0 then 'Stopped'
when 1 then 'Running'
end
,stop_trace_command =
case
when id = 1 then 'Default Trace, No actions to take'
when t.is_rowset = 1 then 'Stop trace in profiler'
else cast('-- Stops the specified trace.
exec sp_trace_setstatus ' + cast(id as nvarchar(10)) + ', 0
-- Closes the specified trace and deletes its definition from the server.
exec sp_trace_setstatus ' + cast(id as nvarchar(10)) + ', 2' as nvarchar(max))
end
,max_size
,t.max_files
,t.is_rollover
,t.event_count
,t.dropped_event_count
,start_time
,stop_time
from
sys.traces as t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment