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

The Legend Continues: Amiga 1000 Keyboard Revival

I have restored the boxed Amiga 1000 main unit and the mice that came with…

2 days ago

Amiga 4000 Repair: This one was just weird

I was recently sent an Amiga 4000 motherboard repair. It should have been quite straightforward,…

4 days ago

Unboxing the Legend Continues: Amiga 1000 Mouse Restoration.

I recently received a boxed Amiga 1000 which was in excellent condition, but required a…

1 week ago

Unboxing a Legend: Amiga 1000

I have a local friend who is a private collector of vintage computers and consoles,…

2 weeks ago

Amiga 4000 With Lots of Little Problems

I’ve had a few people send me things in to repair lately. Amongst these was…

2 months ago

Amiga A3640 CPU Card Repair

Lately, I've been very busy, but haven't had many interesting things to blog about happen.…

2 months ago