Altiris Profiler SQL Server Quick Start
over 2 years 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).
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.
If anyone gets this to work, please let me know :)
daniel
over 2 years ago
somehow the flush code in the demo takes a while, is it normal?