I am trying to determine the impact of context switching on my Java thread. Therefore I would have to know first “how many times has it been preempted?” and second, if possible, “how long was my thread suspended from execution?”. I would doubt very much that this can be done from Java, but hey! the fun things is to do the impossible, right? 🙂 Even If I have to recompile the VM or to use some kind of LINUX tool or hack I would be happy. So now that we know that can’t be done, let’s do it. 🙂
EDIT: Come on people. The other question was priority related. I guess you just enjoy easy and boring questions. The question is clear and valid.
If you can identify the Linux TID (thread ID) for the Java thread you’re interested in (assuming your JVM maps Java threads onto Linux threads) then the pseudo-file
/proc/<tid>/statuscontains many statistics, includingvoluntary_ctxt_switchesandnonvoluntary_ctxt_switches.