This project is read-only.

Database Profiling

As it has been mentioned - the DBDatabase is the central class where all queries are executed against the actual database engine.

This gives us an ideal opportunity to monitor the applications interaction with a database, without affecting the compiled code.

The simplest way is to call the AttachProfiler() method on the database instance, passing in one of the pre-defined IDBProfiler instances - DBConsoleProfiler or DBTextFileProfiler

However, although this works, it does place the responsibility on the developer to remember to remove it.
Much cooler and far more flexible is to define the profiler in the configuration file.

Profiler Configuration

In your app.config or web.config make sure you register the PerceiveIT.Data configuration section at the top.

    <section name="Perceiveit.Data" type="Perceiveit.Data.Configuration.DBConfigurationSection, Perceiveit.Data"/>

Now you can register any of the existing profilers, or your own custom implementation at will.

    wrap-exceptions="true" > <!-- use @wrap-exceptions to stop sensitive information 
                                   from being included in the exception message -->
    <!-- automatically attach profilers to any DBDatabase. 
         The 2 below are the standard (included) profilers, 
         but you can define your own. -->
    <Profilers auto-start="true"  > <!-- If auto-start is false then manual starting of the profiler 
                                         for each DBDatabase instance is required (default is true)-->
      <Attach name="Console" factory="Perceiveit.Data.Profile.DBConsoleProfilerFactory, Perceiveit.Data" />
      <Attach name="LogFile" factory="Perceiveit.Data.Profile.DBTextFileProfilerFactory, Perceiveit.Data" >
        <Set key="file-path" value="C:\Temp\DBLog_[Name]_[Date].log" /><!-- the file-path value is parsed to accept [Name], [Date] and [Connection] options so text file logs can be separated. -->

From now on any DBDatabase will record all the sql statements executed against the specified profilers - including timestamps and duration.

Performance Impact

Yes it does - and it's mostly down to the actual profiler instances themselves rather than any DBDatabase overhead. So it's not recommended for Release applications, but can be useful for diagnosis.
Find out which queries are taking a long time. Which ones are being run most.
And it's only your application - even if other systems are connected to the same database.


This log file shows a sample small output for the DBTextFileProfiler, so you can see what it's like. Can also be imported to excel as a tab separated file.

Last edited Aug 15, 2012 at 5:51 PM by perceiveit, version 8


No comments yet.