diff --git a/Servers/WindowServer/Makefile b/Servers/WindowServer/Makefile index 9d407aa26f..3a068a7bf8 100644 --- a/Servers/WindowServer/Makefile +++ b/Servers/WindowServer/Makefile @@ -14,7 +14,6 @@ OBJS = \ WSCursor.o \ WSWindowFrame.o \ WSButton.o \ - WSCPUMonitor.o \ WSCompositor.o \ WSMenuManager.o \ WSMenuApplet.o \ diff --git a/Servers/WindowServer/WSCPUMonitor.cpp b/Servers/WindowServer/WSCPUMonitor.cpp deleted file mode 100644 index 175c5d2672..0000000000 --- a/Servers/WindowServer/WSCPUMonitor.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -WSCPUMonitor::WSCPUMonitor() - : m_thread([this] { - monitor(); - return 0; - }) -{ - m_thread.start(); -} - -void WSCPUMonitor::monitor() -{ - for (;;) { - static unsigned last_busy; - static unsigned last_idle; - unsigned busy; - unsigned idle; - get_cpu_usage(busy, idle); - unsigned busy_diff = busy - last_busy; - unsigned idle_diff = idle - last_idle; - last_busy = busy; - last_idle = idle; - float cpu = (float)busy_diff / (float)(busy_diff + idle_diff); - m_cpu_history.enqueue(cpu); - m_dirty = true; - sleep(1); - } -} - -void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle) -{ - busy = 0; - idle = 0; - - auto all_processes = CProcessStatisticsReader::get_all(); - - for (auto& it : all_processes) { - for (auto& jt : it.value.threads) { - if (it.value.pid == 0) - idle += jt.times_scheduled; - else - busy += jt.times_scheduled; - } - } -} - -void WSCPUMonitor::paint(Painter& painter, const Rect& rect) -{ - painter.fill_rect(rect, Color::Black); - int i = m_cpu_history.capacity() - m_cpu_history.size(); - for (auto cpu_usage : m_cpu_history) { - painter.draw_line( - { rect.x() + i, rect.bottom() }, - { rect.x() + i, (int)(rect.y() + (rect.height() - (cpu_usage * (float)rect.height()))) }, - Color::from_rgb(0xaa6d4b)); - ++i; - } -} diff --git a/Servers/WindowServer/WSCPUMonitor.h b/Servers/WindowServer/WSCPUMonitor.h deleted file mode 100644 index d69e79cfe3..0000000000 --- a/Servers/WindowServer/WSCPUMonitor.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include -#include - -class Painter; -class Rect; - -class WSCPUMonitor { -public: - WSCPUMonitor(); - - bool is_dirty() const { return m_dirty; } - void set_dirty(bool dirty) { m_dirty = dirty; } - int capacity() const { return m_cpu_history.capacity(); } - void paint(Painter&, const Rect&); - -private: - void monitor(); - - void get_cpu_usage(unsigned& busy, unsigned& idle); - - CircularQueue m_cpu_history; - bool m_dirty { false }; - LibThread::Thread m_thread; -}; diff --git a/Servers/WindowServer/WSMenuManager.cpp b/Servers/WindowServer/WSMenuManager.cpp index 7712bedaf6..fdb7042feb 100644 --- a/Servers/WindowServer/WSMenuManager.cpp +++ b/Servers/WindowServer/WSMenuManager.cpp @@ -29,10 +29,9 @@ WSMenuManager::WSMenuManager() m_timer = CTimer::construct(300, [this] { static time_t last_update_time; time_t now = time(nullptr); - if (now != last_update_time || m_cpu_monitor.is_dirty()) { + if (now != last_update_time) { tick_clock(); last_update_time = now; - m_cpu_monitor.set_dirty(false); } }); } @@ -121,11 +120,7 @@ void WSMenuManager::draw() painter.draw_text(time_rect, time_text, wm.font(), TextAlignment::CenterRight, Color::Black); // FIXME: This rect should only be computed once. - Rect cpu_rect { time_rect.right() - wm.font().width(time_text) - m_cpu_monitor.capacity() - 10, time_rect.y() + 1, m_cpu_monitor.capacity(), time_rect.height() - 2 }; - m_cpu_monitor.paint(painter, cpu_rect); - - // FIXME: This rect should only be computed once. - m_audio_rect = { cpu_rect.left() - 20, cpu_rect.y(), 12, 16 }; + m_audio_rect = { time_rect.right() - wm.font().width(time_text) - 20, time_rect.y() + 1, 12, 16 }; auto& audio_bitmap = m_audio_muted ? *m_muted_bitmap : *m_unmuted_bitmap; painter.blit(m_audio_rect.location(), audio_bitmap, audio_bitmap.rect()); diff --git a/Servers/WindowServer/WSMenuManager.h b/Servers/WindowServer/WSMenuManager.h index 69a33b7793..7569cd1674 100644 --- a/Servers/WindowServer/WSMenuManager.h +++ b/Servers/WindowServer/WSMenuManager.h @@ -4,7 +4,6 @@ #include #include #include -#include #include class AClientConnection; @@ -51,7 +50,6 @@ private: void tick_clock(); RefPtr m_window; - WSCPUMonitor m_cpu_monitor; String m_username; RefPtr m_timer;