Home > drizzle, knowledge, oss > Tips on Drizzle Development and Valgrind

Tips on Drizzle Development and Valgrind

December 1st, 2009

In brief, valgrind is a framework of awesome tools that does an amazing job at detecting memory errors. It will catch silly (often unexpected) mistakes and memory leaks that you’ve made in your code. IMHO, it’s a must have tool for open source hackers that work with Linux. If you develop a plugin or a storage engine for Drizzle/MySQL, you often end up wanting to test your program for memory errors. Actually, it’s not a “want”, it’s a MUST.

Conveniently by supplying a simple startup option, Drizzle and MySQL’s test runner will run the daemon process on valgrind’s virtual machine. I’m not sure about MySQL since I’ve never developed anything for it but at least with Drizzle you can run a test case independently by supplying the desired test name to the test runner.

 $ ./dtr your_test_file_name --valgrind

So, with BlitzDB this is what I do to isolate the test runner to only run my tests:

 $ ./dtr blitzdb.test --valgrind

Very simple.

The minor complication here is that the test runner will not output the valgrind report to the console and instead it writes the output to a file. So where is this file? the answer is, it’s written to the daemon’s error log which is located in the source tree:

$ less drizzle_src/tests/var/log/master.err
CURRENT_TEST: main.blitzdb
==24563== Memcheck, a memory error detector
==24563== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
...

Here’s another tip. If you ever wondered where the files that were generated in the test (like table and index files) are stored, they are stored inside the source tree as well. Here’s an example on my machine:

$ ll drizzle_src/tests/var/master-data/
total 20528
-rw-rw---- 1 tmaesaka tmaesaka 10485760 2009-12-01 22:06 ibdata1
-rw-rw---- 1 tmaesaka tmaesaka  5242880 2009-12-01 22:06 ib_logfile0
-rw-rw---- 1 tmaesaka tmaesaka  5242880 2009-12-01 22:06 ib_logfile1
drwxr-xr-x 2 tmaesaka tmaesaka     4096 2009-12-01 22:06 mysql
drwxr-xr-x 2 tmaesaka tmaesaka     4096 2009-12-01 22:06 test

So, with all that in mind, happy hacking :)

Toru Maesaka drizzle, knowledge, oss ,

  1. Jobin Augustine
    December 2nd, 2009 at 11:03 | #1

    Thank your for the post. and guiding me to valgrind.

    a perfect world don’t have any memory leak :)
    C/C++ world is not requied to think of the garbage collector in Java and .Net world any more?

  2. December 2nd, 2009 at 17:48 | #2

    @Jobin:

    Nope, in C++, garbage collection and deallocation of memory is the responsibility of the programmer. This makes C++ slightly more powerful than Java/.NET (or rather, unmanaged .NET), but along with that power comes extra responsibility/risk of a memory leak.

    @Toru:

    Actually, the flag to ./dtr is –valgrind-mysqld, otherwise the valgrind output in master.err will be the valgrind result of drizzltest.cc and not the server :)

    Cheers!

    Jay

  3. December 2nd, 2009 at 18:41 | #3

    Jay,

    Thanks for correction. Kinda weird, I was getting BlitzDB errors in there but maybe I’ll get more if I use that option. Lemmie try it out now.

    EDIT:
    I just tried the two options and I got the same output… Who knows, maybe someone in the community had made the option consistent :)

    Thanks!

  4. December 4th, 2009 at 04:11 | #4

    Hi again, Toru! :)

    OK, so I was a little puzzled by your comment. Check out this output which shows the difference between –valgrind and –valgrind-mysqld. You’ll notice that the first output shows the valgrind output from drizzletest.cc and the second, I have to cat the var/log/master.err…

    EDIT:
    Thanks Jay. As you mentioned, this output is humungous so I took a copy on my laptop. It’s awesome how we were both confused big time!

  5. December 4th, 2009 at 04:12 | #5

    Hmm, probably shouldn’t have posted all that… :) Sorry, toru!

  6. December 4th, 2009 at 16:32 | #6

    Haha, thanks for giving MyISAM a little thrash. I can’t wait to run this blog on Drizzle + BlitzDB :)

    I’ll update the blog post based on what we discussed later on. Too sleepy now…

  1. No trackbacks yet.