[gnome-builder] plugins/sysprof: stub gnome-builder-sysprof libexec tool
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/sysprof: stub gnome-builder-sysprof libexec tool
- Date: Wed, 20 Jul 2022 19:07:11 +0000 (UTC)
commit ef156c6cfc76b9988eba70f305c04e87db2dd01b
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 20 12:07:05 2022 -0700
plugins/sysprof: stub gnome-builder-sysprof libexec tool
The goal for this subprocess is to provide management of a profiling
session wrapped from IdeRunTool. It will eventually communicate D-Bus
with the spawning process so that we can emit information about the
data collection live and let Builder send signals to the subprocess.
src/plugins/sysprof/gnome-builder-sysprof.c | 123 ++++++++++++++++++++++++++++
src/plugins/sysprof/meson.build | 15 +++-
2 files changed, 136 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/sysprof/gnome-builder-sysprof.c b/src/plugins/sysprof/gnome-builder-sysprof.c
new file mode 100644
index 000000000..99c796f5b
--- /dev/null
+++ b/src/plugins/sysprof/gnome-builder-sysprof.c
@@ -0,0 +1,123 @@
+/* gnome-builder-sysprof.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+
+#include <sysprof.h>
+#include <unistd.h>
+
+static int read_fd = -1;
+static int write_fd = -1;
+static char **env = NULL;
+static gboolean aid_cpu;
+static gboolean aid_perf;
+static gboolean aid_memory;
+static gboolean aid_memprof;
+static gboolean aid_disk;
+static gboolean aid_net;
+static gboolean aid_energy;
+static gboolean aid_battery;
+static gboolean aid_compositor;
+static gboolean aid_tracefd;
+static gboolean no_throttle;
+static const GOptionEntry options[] = {
+ { "read-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &read_fd },
+ { "write-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &write_fd },
+ { "env", 0, 0, G_OPTION_ARG_STRING_ARRAY, &env, "Add an environment variable to the spawned process",
"KEY=VALUE" },
+ { "cpu", 0, 0, G_OPTION_ARG_NONE, &aid_cpu, "Track CPU usage and frequency" },
+ { "perf", 0, 0, G_OPTION_ARG_NONE, &aid_perf, "Record stack traces with perf" },
+ { "memory", 0, 0, G_OPTION_ARG_NONE, &aid_memory, "Record basic system memory usage" },
+ { "memprof", 0, 0, G_OPTION_ARG_NONE, &aid_memprof, "Record stack traces during memory allocations" },
+ { "disk", 0, 0, G_OPTION_ARG_NONE, &aid_disk, "Record disk usage information" },
+ { "net", 0, 0, G_OPTION_ARG_NONE, &aid_net, "Record network usage information" },
+ { "energy", 0, 0, G_OPTION_ARG_NONE, &aid_energy, "Record energy usage using RAPL" },
+ { "battery", 0, 0, G_OPTION_ARG_NONE, &aid_battery, "Record battery charge and discharge rates" },
+ { "compositor", 0, 0, G_OPTION_ARG_NONE, &aid_compositor, "Record GNOME Shell compositor information" },
+ { "no-throttle", 0, 0, G_OPTION_ARG_NONE, &no_throttle, "Disable CPU throttling" },
+ { "tracefd-aid", 0, 0, G_OPTION_ARG_NONE, &aid_tracefd, "Provide TRACEFD to subprocess" },
+ { NULL }
+};
+
+static void
+split_argv (int argc,
+ char **argv,
+ int *our_argc,
+ char ***our_argv,
+ int *sub_argc,
+ char ***sub_argv)
+{
+ gboolean found_split = FALSE;
+
+ *our_argc = 0;
+ *our_argv = g_new0 (char *, 1);
+
+ *sub_argc = 0;
+ *sub_argv = g_new0 (char *, 1);
+
+ for (int i = 0; i < argc; i++)
+ {
+ if (g_strcmp0 (argv[i], "--") == 0)
+ {
+ found_split = TRUE;
+ }
+ else if (found_split)
+ {
+ (*sub_argv) = g_realloc_n (*sub_argv, *sub_argc + 2, sizeof (char *));
+ (*sub_argv)[*sub_argc] = g_strdup (argv[i]);
+ (*sub_argv)[*sub_argc+1] = NULL;
+ (*sub_argc)++;
+ }
+ else
+ {
+ (*our_argv) = g_realloc_n (*our_argv, *our_argc + 2, sizeof (char *));
+ (*our_argv)[*our_argc] = g_strdup (argv[i]);
+ (*our_argv)[*our_argc+1] = NULL;
+ (*our_argc)++;
+ }
+ }
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GError) error = NULL;
+ g_auto(GStrv) our_argv = NULL;
+ g_auto(GStrv) sub_argv = NULL;
+ int our_argc;
+ int sub_argc;
+
+ sysprof_clock_init ();
+
+ split_argv (argc, argv, &our_argc, &our_argv, &sub_argc, &sub_argv);
+
+ context = g_option_context_new ("-- COMMAND");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ if (!g_option_context_parse (context, &our_argc, &our_argv, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ return EXIT_FAILURE;
+ }
+
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/plugins/sysprof/meson.build b/src/plugins/sysprof/meson.build
index b19174f80..6b1b50b4a 100644
--- a/src/plugins/sysprof/meson.build
+++ b/src/plugins/sysprof/meson.build
@@ -1,8 +1,11 @@
if get_option('plugin_sysprof')
+libsysprof_dep = dependency('sysprof-4', version: '>= 3.45.0')
+libsysprof_ui_dep = dependency('sysprof-ui-5', version: '>= 3.45.0')
+
plugins_deps += [
- dependency('sysprof-4', version: '>= 3.45.0'),
- dependency('sysprof-ui-5', version: '>= 3.45.0'),
+ libsysprof_dep,
+ libsysprof_ui_dep,
]
plugins_sources += files([
@@ -23,4 +26,12 @@ plugins_sources += plugin_sysprof_resources
install_data(['org.gnome.builder.sysprof.gschema.xml'], install_dir: schema_dir)
+gnome_builder_sysprof_sources = ['gnome-builder-sysprof.c']
+gnome_builder_sysprof_deps = [libsysprof_dep]
+gnome_builder_sysprof = executable('gnome-builder-sysprof', gnome_builder_sysprof_sources,
+ install: true,
+ install_dir: get_option('libexecdir'),
+ dependencies: gnome_builder_sysprof_deps,
+)
+
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]