Linux

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.

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.

LinuxJedi

View Comments

  • 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.

    • 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.

Share
Published by
LinuxJedi
Tags: Tools

Recent Posts

Diagnosing an Amiga 1200 Data Path Fault

I recently acquired an Amiga 1200 motherboard in a spares/repairs condition for about £100 recently.…

2 days ago

Bare Metal “Hello World” on an STM32MP135F-DK

Whilst I do like working with STM32 development boards, some basic information I need can…

3 days ago

Two special Amiga 4000s: Diagnosing Jops

When I last left this blog series, the first of Stoo Cambridge's A4000s had gone…

6 days ago

Joining wolfSSL

At the beginning of November, I started working for wolfSSL. Now that I'm a week…

1 week ago

Two special Amiga 4000s: Rebuilding Jools

In my previous post, I had the Amiga 4000 known as Jools mostly repaired, there…

4 weeks ago

Two special Amiga 4000s: Repairing Jools

In my last post, I created a list of things I needed to repair on…

4 weeks ago