Begins query profiling for a datacontext instance. This overload allows a filter and an execution plan mode to be specified.

Namespace: Huagati.LinqToSQL.Profiler
Assembly: HuagatiL2SProfiler (in HuagatiL2SProfiler.dll) Version: 1.33.3996.16059

Syntax

C#
public static QueryProfiler BeginProfiling(
	this DataContext dc,
	string outputPath,
	ProfilerFilter filter,
	ExecutionPlanMode executionPlanMode
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function BeginProfiling ( _
	dc As DataContext, _
	outputPath As String, _
	filter As ProfilerFilter, _
	executionPlanMode As ExecutionPlanMode _
) As QueryProfiler
Visual C++
[ExtensionAttribute]
public:
static QueryProfiler^ BeginProfiling(
	DataContext^ dc, 
	String^ outputPath, 
	ProfilerFilter^ filter, 
	ExecutionPlanMode executionPlanMode
)

Parameters

dc
Type: System.Data.Linq..::..DataContext
DataContext to profile
outputPath
Type: System..::..String
Output path or URL to the profiler query log.
filter
Type: Huagati.LinqToSQL.Profiler.Filters..::..ProfilerFilter
An instance of a ProfilerFilter used to filter what queries/executions to include in the log.
executionPlanMode
Type: Huagati.LinqToSQL.Profiler..::..ExecutionPlanMode
ExecutionPlanMode value controlling whether execution plans should be retrieved or not. See the ExecutionPlanMode enum documentation for available options.

Return Value

Returns a QueryProfiler instance representing the current profiler session.

Examples

This example shows how to use the DataContext extension method BeginProfiling to set up profiling from within an application.
CopyC#
using (MyDataContext dc = new MyDataContext())
{
    //Initialize profiling with a page read filter set to 10k page reads.
    // Also include actual execution plans for queries that exceed this filter setting
    QueryProfiler qp = dc.BeginProfiling(@"c:\temp\profilerOutput", new PageReadFilter(10000), ExecutionPlanMode.Actual);

    //define a query
    var query = from emp in dc.Employees where emp.EmployeeAddresses.Address.City == "London" select emp;

    //enumerate employees
    foreach (Employee emp in dc.Employees)
    {
        System.Diagnostics.Debug.WriteLine(emp.EmployeeID.ToString());
    }

    //disable profiling
    qp.EndProfiling();
}
Alternatively, override the datacontext constructor with a constructor that initialize profiling and a dispose method that terminates profiling:
CopyC#
public partial class MyDataContext
{
    private QueryProfiler _profiler = null;

    public MyDataContext(bool enableProfiling) : this()
    {
        if (enableProfiling == true)
        {
            string profilerOutput = @"https://apps.huagati.com/queryprofiler/?logid=7382";
            _profiler = this.BeginProfiling(profilerOutput, new ExecutionTimeFilter(500), ExecutionPlanMode.Actual);
        }
    }

    protected override void Dispose(bool disposing)
    {
        if (_profiler != null)
        {
            this.EndProfiling();
        }
        base.Dispose(disposing);
    }
}

See Also