diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-07-17 22:22:22 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-18 07:23:26 +0200 |
commit | a9d1a86e6edc3fa3089a69f15d8ced52e8578d43 (patch) | |
tree | 35cb2ac07b77b17e251a7824296ecdb3d986bac2 | |
parent | 9724d540b6407d49b9351d680b697effc1a0ea11 (diff) | |
download | serenity-a9d1a86e6edc3fa3089a69f15d8ced52e8578d43.zip |
CProcessStatisticsReader: Be consistent about terminology from the kernel down
-rw-r--r-- | Applications/ProcessManager/ProcessModel.cpp | 32 | ||||
-rw-r--r-- | Applications/ProcessManager/ProcessModel.h | 8 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibCore/CProcessStatisticsReader.cpp | 24 | ||||
-rw-r--r-- | Libraries/LibCore/CProcessStatisticsReader.h | 26 | ||||
-rw-r--r-- | Servers/WindowServer/WSCPUMonitor.cpp | 4 | ||||
-rw-r--r-- | Userland/top.cpp | 26 |
7 files changed, 74 insertions, 48 deletions
diff --git a/Applications/ProcessManager/ProcessModel.cpp b/Applications/ProcessManager/ProcessModel.cpp index 462fff7daa..428e8779cf 100644 --- a/Applications/ProcessManager/ProcessModel.cpp +++ b/Applications/ProcessManager/ProcessModel.cpp @@ -120,16 +120,16 @@ GVariant ProcessModel::data(const GModelIndex& index, Role role) const ASSERT_NOT_REACHED(); return 3; case Column::Virtual: - return (int)process.current_state.virtual_size; + return (int)process.current_state.amount_virtual; case Column::Physical: - return (int)process.current_state.physical_size; + return (int)process.current_state.amount_resident; case Column::CPU: return process.current_state.cpu_percent; case Column::Name: return process.current_state.name; // FIXME: GVariant with unsigned? case Column::Syscalls: - return (int)process.current_state.syscalls; + return (int)process.current_state.syscall_count; } ASSERT_NOT_REACHED(); return {}; @@ -156,16 +156,16 @@ GVariant ProcessModel::data(const GModelIndex& index, Role role) const return *m_normal_priority_icon; return process.current_state.priority; case Column::Virtual: - return pretty_byte_size(process.current_state.virtual_size); + return pretty_byte_size(process.current_state.amount_virtual); case Column::Physical: - return pretty_byte_size(process.current_state.physical_size); + return pretty_byte_size(process.current_state.amount_resident); case Column::CPU: return process.current_state.cpu_percent; case Column::Name: return process.current_state.name; // FIXME: It's weird that GVariant doesn't support unsigned ints. Should it? case Column::Syscalls: - return (int)process.current_state.syscalls; + return (int)process.current_state.syscall_count; } } @@ -176,24 +176,24 @@ void ProcessModel::update() { auto all_processes = CProcessStatisticsReader::get_all(); - unsigned last_sum_nsched = 0; + unsigned last_sum_times_scheduled = 0; for (auto& it : m_processes) - last_sum_nsched += it.value->current_state.nsched; + last_sum_times_scheduled += it.value->current_state.times_scheduled; HashTable<pid_t> live_pids; - unsigned sum_nsched = 0; + unsigned sum_times_scheduled = 0; for (auto& it : all_processes) { ProcessState state; state.pid = it.value.pid; - state.nsched = it.value.nsched; + state.times_scheduled = it.value.times_scheduled; state.user = it.value.username; state.priority = it.value.priority; - state.syscalls = it.value.syscalls; + state.syscall_count = it.value.syscall_count; state.state = it.value.state; state.name = it.value.name; - state.virtual_size = it.value.virtual_size; - state.physical_size = it.value.physical_size; - sum_nsched += it.value.nsched; + state.amount_virtual = it.value.amount_virtual; + state.amount_resident = it.value.amount_resident; + sum_times_scheduled += it.value.times_scheduled; { auto pit = m_processes.find(it.value.pid); if (pit == m_processes.end()) @@ -216,8 +216,8 @@ void ProcessModel::update() continue; } auto& process = *it.value; - u32 nsched_diff = process.current_state.nsched - process.previous_state.nsched; - process.current_state.cpu_percent = ((float)nsched_diff * 100) / (float)(sum_nsched - last_sum_nsched); + u32 times_scheduled_diff = process.current_state.times_scheduled - process.previous_state.times_scheduled; + process.current_state.cpu_percent = ((float)times_scheduled_diff * 100) / (float)(sum_times_scheduled - last_sum_times_scheduled); if (it.key != 0) { total_cpu_percent += process.current_state.cpu_percent; m_pids.append(it.key); diff --git a/Applications/ProcessManager/ProcessModel.h b/Applications/ProcessManager/ProcessModel.h index 4371367a35..046823ba9a 100644 --- a/Applications/ProcessManager/ProcessModel.h +++ b/Applications/ProcessManager/ProcessModel.h @@ -41,14 +41,14 @@ private: struct ProcessState { pid_t pid; - unsigned nsched; + unsigned times_scheduled; String name; String state; String user; String priority; - size_t virtual_size; - size_t physical_size; - unsigned syscalls; + size_t amount_virtual; + size_t amount_resident; + unsigned syscall_count; float cpu_percent; }; diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 5fd6056b96..e5a340239e 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -585,6 +585,8 @@ ByteBuffer procfs$all(InodeIdentifier) InterruptDisabler disabler; auto processes = Process::all_processes(); JsonArray array; + + // Keep this in sync with CProcessStatistics. auto build_process = [&](const Process& process) { JsonObject process_object; process_object.set("pid", process.pid()); diff --git a/Libraries/LibCore/CProcessStatisticsReader.cpp b/Libraries/LibCore/CProcessStatisticsReader.cpp index cb0a7f4e46..74331797df 100644 --- a/Libraries/LibCore/CProcessStatisticsReader.cpp +++ b/Libraries/LibCore/CProcessStatisticsReader.cpp @@ -23,16 +23,28 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all() json.as_array().for_each([&](auto& value) { const JsonObject& process_object = value.as_object(); CProcessStatistics process; + + // kernel data first process.pid = process_object.get("pid").to_u32(); - process.nsched = process_object.get("times_scheduled").to_u32(); + process.times_scheduled = process_object.get("times_scheduled").to_u32(); + process.pgid = process_object.get("pgid").to_u32(); + process.sid = process_object.get("sid").to_u32(); process.uid = process_object.get("uid").to_u32(); - process.username = username_from_uid(process.uid); - process.priority = process_object.get("priority").to_string(); - process.syscalls = process_object.get("syscall_count").to_u32(); + process.gid = process_object.get("gid").to_u32(); process.state = process_object.get("state").to_string(); + process.ppid = process_object.get("ppid").to_u32(); + process.nfds = process_object.get("nfds").to_u32(); process.name = process_object.get("name").to_string(); - process.virtual_size = process_object.get("amount_virtual").to_u32(); - process.physical_size = process_object.get("amount_resident").to_u32(); + process.tty = process_object.get("tty").to_string(); + process.amount_virtual = process_object.get("amount_virtual").to_u32(); + process.amount_resident = process_object.get("amount_resident").to_u32(); + process.amount_shared = process_object.get("amount_shared").to_u32(); + process.ticks = process_object.get("ticks").to_u32(); + process.priority = process_object.get("priority").to_string(); + process.syscall_count = process_object.get("syscall_count").to_u32(); + + // and synthetic data last + process.username = username_from_uid(process.uid); map.set(process.pid, process); }); diff --git a/Libraries/LibCore/CProcessStatisticsReader.h b/Libraries/LibCore/CProcessStatisticsReader.h index c26312bc89..034b97a363 100644 --- a/Libraries/LibCore/CProcessStatisticsReader.h +++ b/Libraries/LibCore/CProcessStatisticsReader.h @@ -4,16 +4,28 @@ #include <AK/HashMap.h> struct CProcessStatistics { + // Keep this in sync with /proc/all. + // From the kernel side: pid_t pid; - unsigned nsched; - String name; - String state; - String username; + unsigned times_scheduled; + unsigned pgid; + unsigned sid; uid_t uid; + gid_t gid; + String state; + pid_t ppid; + unsigned nfds; + String name; + String tty; + size_t amount_virtual; + size_t amount_resident; + size_t amount_shared; + unsigned ticks; String priority; - size_t virtual_size; - size_t physical_size; - unsigned syscalls; + unsigned syscall_count; + + // synthetic + String username; }; class CProcessStatisticsReader { diff --git a/Servers/WindowServer/WSCPUMonitor.cpp b/Servers/WindowServer/WSCPUMonitor.cpp index 5554a9493a..c29d408c22 100644 --- a/Servers/WindowServer/WSCPUMonitor.cpp +++ b/Servers/WindowServer/WSCPUMonitor.cpp @@ -40,9 +40,9 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle) for (auto& it : all_processes) { if (it.value.pid == 0) - idle += it.value.nsched; + idle += it.value.times_scheduled; else - busy += it.value.nsched; + busy += it.value.times_scheduled; } } diff --git a/Userland/top.cpp b/Userland/top.cpp index d60f86c24f..48370c385e 100644 --- a/Userland/top.cpp +++ b/Userland/top.cpp @@ -13,14 +13,14 @@ struct ProcessData { CProcessStatistics stats; - unsigned nsched_since_prev { 0 }; + unsigned times_scheduled_since_prev { 0 }; unsigned cpu_percent { 0 }; unsigned cpu_percent_decimal { 0 }; }; struct Snapshot { HashMap<unsigned, ProcessData> map; - u32 sum_nsched { 0 }; + u32 sum_times_scheduled { 0 }; }; static Snapshot get_snapshot() @@ -31,7 +31,7 @@ static Snapshot get_snapshot() for (auto& it : all_processes) { auto& stats = it.value; - snapshot.sum_nsched += stats.nsched; + snapshot.sum_times_scheduled += stats.times_scheduled; ProcessData process_data; process_data.stats = stats; snapshot.map.set(stats.pid, move(process_data)); @@ -47,7 +47,7 @@ int main(int, char**) usleep(10000); for (;;) { auto current = get_snapshot(); - auto sum_diff = current.sum_nsched - prev.sum_nsched; + auto sum_diff = current.sum_times_scheduled - prev.sum_times_scheduled; printf("\033[3J\033[H\033[2J"); printf("\033[47;30m%6s %3s %-8s %-8s %6s %6s %4s %s\033[K\033[0m\n", @@ -63,20 +63,20 @@ int main(int, char**) pid_t pid = it.key; if (pid == 0) continue; - u32 nsched_now = it.value.stats.nsched; + u32 times_scheduled_now = it.value.stats.times_scheduled; auto jt = prev.map.find(pid); if (jt == prev.map.end()) continue; - u32 nsched_before = (*jt).value.stats.nsched; - u32 nsched_diff = nsched_now - nsched_before; - it.value.nsched_since_prev = nsched_diff; - it.value.cpu_percent = ((nsched_diff * 100) / sum_diff); - it.value.cpu_percent_decimal = (((nsched_diff * 1000) / sum_diff) % 10); + u32 times_scheduled_before = (*jt).value.stats.times_scheduled; + u32 times_scheduled_diff = times_scheduled_now - times_scheduled_before; + it.value.times_scheduled_since_prev = times_scheduled_diff; + it.value.cpu_percent = ((times_scheduled_diff * 100) / sum_diff); + it.value.cpu_percent_decimal = (((times_scheduled_diff * 1000) / sum_diff) % 10); processes.append(&it.value); } quick_sort(processes.begin(), processes.end(), [](auto* p1, auto* p2) { - return p2->nsched_since_prev < p1->nsched_since_prev; + return p2->times_scheduled_since_prev < p1->times_scheduled_since_prev; }); for (auto* process : processes) { @@ -85,8 +85,8 @@ int main(int, char**) process->stats.priority[0], process->stats.username.characters(), process->stats.state.characters(), - process->stats.virtual_size / 1024, - process->stats.physical_size / 1024, + process->stats.amount_virtual / 1024, + process->stats.amount_resident / 1024, process->cpu_percent, process->cpu_percent_decimal, process->stats.name.characters()); |