summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-04 18:14:48 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-04 20:13:55 +0200
commit436a1dce340ae3373c0425d800627bdcd99b1f2d (patch)
tree00d7d5f844d0c8fd6ea9ea080c63864f8efec73a /Userland
parent0490540e21b6e6f114f28a8eeffa69d7b656f6a7 (diff)
downloadserenity-436a1dce340ae3373c0425d800627bdcd99b1f2d.zip
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. :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applets/ResourceGraph/main.cpp64
1 files changed, 30 insertions, 34 deletions
diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp
index 2983aaad37..d686190246 100644
--- a/Userland/Applets/ResourceGraph/main.cpp
+++ b/Userland/Applets/ResourceGraph/main.cpp
@@ -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>
* All rights reserved.
*
@@ -215,49 +215,45 @@ int main(int argc, char** argv)
return 1;
}
- bool cpu = false;
- bool memory = false;
- const char* name = nullptr;
- const char* color = nullptr;
- const char* error_color = nullptr;
+ const char* cpu = nullptr;
+ const char* memory = nullptr;
Core::ArgsParser args_parser;
- args_parser.add_option(cpu, "Show CPU usage", "cpu", 'C');
- args_parser.add_option(memory, "Show memory usage", "memory", 'M');
- 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.add_option(cpu, "Create CPU graph", "cpu", 'C', "cpu");
+ args_parser.add_option(memory, "Create memory graph", "memory", 'M', "memory");
args_parser.parse(argc, argv);
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;
}
- if (cpu && memory) {
- printf("--cpu and --memory options must not be used together");
- return 1;
- }
- GraphType graph_type;
- if (cpu)
- graph_type = GraphType::CPU;
- if (memory)
- graph_type = GraphType::Memory;
- if (name == nullptr)
- name = "ResourceGraph";
+ NonnullRefPtrVector<GUI::Window> applet_windows;
+
+ auto create_applet = [&](GraphType graph_type, StringView spec) {
+ auto parts = spec.split_view(',');
- 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);
+ dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec);
- auto window = GUI::Window::construct();
- window->set_title(name);
- window->set_window_type(GUI::WindowType::Applet);
- window->resize(GraphWidget::history_size + 2, 15);
+ if (parts.size() != 2)
+ return;
- window->set_main_widget<GraphWidget>(graph_type, graph_color, graph_error_color);
- window->show();
+ 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)
+ create_applet(GraphType::CPU, cpu);
+ if (memory)
+ create_applet(GraphType::Memory, memory);
if (unveil("/res", "r") < 0) {
perror("unveil");