开发者

Under Linux, how do I track down a memory leak in pre-built software?

开发者 https://www.devze.com 2023-01-03 22:53 出处:网络
I have a new Ubuntu Linux Server 64bit 10.04 LTS. A default install of Mysql with replication turned on appears to be leaking memory.

I have a new Ubuntu Linux Server 64bit 10.04 LTS.

A default install of Mysql with replication turned on appears to be leaking memory. However, we've tried going back to an earlier version and memory is still leaking but I can't tell where.

What tools/technique开发者_开发问答s can I use to pinpoint where memory is leaking so that I can rectify the problem?


Valgrind, http://valgrind.org/, can be very useful in these situations. It runs on unmodified executables but it does help tremendously if you can install the debugging symbols. Be sure to use the --show-reachable=yes flag as the leaked memory may still be reachable in some way but just not the way you want it. Also --trace-children in case of a fork. You'll likely have to track down in the start-up script where the executable is called and then add something like the following:

 valgrind --show-reachable=yes --trace-children=yes --log-file=/path/to/log SQL-cmdline sqlargs

The man page has lots of other potentially useful options.

Have you tried the MySQL mailing list? Something like this would certainly be of interest to them if you can reproduce it in a straightforward manner.


You can use Valgrind as ninjalj suggests, but I doubt you'll get that close to anything useful. Even if you see a real leak (and they will be hard enough to validate), tracking down the root cause through the C call stacks will likely be very annoying (for example if the leak is triggered by a particular SQL pattern or stored procedure, you'll be looking at the call stack from the resultant optimized query, and not the original calls, which are likely in a different language).

Normally you might have no recourse, and have to resort to tracking it down through callstacks and iterative testing, but you have the source code to MySQL (including the source for the exact default package install), so you can use more advanced tools like MemoryScape (or at least build with symbols in order to provide Valgrind more food for thought).


Try using valgrind.


A very good and powerful tool, which is installed/available for most distributions is Valgrind.

It has a plethora of different options and is pretty much (as far as I've seen) the default profiler under linux systems.

0

精彩评论

暂无评论...
验证码 换一张
取 消