Wednesday, August 1, 2012

(update 2013/09/19 minor bug to deal with a staging table that had non-sequential IDs)

I just posted this on the Cleartrace forums, but wanted a copy here.

Basically, Cleartrace takes trace files, imports the code calls, and turns it into information. Here's the code that runs most often, here's the code that takes the longest to run, here's your I/O hog, etc.

Everybody I ask about Profiler typically talks about running it then manually going through the results. While that's fine for small stuff, I'm more interested in aggregations and baselines. So were the people behind Cleartrace, fortunately. But I need it automated, and on several machines. Hence, this code.

Once cleartrace is running and set up to use a server, run this code to add a config table, then set up some servers.

I assume you're running with adequate permissions; if not, set up the folders put the files in a share and set that as your trace_folder. Set up a specific name for the trace.

Once it's imported some, bring up Cleartrace (the real version) and choose an import group, then start looking at data. Slice and dice as necessary.

Note that this does NOT keep the details - it's all aggregates, even in the CT DB. Which is why we save the trace files for posterity.

This is not any big deal, it's a rough first pass, I'm sure I'll have to fix it later. But it works and it lets me check out servers for user requests. (I didn't use XE or EN for several reasons, not the least of which because XE doesn't have all the capabilities I need under 2008)

USE Cleartrace
go
if object_id('Cleartrace..CT_AutoServerList') is not null
DROP TABLE CT_AutoServerList
CREATE TABLE CT_AutoServerList
(id INT IDENTITY,
server_name sysname,
trace_folder VARCHAR(200),
trace_name VARCHAR(50),
is_active BIT,
insert_datetime DATETIME DEFAULT(GETDATE()),
update_datetime datetime
)
SELECT * FROM CT_AutoServerList
INSERT INTO CT_AutoServerList
( server_name ,
trace_folder,
trace_name,
is_active ,
insert_datetime
)
VALUES ( 'yourservernamehere', -- server_name - sysname
'e:\foldertoholdtraces',
'tracenamegoeshere',
1 , -- is_active - bit
'2012-07-31 10:02:00'
)
-----------------------------
--Cleartrace automated load--
--mdb 2012/08/01 1.00 --
-----------------------------
CREATE PROCEDURE ReadTrace.usp_AutomateTraceLoad
as
/*
--mdb 20120801 first version!
Purpose: Pull trace files from a variety of servers and use Cleartracecmd (Cleartrace Command Line) to
automatically load into tables for processing, using a particular trace name and saving to a folder
on the "processing" server.
Cleartrace can be found at www.scalesql.com/cleartrace/
and is written(?) & maintained by Bill Graziano. It's his tool and I take no credit for it.
It's indispensable for reading traces. My code simply tries to automate it.
Instructions:
Download Cleartrace (full version, since we use Cleartracecmd.exe).
Run Cleartrace and choose a server/database. It will create the DB and objects as needed. Import a file to make sure it's all created.
Run this script in that database.
Create a folder to hold the trace files
Add rows to the CTAutoServerList table
Set up traces on the servers you want to manage. Set a beginning/end time so that this has time to run at night and import.