Skip to content
Snippets Groups Projects
Commit c152b50e authored by Glauber Costa's avatar Glauber Costa Committed by Pekka Enberg
Browse files

sched: export total sys and user time statistics


This is one of the statistics that shows up in /proc/self/stat under Linux, but
this is generally interesting for applications. Since we don't have kernel mode
and userspace mode, it is very hard to differentiate between "time spent in
userspace" and "kernel time spent on behalf of the process". Therefore, we will
present system time as always 0. If we wanted, we could at least differentiate
clearly osv-specific threads as system time, but there is no need to go through
the trouble now.

Signed-off-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 7bdbb328
No related branches found
No related tags found
No related merge requests found
......@@ -552,6 +552,22 @@ mutex thread_map_mutex;
std::unordered_map<unsigned long, thread *> thread_map
__attribute__((init_priority((int)init_prio::threadlist)));
static thread_runtime::duration total_app_time_exited(0);
std::chrono::nanoseconds osv_run_stats()
{
thread_runtime::duration total_app_time;
WITH_LOCK(thread_map_mutex) {
total_app_time = total_app_time_exited;
for (auto th : thread_map) {
thread *t = th.second;
total_app_time += t->thread_clock();
}
}
return std::chrono::duration_cast<std::chrono::nanoseconds>(total_app_time);
}
// We reserve a space in the end of the PID space, so we can reuse those
// special purpose ids for other things. 4096 positions is arbitrary, but
// <<should be enough for anybody>> (tm)
......@@ -645,6 +661,7 @@ thread::~thread()
}
WITH_LOCK(thread_map_mutex) {
thread_map.erase(_id);
total_app_time_exited += _total_cpu_time;
}
if (_attr._stack.deleter) {
_attr._stack.deleter(_attr._stack);
......
......@@ -621,6 +621,8 @@ private:
static callback_dispatch _dispatch;
};
std::chrono::nanoseconds osv_run_stats();
class thread_runtime_compare {
public:
bool operator()(const thread& t1, const thread& t2) const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment