|
2 | 2 | #include "intctl.h" |
3 | 3 | #include "task/smp.h" |
4 | 4 | #include "string_builder.h" |
| 5 | +#include "timer.h" |
| 6 | +#include "metadata.h" |
5 | 7 |
|
6 | | -static bool gen_ctxt_processes(string_builder_t *builder){ |
7 | | - size_t all_ctxt = 0; |
8 | | - size_t processes_all = 0; |
9 | | - for (size_t i = 0; i < get_cpu_count(); i++) { |
| 8 | +char *proc_gen_stat(size_t *context_len) { |
| 9 | + string_builder_t *builder = create_string_builder(4096); |
| 10 | + size_t cpu_count = get_cpu_count(); |
| 11 | + |
| 12 | + uint64_t total_idle = 0; |
| 13 | + uint64_t total_system = 0; |
| 14 | + size_t processes_all = 0; |
| 15 | + size_t procs_running = 0; |
| 16 | + |
| 17 | + for (size_t i = 0; i < cpu_count; i++) { |
10 | 18 | cpu_local_t *info = get_cpu_local(i); |
11 | | - if(info == NULL) continue; |
12 | | - all_ctxt += info->jiffies; |
| 19 | + if (info == NULL || !info->enable) continue; |
| 20 | + total_system += info->jiffies - info->idle_jiffies; |
| 21 | + total_idle += info->idle_jiffies; |
13 | 22 | processes_all += info->task_count; |
| 23 | + if (info->current_task && info->current_task->status == T_RUNNING) |
| 24 | + procs_running++; |
14 | 25 | } |
15 | | - bool status = string_builder_append(builder,"ctxt %llu\n",all_ctxt); |
16 | | - status &= string_builder_append(builder,"processes %llu\n",processes_all); |
17 | | - return !status; |
18 | | -} |
19 | 26 |
|
20 | | -char *proc_gen_stat(size_t *context_len) { |
21 | | - string_builder_t *builder = create_string_builder(4096); |
| 27 | + string_builder_append(builder, "cpu 0 0 %llu %llu 0 0 0 0 0 0\n", |
| 28 | + total_system, total_idle); |
| 29 | + |
| 30 | + for (size_t i = 0; i < cpu_count; i++) { |
| 31 | + cpu_local_t *info = get_cpu_local(i); |
| 32 | + if (info == NULL || !info->enable) continue; |
| 33 | + uint64_t sys = info->jiffies - info->idle_jiffies; |
| 34 | + uint64_t idle = info->idle_jiffies; |
| 35 | + string_builder_append(builder, "cpu%llu 0 0 %llu %llu 0 0 0 0 0 0\n", |
| 36 | + (uint64_t)i, sys, idle); |
| 37 | + } |
| 38 | + |
| 39 | + string_builder_append(builder, "intr %llu\n", get_all_irq_count()); |
| 40 | + string_builder_append(builder, "ctxt %llu\n", total_system + total_idle); |
| 41 | + |
| 42 | + int64_t btime = mktime_universal(); |
| 43 | + if (btime > 0) { |
| 44 | + uint64_t uptime_sec = nano_time() / 1000000000ULL; |
| 45 | + string_builder_append(builder, "btime %llu\n", (uint64_t)(btime - uptime_sec)); |
| 46 | + } else { |
| 47 | + string_builder_append(builder, "btime 0\n"); |
| 48 | + } |
22 | 49 |
|
23 | | - if(gen_ctxt_processes(builder)) goto end; |
| 50 | + string_builder_append(builder, "processes %llu\n", (uint64_t)processes_all); |
| 51 | + string_builder_append(builder, "procs_running %llu\n", (uint64_t)procs_running); |
| 52 | + string_builder_append(builder, "procs_blocked 0\n"); |
| 53 | + string_builder_append(builder, "softirq 0 0 0 0 0 0 0 0 0 0 0\n"); |
24 | 54 |
|
25 | | -end: |
26 | 55 | *context_len = builder->size; |
27 | 56 | char *data = builder->data; |
28 | 57 | free(builder); |
|
0 commit comments