mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
WindowServer: Remove WSCPUMonitor
We'll still have a CPU graph, just not in the WindowServer process.
This commit is contained in:
parent
c3029a6a1f
commit
86d84f1654
5 changed files with 2 additions and 104 deletions
|
@ -14,7 +14,6 @@ OBJS = \
|
||||||
WSCursor.o \
|
WSCursor.o \
|
||||||
WSWindowFrame.o \
|
WSWindowFrame.o \
|
||||||
WSButton.o \
|
WSButton.o \
|
||||||
WSCPUMonitor.o \
|
|
||||||
WSCompositor.o \
|
WSCompositor.o \
|
||||||
WSMenuManager.o \
|
WSMenuManager.o \
|
||||||
WSMenuApplet.o \
|
WSMenuApplet.o \
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
#include <AK/JsonArray.h>
|
|
||||||
#include <AK/JsonObject.h>
|
|
||||||
#include <AK/JsonValue.h>
|
|
||||||
#include <LibCore/CProcessStatisticsReader.h>
|
|
||||||
#include <WindowServer/WSCPUMonitor.h>
|
|
||||||
#include <WindowServer/WSEventLoop.h>
|
|
||||||
#include <WindowServer/WSWindowManager.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <AK/CircularQueue.h>
|
|
||||||
#include <LibThread/Thread.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
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<float, 30> m_cpu_history;
|
|
||||||
bool m_dirty { false };
|
|
||||||
LibThread::Thread m_thread;
|
|
||||||
};
|
|
|
@ -29,10 +29,9 @@ WSMenuManager::WSMenuManager()
|
||||||
m_timer = CTimer::construct(300, [this] {
|
m_timer = CTimer::construct(300, [this] {
|
||||||
static time_t last_update_time;
|
static time_t last_update_time;
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
if (now != last_update_time || m_cpu_monitor.is_dirty()) {
|
if (now != last_update_time) {
|
||||||
tick_clock();
|
tick_clock();
|
||||||
last_update_time = now;
|
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);
|
painter.draw_text(time_rect, time_text, wm.font(), TextAlignment::CenterRight, Color::Black);
|
||||||
|
|
||||||
// FIXME: This rect should only be computed once.
|
// 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_audio_rect = { time_rect.right() - wm.font().width(time_text) - 20, time_rect.y() + 1, 12, 16 };
|
||||||
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 };
|
|
||||||
|
|
||||||
auto& audio_bitmap = m_audio_muted ? *m_muted_bitmap : *m_unmuted_bitmap;
|
auto& audio_bitmap = m_audio_muted ? *m_muted_bitmap : *m_unmuted_bitmap;
|
||||||
painter.blit(m_audio_rect.location(), audio_bitmap, audio_bitmap.rect());
|
painter.blit(m_audio_rect.location(), audio_bitmap, audio_bitmap.rect());
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <LibCore/CObject.h>
|
#include <LibCore/CObject.h>
|
||||||
#include <LibCore/CTimer.h>
|
#include <LibCore/CTimer.h>
|
||||||
#include <WindowServer/WSMenuApplet.h>
|
#include <WindowServer/WSMenuApplet.h>
|
||||||
#include <WindowServer/WSCPUMonitor.h>
|
|
||||||
#include <WindowServer/WSWindow.h>
|
#include <WindowServer/WSWindow.h>
|
||||||
|
|
||||||
class AClientConnection;
|
class AClientConnection;
|
||||||
|
@ -51,7 +50,6 @@ private:
|
||||||
void tick_clock();
|
void tick_clock();
|
||||||
|
|
||||||
RefPtr<WSWindow> m_window;
|
RefPtr<WSWindow> m_window;
|
||||||
WSCPUMonitor m_cpu_monitor;
|
|
||||||
String m_username;
|
String m_username;
|
||||||
RefPtr<CTimer> m_timer;
|
RefPtr<CTimer> m_timer;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue