
MTuner is a C/C++ memory profiler and memory leak finder - llazzaro
https://github.com/milostosic/MTuner
======
Elv13
In case someone is looking for the equivalent on Linux and Mac, there is
HeapTrack

[https://github.com/KDE/heaptrack](https://github.com/KDE/heaptrack)

edit: typo

~~~
kakali
I've been looking for something like this. Massif makes it look like my code
is reasonably healthy. HeapTrack shows I'm doing absurd number of small heap
allocations.

------
stinos
I never used other memory profilers than MTuner mainly because not needing it,
but also because MTuner works so well (for what I used it) I saw no reason to
look for anything else: the combination of the different ways to view
allocations/deallocations make for a very detailed yet uncomplicated view of
your application's memory managment. E.g. first thing I noticed once was a
constructor allocating 20 blocks of 8K and freeing them again just to
initialize a vector, so that immediately tells you there's room for
improvement there. Possibly other tools work just as well, but I can't
compare.

It's also interesting just to look at all the data to figure out how
exepensive some things are memory-wise. These days with the more modern C++
it's easy to forget what goes on under the hood. Nothing wrong with that per-
se: C++ is usually performant enough that you just don't have to care about it
_at all_. But if you have this typcial engineering mindset and like to know
how stuff works just for the sake of it, and 'stuff' in this case is 'memory
usage', then this is your tool.

------
nagVenkat
How different is this from Intel's vtune amplifier? I used vtune amplifier to
get the memory profiles for some c++ code I had written before.

~~~
mattip
Is it free? Can the code be verified for backdoors? Does it work on non-intel
chips?

~~~
nagVenkat
Thanks. I used vtune sometime ago while I was a student. But I will try to
investigate the foss alternatives.

------
andrewprock
Doesn't valgrind do this?

~~~
Elv13
Most of it (memcheck and massif), but good luck getting the important data
out. Memcheck is fine, but massif is quite restricted as a object-level memory
monitor. I can't talk for MTuner, but HeapTrack is very, very useful to track
and eradicate temporary allocations (useless C++ object create when using `==`
or passing by copy.

~~~
grandinj
Sounds cool. Any pointers to useful tutorials on making that idea work?

~~~
Elv13
Well, it's not really an idea. It is what HeapTrack and MTuner do. You install
them, inspect the result, fix the worst offenders, repeat. There isn't much to
it.

------
amq
Did anyone try it with [https://developer.arm.com/open-source/gnu-
toolchain/gnu-rm](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm)?

------
0xFFC
Very good. I wish you all the success.

But I have a (side) question. You are using Makefile while targeting non-nix
platforms. Why? It seems to me it is the strangest combination ever.

~~~
mivanchev
For convenience! Make is a powerful software and GNU Make is readily available
for Windows, e.g. as part of MinGW. I also actively use it for my projects,
because it's just kind of always there when you need a build system and you
can put together an initial Makefile real quick.

~~~
0xFFC
Isn't all of these arguments applicable to CMake?

Considering GNU Make is not itself available in Windows and you should install
MinGW for getting make.

~~~
fwsgonzo
Windows is a pain to program on, and MinGW alleviates that somewhat. I do use
CMake though, but I still want to use "normal" clang, so I have to generate a
unix makefile. I don't want to maintain two sets of build systems.

~~~
stinos
_Windows is a pain to program on,_

It's really not, _if_ you know how to do it. But that goes for any OS out
there. I mean, put a seasoned visual-studio-on-windows-only dev in front of a
linux box and tell him to set up the build of a non-trivial application and
watch what happens. Chances are pretty high the answer is 'linux is a pain to
program on' :]

 _but I still want to use "normal" clang, so I have to generate a unix
makefile_

[https://blogs.msdn.microsoft.com/vcblog/2017/03/07/use-
any-c...](https://blogs.msdn.microsoft.com/vcblog/2017/03/07/use-any-c-
compiler-with-visual-studio/) it's still relatively young but seems to work
quite ok

~~~
bnolsen
windows not being able to mix and match object files compiled in different
ways is really disastrous. On linux and windows I always work in release mode.
If I have problems on the linux side I can target compile 1 or 2 object files
debug, relink, run and get stack traces if I need. That's all totally
independent of programming environment.

~~~
pjmlp
That has nothing to do with Windows vs GNU/Linux, rather the compilers being
used.

UNIX is more than just GNU/Linux, and Windows compilers are more than just
Visual Studio.

------
matt4711
Is there a binary version of this tool that can be downloaded somewhere? Seems
a bit of a pain to install.

~~~
mmozeiko
Follow the link to homepage in readme, there you'll find download link to
binary:
[http://mtuner.net/index.html#download](http://mtuner.net/index.html#download)

------
FraKtus
How does that compare with the sanitizers in Clang (Memory, Address .. ) ?

------
bnastic
Impressive work, Mr Tošić! :)

------
X86BSD
2 Clause BSD! Woop woop!

Seriously this is another good app in the arsenal.

------
korginator
Doesn't work on a Mac.

~~~
saghm
Yes, it says that in the README. Plenty of people use other operating systems,
though.

~~~
unkown-unknowns
> MTuner is a C/C++ memory profiler and memory leak finder for Windows, PS4,
> PS3, etc.

I don't see any mention of Mac at all in the Readme, and I find the "etc" part
confusing. For example, I use FreeBSD. PS4 is based on FreeBSD. Does FreeBSD
go under the "etc" part? If not then what does?

~~~
teamhappy

        > MTuner supports Windows, PlayStation 4 and PlayStation 3
        > out of the box. Additionally, any platform with GCC or
        > Clang based cross compiler can easily be supported with a
        > little extra work. Instrumentation API comes with full 
        > source code which means it’s a matter of porting a few 
        > routines to get it up and running on additional platforms.
    

[http://mtuner.net/doc/overview_compilers.html](http://mtuner.net/doc/overview_compilers.html)

~~~
lultimouomo
It's still not clear to me. I _think_ it means you can use if your host
platform is Windows, but you can target other platforms through cross-
compiling, but it doesn't say it explicitly.

