Linux tools: ack and memleakx

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.

Published by

LinuxJedi

I am a Senior Software Engineer for MariaDB leading the development of MariaDB ColumnStore.

3 thoughts on “Linux tools: ack and memleakx”

    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.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s