Altiris Profiler SQL Server Quick Start

about 1 year ago

I have been blogging a fair bit about Altiris Profiler, however I haven’t put together any simple quickstart to demonstrate this technology. This post aims to rectify this.

To start off lets look a typical pattern that is used when executing SQL against SQL server.

 

SqlCommand cmd = cnn.CreateCommand();<br />cmd.CommandText = <span class="str">"create table #test (data int)"</span>;<br />cmd.ExecuteNonQuery(); 
 

Let’s substitute the SqlCommand with a proxy object responsible for profiling. First, we define a reusable function that we will use instead of CreateCommand.  

 

<span class="kwrd">private</span> <span class="kwrd">static</span> SqlCommand CreateCommand(SqlConnection cnn)<br />{<br />    SqlCommand cmd = cnn.CreateCommand();<br />    <span class="kwrd">if</span> (SqlProfiler.ProfilingEnabled)<br />    {<br />        SqlCommandProxy proxy = <span class="kwrd">new</span> SqlCommandProxy(cmd); <br />        cmd =(SqlCommand)proxy.GetTransparentProxy();<br />    }<br />    <span class="kwrd">return</span> cmd;<br />} 

 

Next, in our app in all places where we used to use Connection.CreateCommand or new SqlCommand() we will use this new function instead.

 

Depending on how you application is designed this exercise may be trivial or tedious.

 

A copy of the demo project can be download here. The Altiris profiling framework is available here.

 

To try out the demo project, ensure you execute profiler.exe (in c:\program files\altiris\diagnostics) and Visual Studio as administrator on Windows Vista.

 

When you run profiler skip the wizard screen and press the start profiling button (green arrow).

 
 
SQLProfilerWindow

After that we have full stack traces for every sql statement that we executed in the demo, full details about why sql statements failed.

The demo also contains code profiling that wraps all the SQL statements executed.

 

<span class="kwrd">using</span> (CodeProfiler cp = CodeProfiler.StartProfiling(<span class="str">"TestCategory"</span>,<span class="str">"TestSubCategory"</span>))

 

This gives us some very interesting high level instrumentation. I know the whole using block took 1.179 secs, 1.086 were in SQL

 

CodeProfilerWindow

 

If anyone gets this to work, please let me know :)

Comments

daniel

about 1 year ago

this is awesome.
somehow the flush code in the demo takes a while, is it normal?

Sam

about 1 year ago

Daniel,

Thanks :)

I just ran a quick test, the flush takes approx 500ms to run. Running the flush code is only necessary before shutting down an app that is been profiled. During normal operation the framework will flush events on a regular basis.

To minimize the impact of the profiling framework we hand back control to the thread being profiled as soon as possible. A second thread sends over events from all the threads being profiled via a memory mapped file to the profiler app.

Comments Closed.