Altiris Profiler SQL Server Quick Start
over 5 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();
cmd.CommandText = "create table #test (data int)";
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. Â
Â
private static SqlCommand CreateCommand(SqlConnection cnn)
{
SqlCommand cmd = cnn.CreateCommand();
if (SqlProfiler.ProfilingEnabled)
{
SqlCommandProxy proxy = new SqlCommandProxy(cmd);
cmd =(SqlCommand)proxy.GetTransparentProxy();
}
return cmd;
}
Â
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.
Â
using (CodeProfiler cp = CodeProfiler.StartProfiling("TestCategory","TestSubCategory"))
Â
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 :)
somehow the flush code in the demo takes a while, is it normal?