监控pthread上下文切换 [英] Monitoring pthread context switching

查看:238
本文介绍了监控pthread上下文切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视多线程pthread应用程序中的上下文切换行为。

I would like to monitor the the context switching behavior in a multi-threaded pthread application.

在其他RTOS(Micro C OS)中,我已经能够注册应用程序中的每个线程的上下文切换回调,然后记录(或切换gpio)并实时观察线程上下文切换。这是调试多线程的实时行为和交互的有价值的工具。

In other RTOSes(Micro C OS) I have been able to register a context switch callback for each thread in the application, and then log (or toggle a gpio) and watch the thread context switching in real time. This was a valuable tool for debugging the real time behavior and interaction of the multiple threads.

我目前的环境是使用pthread api嵌入式的linux。有没有办法监控每个上下文切换?

My current environment is embedded linux utilizing the pthread api. Is there a way to monitor each of the context switches?

推荐答案

不按照你所描述的方式,但是有各种分析工具对于Linux,如oprofile,SystemTap和perf事件,我不知道它们适合嵌入式开发的程度。

Not in the way you describe, however there are various profiling tools for Linux, like oprofile, SystemTap and perf events, I'm not sure how well they'd fit into embedded development though.

编辑:perf可能是最好的你正在运行一个最近的内核来使用它),因为它在主干线,所以你只需要打开它,这是非常基本的。

perf is probably best (if you are running a recent enough kernel to use it) since it's in the mainline so you just have to turn it on, and it's really basic.

编辑:如果没有那些工作给你,你可以随时修改内核上下文切换代码...

if none of those work for you you can always modify the kernel context switch code...

编辑:我错过了一个跟踪框架,还有LTTng

I missed one of the tracing frameworks, there is also LTTng

如果您正在使用busybox并且可以编译自己的内核,perf可能是最简单的方式,它包括打开内核中的perf事件并编译自带的perf工具内核源码(它在tools / perf中)

If you're using busybox and can compile your own kernel perf is probably the most minimal way to go, it's consists of turning on perf events in the kernel and compiling the perf tool that comes with the kernel source (it's in tools/perf)

这篇关于监控pthread上下文切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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