测量Linux多线程应用程序的堆栈使用情况 [英] Measuring stack usage for Linux multi-threaded app

查看:89
本文介绍了测量Linux多线程应用程序的堆栈使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Linux嵌入式平台开发多线程应用程序.

I'm developing a multi-threaded app for a Linux embedded platform.

此刻,我正在将每个线程的堆栈大小(通过pthread_set_attr)设置为一个相当大的默认值.我想将每个线程的值微调为更小的值,以减少应用程序的内存使用量.我可以尝试通过反复试验的方法将每个线程的堆栈大小设置为逐渐减小的值,直到程序崩溃为止,但是应用程序使用约15个线程,每个线程具有完全不同的功能/属性,因此该方法非常耗时.

At the moment I'm setting the stack size for each thread (via pthread_set_attr) to a fairly large default value. I would like to fine tune that value for each thread to something smaller to reduce my application's memory usage. I could go through the trial and error route of setting each thread's stack size to progressively smaller values until the program crashed, but the application uses ~15 threads each with completely different functionality/attributes so that approach would be extremely time consuming.

我宁愿能够直接测量每个线程的堆栈使用率.有一些公用事业人员可以推荐这样做吗? (例如,我来自vxWorks背景,并且使用vxWorks shell中的"ti"命令直接提供了堆栈使用情况的统计信息以及有关任务状态的其他有用信息.)

I would much rather prefer being able to directly measure each thread's stack usage. Is there some utility people can recommend to do this? (For example, I come from a vxWorks background and using the 'ti' command from the vxWorks shell directly gives stats on the stack usage as well as other useful info on the task status.)

谢谢

推荐答案

以下是测量Linux应用程序中(本机pthread)堆栈使用情况的两个工具:

Here are two tools that measure (native pthreads) stack usage in Linux applications:

  • Valgrind
  • Stackusage

Valgrind

用法:

valgrind --tool=drd --show-stack-usage=yes PROG

Valgrind是一种稳定而强大的工具,不仅可用于测量堆栈使用情况.但是,它可能不支持所有嵌入式CPU型号.

Valgrind is a stable and powerful tool, useful not only for measuring stack usage. It may not support all embedded CPU models though.

堆栈使用量

用法:

stackusage PROG

Stackusage是专门用于测量线程堆栈使用率的轻量级工具,对于配备了glibc的大多数嵌入式Linux平台而言,它应该是可移植的.在这一点上,它可能不如Valgrind/drd那样经过充分测试或成熟.

Stackusage is a light-weight tool specifically designed for measuring thread stack usage which should be portable for most embedded Linux platforms equipped with glibc. It is likely not as well-tested or mature as Valgrind/drd at this point.

完全公开:我是Stackusage的作者.

Full disclosure: I'm the author of Stackusage.

这篇关于测量Linux多线程应用程序的堆栈使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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