Skip to content

Commit

Permalink
Add more information to /proc/stat
Browse files Browse the repository at this point in the history
Now it's compatible with Linux's implementation
  • Loading branch information
nimelehin committed Nov 18, 2020
1 parent b6d230e commit d45c092
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fs/proc/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ static int proc_show_version(struct proc_entry *UNUSED(entry), struct proc_data
}

static int proc_show_stat(struct proc_entry *UNUSED(entry), struct proc_data *buf) {
int ncpus = get_cpu_count();
struct cpu_usage usage = get_cpu_usage();
proc_printf(buf, "cpu %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64"\n", usage.user_ticks, usage.nice_ticks, usage.system_ticks, usage.idle_ticks);
struct uptime_info uptime_info = get_uptime();
unsigned uptime = uptime_info.uptime_ticks;

uint64_t one_cpu_user_ticks = usage.user_ticks / ncpus;
uint64_t one_cpu_system_ticks = usage.system_ticks / ncpus;
uint64_t one_cpu_idle_ticks = usage.idle_ticks / ncpus;
uint64_t one_cpu_nice_ticks = usage.nice_ticks / ncpus;

proc_printf(buf, "cpu %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" 0 0 0 0\n", usage.user_ticks, usage.nice_ticks, usage.system_ticks, usage.idle_ticks);
for (int i = 0; i < ncpus; i++) {
proc_printf(buf, "cpu%d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" 0 0 0 0\n", i, one_cpu_user_ticks, one_cpu_nice_ticks, one_cpu_system_ticks, one_cpu_idle_ticks);
}
proc_printf(buf, "ctxt 0\n");
proc_printf(buf, "btime %u\n", uptime);
proc_printf(buf, "processes %d\n", alive_task_count);
proc_printf(buf, "procs_running %d\n", alive_task_count - blocked_task_count);
proc_printf(buf, "procs_blocked %d\n", blocked_task_count);
return 0;
}

Expand Down

0 comments on commit d45c092

Please sign in to comment.