My day job requires me to spend a lot of time in Linux terminals, hammering away at MariaDB ColumnStore to write and test new code as well as finding and fixing bugs. I have decided to write about the tools I use to get the job done, especially newer ones I have discovered.

ack

The first tool I’m going to talk about is ack. ack is a replacement for grep which is designed to be used on files. By default it will scan the current directory and  subdirectories for the given text. You can also tell it to only scan certain file types.

In the example below I’ve asked it to search for the word “Token” in the current codebase in all C++ header file types.

Screenshot from 2017-08-24 08-15-35

I have found more often than not I am reaching for ack instead of grep when searching codebases for certain content because it already uses by default the options I would use in grep and is easy to filter by file type. I now have to remember to install it on all my machines and VMs when setting them up as I naturally go to it first.

memleakx

Memleakx is a tool I found completely by accident recently but has been really useful in solving a recent complex memory leak issue (which turned out to be down to orphaned threads). It was created by Wu Bingzheng who I have crossed paths with before during my days working at NGINX.

It is similar to Valgrind’s memcheck but has the added advantage that you can attach it to an already running process. Something I have been dying for Valgrind to have since I’m usually debugging long-running daemons. Or I’m debugging daemons that have an extremely long setup time when running under Valgrind.

You can tell memleakx to spit out reports every X seconds of the allocations that have been made but not freed yet. Making it extremely useful to find things may not technically be leaks as they will be cleaned up later, but can still consume a lot of RAM when not needed.

It appears to have similar CPU overheads as Valgrind, I haven’t looked at its source code to see what it does internally yet.

If you are doing a lot of memory debugging I highly recommend adding this one to your toolbox. It doesn’t appear to be in any repositories yet so you have to get the source from GitHub or the RPM/DEB packages.

Image credit: Biser Todorov, used under a Creative Commons license.

3 responses to “Linux tools: ack and memleakx”

  1. I’ve been poking at LeakSanitizer recently (build with -fsanitize=address) and that’s both pretty low overhead and can find things valgrind can’t.

    1. I’ve wanted to try that but was hitting compile problems with another MariaDB engine. I should have spent more time trying to figure out why.
      I have been playing with the TCMalloc heap profiler which has been useful in occasion.
      I plan to make these blogs a series so more things like this to come.

  2. […] my previous post about ack a Twitter follower, Nick Morrott, pointed out that there is a potentially better tool than […]

Leave a Reply

Your email address will not be published. Required fields are marked *