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

查看:16
本文介绍了测量 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

用法:

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天全站免登陆