Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

linux - Monitoring pthread context switching

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

EDIT: 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.

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

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

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...