Cory O'Daniel – These are just words Software development, thoughts, and randomness

25Nov/090

DataMapper Cutie – The query tracker and profiler

So Ive been busting my butt on this query tracker for a while now. Its been finished twice and not released (once when I hated the API, and once right before 0.10 was release). But here she is, open for the hacking.

Its pretty easy to get set up, the gems are on http://gemcutter.org

To get started:

1
2
3
4
5
6
7
8
$ gem sources -a http://gemcutter.org # Add gem cutter to your gem sources
$ gem install dm-cutie
 
# This is a plugin pack for dm-cutie
$ gem install dm-cutie-extras 
 
# this is the front-end to dm-cutie
$ gem install dm-cutie-ui

If you plan to use MySQL to store dm-cuties information, set up a schema for that now by doing:

1
mysql: CREATE SCHEMA `dm_cutie`;

dm-cutie will allow you to store stuff across different adapters, so you can actually profile a Mysql DataMapper Repository into a dm-cutie sqlite3 repository. Its ok, she gets it

Now, in your application after your default DataMapper repository is set up do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'dm-cutie'
 #currently only data_objects is supported
DataMapper::Cutie.enable_adapter :data_objects
require 'dm-cutie-extras'
 
# Query Plans!
DataMapper::Cutie::Extras.load :mysql_execution_step 
 
# Index optimization tips!
DataMapper::Cutie::Extras.load :mysql_index 
 
# Mysql Errors and warnings!
DataMapper::Cutie::Extras.load :mysql_warning 
 
 
DataMapper::Cutie.setup do |c| 
  c[:repo_name]       = :dm_cutie # name of your repo  
  c[:exclude_models]  = false #[:person, :car] #models to exclude
  c[:only_models]     = false #[:article, :address] #model to include
  c[:slow_query_length] = 2
end
 
#Forces Cutie to always migrate HER models
DataMapper::Cutie.start(true)

Let dm-cutie sit in your code for a while, she will start to generate lost of data on your repository. I would recommend not putting dm-cutie in a production environment due to the amount of queries that it generates. It is best used in a development or a staging environment and then applies the learned optimization strategies to your production environment.

After cutie has been running a while (or immediately if you are impatient) from the command line do:

1
$ dm-cutie-ui -p 4567 --extras=mysql_warning,mysql_index,mysql_execution_step

If you didn't use any of the extras in your application you SHOULDNT list them when you start the dm-cutie-ui.

That's that. You just need to sign in using the URI for your repository, it will be something like: mysql://root@localhost/dm_cutie.

An important note is that when you log into dm-cutie-ui you are logging into the dm-cutie repository, not your applications, so keep that in mind so you dont get errors saying the dm-cutie repo doesn't exist.

Well that's it for now, I'll post about this more after the holiday when I make a few more plugins. Enjoy!

There is a ton more documentation at:

Post to Twitter Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon