1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

ResourceGraph.Applet: Host both CPU and memory applet in one process

No reason we can't host these in the same process, and then we have
one less process to dynamically link at boot. :^)
This commit is contained in:
Andreas Kling 2021-04-04 18:14:48 +02:00
parent 0490540e21
commit 436a1dce34
2 changed files with 34 additions and 46 deletions

View file

@ -75,16 +75,8 @@ SocketPermissions=660
Priority=low Priority=low
User=clipboard User=clipboard
[CPUGraph.Applet] [ResourceGraph.Applet]
Executable=/bin/ResourceGraph.Applet Arguments=--cpu=CPUGraph,#00bb00 --memory=MemoryGraph,#00bbbb
Arguments=--cpu --name=CPUGraph --color=#00bb00
Priority=low
KeepAlive=1
User=anon
[MemoryGraph.Applet]
Executable=/bin/ResourceGraph.Applet
Arguments=--memory --name=MemoryGraph --color=#00bbbb
Priority=low Priority=low
KeepAlive=1 KeepAlive=1
User=anon User=anon

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de> * Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
* All rights reserved. * All rights reserved.
* *
@ -215,49 +215,45 @@ int main(int argc, char** argv)
return 1; return 1;
} }
bool cpu = false; const char* cpu = nullptr;
bool memory = false; const char* memory = nullptr;
const char* name = nullptr;
const char* color = nullptr;
const char* error_color = nullptr;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.add_option(cpu, "Show CPU usage", "cpu", 'C'); args_parser.add_option(cpu, "Create CPU graph", "cpu", 'C', "cpu");
args_parser.add_option(memory, "Show memory usage", "memory", 'M'); args_parser.add_option(memory, "Create memory graph", "memory", 'M', "memory");
args_parser.add_option(name, "Applet name used by WindowServer.ini to set the applet order", "name", 'n', "name");
args_parser.add_option(color, "Graph color", "color", 'c', "color");
args_parser.add_option(error_color, "Graph color (error)", "error-color", 'e', "error-color");
args_parser.parse(argc, argv); args_parser.parse(argc, argv);
if (!cpu && !memory) { if (!cpu && !memory) {
printf("Either --cpu or --memory option must be used"); printf("At least one of --cpu or --memory must be used");
return 1; return 1;
} }
if (cpu && memory) {
printf("--cpu and --memory options must not be used together"); NonnullRefPtrVector<GUI::Window> applet_windows;
return 1;
} auto create_applet = [&](GraphType graph_type, StringView spec) {
GraphType graph_type; auto parts = spec.split_view(',');
dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec);
if (parts.size() != 2)
return;
auto name = parts[0];
auto graph_color = Gfx::Color::from_string(parts[1]);
auto window = GUI::Window::construct();
window->set_title(name);
window->set_window_type(GUI::WindowType::Applet);
window->resize(GraphWidget::history_size + 2, 15);
window->set_main_widget<GraphWidget>(graph_type, graph_color, Optional<Gfx::Color> {});
window->show();
applet_windows.append(move(window));
};
if (cpu) if (cpu)
graph_type = GraphType::CPU; create_applet(GraphType::CPU, cpu);
if (memory) if (memory)
graph_type = GraphType::Memory; create_applet(GraphType::Memory, memory);
if (name == nullptr)
name = "ResourceGraph";
Optional<Gfx::Color> graph_color, graph_error_color;
if (color != nullptr)
graph_color = Gfx::Color::from_string(color);
if (error_color != nullptr)
graph_error_color = Gfx::Color::from_string(error_color);
auto window = GUI::Window::construct();
window->set_title(name);
window->set_window_type(GUI::WindowType::Applet);
window->resize(GraphWidget::history_size + 2, 15);
window->set_main_widget<GraphWidget>(graph_type, graph_color, graph_error_color);
window->show();
if (unveil("/res", "r") < 0) { if (unveil("/res", "r") < 0) {
perror("unveil"); perror("unveil");