ladybird/Userland/Libraries/LibWebView/ProcessManager.h
Andrew Kaster 31c0d00ab1 Ladybird: Add a simple TaskManager window for tracking child processes
This implementation uses a really basic WebView to update stats once
a second. In the future it might make more sense to both move the
details into LibWebView, and to create a native widget for each platform
to remove the overhead of having an extra WebView.
2024-04-02 09:52:34 -06:00

55 lines
1,017 B
C++

/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibCore/EventReceiver.h>
#include <LibWebView/Forward.h>
#pragma once
namespace WebView {
enum class ProcessType {
Chrome,
WebContent,
WebWorker,
SQLServer,
RequestServer,
ImageDecoder,
};
struct ProcessInfo {
ProcessType type;
pid_t pid;
u64 memory_usage_kib = 0;
float cpu_percent = 0.0f;
};
ProcessType process_type_from_name(StringView);
StringView process_name_from_type(ProcessType type);
class ProcessManager {
public:
static ProcessManager& the();
static void initialize();
void add_process(WebView::ProcessType, pid_t);
void remove_process(pid_t);
void update_all_processes();
Vector<ProcessInfo> processes() const { return m_processes; }
String generate_html();
private:
ProcessManager();
~ProcessManager();
Vector<ProcessInfo> m_processes;
};
}