分析内存使用我的代码(开源)和第三方代码(封闭源)的最佳策略 [英] Best strategy for profiling memory usage of my code (open source) and 3rd party code(closed source)

查看:220
本文介绍了分析内存使用我的代码(开源)和第三方代码(封闭源)的最佳策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很快就要为使用C / C ++编写的代码编写正确的内存配置文件,并使用CUDA来利用GPU处理。

I am soon going to be tasked with doing a proper memory profile of a code that is written in C/C++ and uses CUDA to take advantage of GPU processing.

我最初的想法是创建宏和运算符重载,这将允许我跟踪调用malloc,免费,删除和新的调用在我的源代码。我只能够包括一个不同的头,并使用 __ FILE__和__LINE __ 宏打印对日志文件的内存调用。此类策略位于以下位置: http://www.almostinfinite.com/memtrack.html

My initial thoughts would be to create macros and operator overloads that would allow me to track calls to malloc, free, delete, and new calls within my source code. I would just be able to include a different header, and use the __FILE__ and __LINE__ macros to print memory calls to a log file. This type of strategy is found here: http://www.almostinfinite.com/memtrack.html

在第三方库中链接的最佳方式是什么?我假设我几乎只能跟踪内存使用之前和之后的函数调用,正确?在我的宏/过载情况下,我可以简单地跟踪请求的大小,以确定需要多少内存。我怎么能知道第三方库使用多少?也是我的理解,跟踪自由并没有真正给你任何意义的代码在任何特定的时间使用,因为它不一定返回到操作系统。

What is the best way to track that usage in a linked in 3rd party library? I am assuming I'd pretty much only be able to track memory usage before and after the function calls, correct? In my macro/overload scenario, I can simply track the size of the requests to figure out how much memory is being asked for. How would I be able to tell how much the 3rd party lib is using? It is my understanding also, that tracking "free" doesnt really give you any sense of how much the code is using at any particular time, because it is not necessarily returned to the OS. I appreciate any discussion of the matter.

我真的不想使用任何内存分析工具,如Totalview或valgrind ,因为他们通常做一个很多其他东西(边界检查等),似乎使软件运行非常缓慢。另一个原因是,我想这有点线程安全 - 软件使用MPI我相信产生进程。我将尝试对此进行实时配置,以便我可以转储到日志文件或可以由另一个进程读取的东西,以可视化内存使用情况的软件运行。这也主要在linux环境中运行。

I dont really want to use any memory profiling tools like Totalview or valgrind, because they typically do a lot of other things (bounds checking, etc) that seems to make the software run very slow. Another reason for this is that I want this to be somewhat thread safe - the software uses MPI I believe to spawn processes. I am going to be trying to profile this in real time so I can dump out to log files or something that can be read by another process to visualize memory usage as the software runs. This is also primarily going to be run in a linux environment.

感谢

推荐答案

如果您不想使用外部工具,可以尝试使用以下工具:

If you don't want to use an "external" tool, you can try to use tools like:

它安装处理程序malloc,realloc和free,并将每个操作记录到一个文件。

It installs handlers for malloc, realloc and free and log every operation to a file. See the Wikipedia I lined for code usage examples.

dmalloc

这是一个可以在代码中使用的库,可以找到内存泄漏,逐一错误和使用无效地址。您也可以在编译时使用-DDMALLOC_DISABLE禁用它。

It's a library you can use in your code, and can find memory leaks, off-by-one errors and usage of invalid addresses. You can also disable it at compile time with -DDMALLOC_DISABLE.

无论如何,我宁愿不会得到这种方法。相反,我建议您在valgrind(或任何等效工具)上的测试服务器上运行它时,尝试并压力测试您的应用程序,并确保您正在进行内存分配,然后让应用程序运行,而不在生产中进行任何内存分配检查以最大化速度。但是,事实上,这取决于你的应用程序做什么和你的需求是什么。

Anyway, I would rather not get this approach. Instead, I suggest you to try and stress test your application while running it on a test server under valgrind (or any equivalent tool) and ensure you're doing memory allocation right, and then let the application run without any memory allocation checking in production to maximize the speed. But, in fact, it depends on what your application do and what your needs are.

这篇关于分析内存使用我的代码(开源)和第三方代码(封闭源)的最佳策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆