Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 xp_trace% in SQL 7

Author  Topic 

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-11 : 12:46:37
I am trying to write a proc that starts a trace of batch completed for a given spid and outputs duration, writes, reads and cpu to a given table. My proc isn't working and I'm hoping someone can shed some light....

drop proc usp_tracestart
go
drop proc usp_traceend
go

create proc usp_tracestart
@spid smallint,
@host varchar(256),
@table varchar(256),
@filter varchar(256),
@queue_handle int OUT
as

--Declare the variables
declare
@column_value int --data column bitmask

--Set the column mask for the data columns to capture
set @column_value = 67108864|1|131072|32768|65536|4096

--Create a queue.
exec master.dbo.xp_trace_addnewqueue
1000, --max_items
5, --timeout
95, --thread_boost
90, --thread_reduce
@column_value, --required_columns
@queue_handle out --queue_handle

--Specify the event classes to trace.
exec master.dbo.xp_trace_seteventclassrequired
@queue_handle, --queue_handle
12, --event_class -> SQL:BatchCompleted
1 --isrequired

--Set any filters.
exec master.dbo.xp_trace_setappfilter
@queue_handle, --queue_handle
'MS SQL Query Analyzer%', --'include_only_applications'
'SQL Server Profiler%' --'exclude_applications'

exec master.dbo.xp_trace_setspidfilter
@queue_handle, --queue_handle
@spid --spid

exec master.dbo.xp_trace_sethostfilter
@queue_handle, --queue_handle
@host, --'include_hosts'
NULL --'exclude_hosts'

exec master.dbo.xp_trace_settextfilter
@queue_handle, --queue_handle
@filter, --'include_text'
NULL --'exclude_text'

--Configure the queue to write to a table.
exec master.dbo.xp_trace_setqueuedestination
@queue_handle, --queue_handle
4, --destination -> To Table
1, --value -> enabled
@host, --'server'
@table --'object'

--Start the consumer.
exec master.dbo.xp_trace_startconsumer
@queue_handle --queue_handle
/*
--Save the queue definition as DemoQueue.
exec master.dbo.xp_trace_savequeuedefinition
@queue_handle, --queue_handle
'Stats', --'queue_name'
1 --is_shared

--Mark it for autostart
exec master.dbo.xp_trace_setqueueautostart
'Stats', --'queue_name'
1 --is_shared
*/
go


create proc usp_traceend
@queue_handle int
as

--Destroy the trace
exec master.dbo.xp_trace_destroyqueue
@queue_handle --queue_handle
/*
exec master.dbo.xp_trace_deletequeuedefinition
'Stats', --'queue_name'
1 --is_shared
*/
go

 
... and here is some the code I am using to call my procs ...


set nocount on
go

drop table vctest
drop table #traces
drop table vcstats
go

create table vctest (pk varchar(6) not null primary key)
create table #traces (queue_handle int not null primary key)
go

declare
@trace int

exec dba.dbo.usp_tracestart
@spid = @@spid,
@host = 'PAGE47',
@table = 'dba.dbo.vcstats',
@filter = '%insert%',
@queue_handle = @trace OUT
insert #traces
select @trace
go

declare @i int
set @i = 1
while @i <= 1000
begin
insert vctest values (convert(varchar(6),@i))
set @i = @i + 1
end
go

declare @trace int
select @trace = queue_handle
from #traces
exec dba.dbo.usp_traceend @trace
delete #traces
where queue_handle = @trace
go

select * from dba.dbo.vcstats
go

 
...nothing ends up in dba.dbo.vcstats

<O>

Edited by - Page47 on 07/11/2002 12:48:48

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-11 : 13:17:57
WHAT???

If I run this junk as is . . . I end up with nothing in vcstats, I get nothing.

If, however, I set up a trace in profiler to trace me running this junk, I end up with the desired data in vcstats...

I must be missing something. You can run a trace without profiler running, right? WTF?

<O>
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-11 : 13:35:16
It seems like if I make the trace consumer at table, something doesn't work. However, I need my statistics data in a table for further manipulation.

<O>
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-11 : 13:40:41
Everything I can find uses a file as the consumer. You can pump to a table, yeah?

<O>
Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-07-11 : 13:44:38
And they wondered how he got enough posts to become an aged

-----------------------
Take my advice, I dare ya
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-07-11 : 16:36:36
Jay, what's up with this thread? Split personality? Give your password to someone else? Stream-of-consciousness programming?

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-12 : 07:52:31
Just trying to keep the thread updated on the status of my problem . . . current update? Bagged the stored proc trace and just used profiler . . . its a damn shame, but the xp_trace procs just don't seem to work as advertised when you try to make the consumer a table . . . oh well.

<O>
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-07-12 : 09:32:34
why not DTS/BCP the 'consumer' file back into a table?...sticky tape solution?

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-07-12 : 09:34:31
I'm sure that'll work...next time

<O>
Go to Top of Page
   

- Advertisement -