Collect resource usage for a single thread. */
| 848 | |
| 849 | /* Collect resource usage for a single thread. */ |
| 850 | void |
| 851 | rufetchtd(struct thread *td, struct rusage *ru) |
| 852 | { |
| 853 | struct proc *p; |
| 854 | uint64_t runtime, u; |
| 855 | |
| 856 | p = td->td_proc; |
| 857 | PROC_STATLOCK_ASSERT(p, MA_OWNED); |
| 858 | THREAD_LOCK_ASSERT(td, MA_OWNED); |
| 859 | /* |
| 860 | * If we are getting stats for the current thread, then add in the |
| 861 | * stats that this thread has accumulated in its current time slice. |
| 862 | * We reset the thread and CPU state as if we had performed a context |
| 863 | * switch right here. |
| 864 | */ |
| 865 | if (td == curthread) { |
| 866 | u = cpu_ticks(); |
| 867 | runtime = u - PCPU_GET(switchtime); |
| 868 | td->td_runtime += runtime; |
| 869 | td->td_incruntime += runtime; |
| 870 | PCPU_SET(switchtime, u); |
| 871 | } |
| 872 | ruxagg_locked(p, td); |
| 873 | *ru = td->td_ru; |
| 874 | calcru1(p, &td->td_rux, &ru->ru_utime, &ru->ru_stime); |
| 875 | } |
| 876 | |
| 877 | /* XXX: the MI version is too slow to use: */ |
| 878 | #ifndef __HAVE_INLINE_FLSLL |
no test coverage detected