mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 08:00:53 +00:00
tools: remove more tooling
These eventually all go away.
This commit is contained in:
@ -1,94 +0,0 @@
|
|||||||
/* list-threads.c
|
|
||||||
*
|
|
||||||
* Copyright 2019 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 <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <sysprof-capture.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "../libsysprof/sysprof-capture-autocleanups.h"
|
|
||||||
|
|
||||||
static bool
|
|
||||||
foreach_cb (const SysprofCaptureFrame *frame,
|
|
||||||
void *user_data)
|
|
||||||
{
|
|
||||||
const SysprofCaptureSample *sample = (SysprofCaptureSample *)frame;
|
|
||||||
GHashTable *seen = user_data;
|
|
||||||
|
|
||||||
if (!g_hash_table_contains (seen, GINT_TO_POINTER (sample->tid)))
|
|
||||||
g_hash_table_insert (seen,
|
|
||||||
GINT_TO_POINTER (sample->tid),
|
|
||||||
GINT_TO_POINTER (frame->pid));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
gint
|
|
||||||
main (gint argc,
|
|
||||||
gchar *argv[])
|
|
||||||
{
|
|
||||||
static const SysprofCaptureFrameType types[] = {
|
|
||||||
SYSPROF_CAPTURE_FRAME_SAMPLE,
|
|
||||||
};
|
|
||||||
g_autoptr(GHashTable) seen = NULL;
|
|
||||||
g_autoptr(SysprofCaptureReader) reader = NULL;
|
|
||||||
g_autoptr(SysprofCaptureCursor) cursor = NULL;
|
|
||||||
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_strcmp0 ("-", argv[1]) == 0)
|
|
||||||
reader = sysprof_capture_reader_new_from_fd (dup (STDIN_FILENO));
|
|
||||||
else
|
|
||||||
reader = sysprof_capture_reader_new (argv[1]);
|
|
||||||
|
|
||||||
if (reader == NULL)
|
|
||||||
{
|
|
||||||
g_printerr ("Failed to open %s capture\n", argv[1]);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
seen = g_hash_table_new (NULL, NULL);
|
|
||||||
|
|
||||||
cursor = sysprof_capture_cursor_new (reader);
|
|
||||||
sysprof_capture_cursor_add_condition (cursor,
|
|
||||||
sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types));
|
|
||||||
sysprof_capture_cursor_foreach (cursor, foreach_cb, seen);
|
|
||||||
|
|
||||||
{
|
|
||||||
GHashTableIter iter;
|
|
||||||
gpointer k, v;
|
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, seen);
|
|
||||||
|
|
||||||
while (g_hash_table_iter_next (&iter, &k, &v))
|
|
||||||
{
|
|
||||||
g_print ("pid=%d tid=%d\n",
|
|
||||||
GPOINTER_TO_INT (v),
|
|
||||||
GPOINTER_TO_INT (k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
@ -1,58 +1,6 @@
|
|||||||
tools_deps = [
|
#sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c',
|
||||||
dependency('glib-2.0'),
|
# dependencies: [libsysprof_static_dep, polkit_dep, polkit_agent_dep],
|
||||||
libsysprof_capture_dep,
|
# c_args: tools_cflags,
|
||||||
]
|
# install_dir: get_option('bindir'),
|
||||||
|
# install: true,
|
||||||
tools_cflags = [ '-DSYSPROF_COMPILATION ']
|
#)
|
||||||
|
|
||||||
sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c',
|
|
||||||
dependencies: [libsysprof_static_dep, polkit_dep, polkit_agent_dep],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install_dir: get_option('bindir'),
|
|
||||||
install: true,
|
|
||||||
)
|
|
||||||
|
|
||||||
sysprof_cat = executable('sysprof-cat', 'sysprof-cat.c',
|
|
||||||
dependencies: tools_deps,
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
|
|
||||||
if get_option('libsysprof')
|
|
||||||
sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c',
|
|
||||||
dependencies: [libsysprof_dep],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
|
|
||||||
rewrite_pid = executable('rewrite-pid', ['rewrite-pid.c'],
|
|
||||||
dependencies: [libsysprof_dep],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if get_option('sysprofd') == 'bundled' or get_option('libsysprof')
|
|
||||||
sysprof_profiler_ctl = executable('sysprof-profiler-ctl',
|
|
||||||
[ 'sysprof-profiler-ctl.c', ipc_profiler_src ],
|
|
||||||
dependencies: [ tools_deps, dependency('gio-unix-2.0', version: glib_req_version) ],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
list_threads = executable('list-threads', ['list-threads.c'],
|
|
||||||
dependencies: [ tools_deps ],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install: false,
|
|
||||||
)
|
|
||||||
|
|
||||||
if get_option('agent')
|
|
||||||
sysprof_agent = executable('sysprof-agent',
|
|
||||||
['sysprof-agent.c', ipc_agent_src],
|
|
||||||
dependencies: [libsysprof_static_dep],
|
|
||||||
c_args: tools_cflags,
|
|
||||||
install_dir: get_option('bindir'),
|
|
||||||
install: true,
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|||||||
@ -1,129 +0,0 @@
|
|||||||
/* rewrite-pid.c
|
|
||||||
*
|
|
||||||
* Copyright 2023 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 <gio/gio.h>
|
|
||||||
#include <sysprof-capture.h>
|
|
||||||
|
|
||||||
/* Rewrite a capture file to change PID X to Y */
|
|
||||||
|
|
||||||
static void
|
|
||||||
rewrite_pid (guint8 *data,
|
|
||||||
gsize len,
|
|
||||||
int old_pid,
|
|
||||||
int new_pid)
|
|
||||||
{
|
|
||||||
SysprofCaptureFileHeader header;
|
|
||||||
guint8 *endptr = &data[len];
|
|
||||||
guint8 *frameptr = (guint8 *)&data[sizeof (SysprofCaptureFileHeader)];
|
|
||||||
gboolean swap;
|
|
||||||
|
|
||||||
if (len < sizeof header)
|
|
||||||
return;
|
|
||||||
|
|
||||||
memcpy (&header, data, sizeof header);
|
|
||||||
|
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
||||||
swap = !header.little_endian;
|
|
||||||
#else
|
|
||||||
swap = header.little_endian;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (swap)
|
|
||||||
{
|
|
||||||
old_pid = GUINT16_SWAP_LE_BE (old_pid);
|
|
||||||
new_pid = GUINT16_SWAP_LE_BE (new_pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (frameptr < endptr)
|
|
||||||
{
|
|
||||||
SysprofCaptureFrame *frame = (SysprofCaptureFrame *)frameptr;
|
|
||||||
|
|
||||||
if (frame->pid == old_pid)
|
|
||||||
frame->pid = new_pid;
|
|
||||||
|
|
||||||
if (swap)
|
|
||||||
frameptr += GUINT16_SWAP_LE_BE (frame->len);
|
|
||||||
else
|
|
||||||
frameptr += frame->len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_args (int argc,
|
|
||||||
char **argv,
|
|
||||||
const char **file,
|
|
||||||
int *old_pid,
|
|
||||||
int *new_pid)
|
|
||||||
{
|
|
||||||
if (argc != 4)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
*file = argv[1];
|
|
||||||
|
|
||||||
if (!g_file_test (*file, G_FILE_TEST_IS_REGULAR))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
*old_pid = g_ascii_strtoll (argv[2], NULL, 10);
|
|
||||||
*new_pid = g_ascii_strtoll (argv[3], NULL, 10);
|
|
||||||
|
|
||||||
return *old_pid != 0 && *new_pid != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc,
|
|
||||||
char *argv[])
|
|
||||||
{
|
|
||||||
g_autoptr(GBytes) bytes = NULL;
|
|
||||||
g_autoptr(GError) error = NULL;
|
|
||||||
g_autoptr(GFile) gfile = NULL;
|
|
||||||
const char *file;
|
|
||||||
int old;
|
|
||||||
int new;
|
|
||||||
|
|
||||||
if (!parse_args (argc, argv, &file, &old, &new))
|
|
||||||
{
|
|
||||||
g_printerr ("usage: rewrite-pid FILE OLD_PID NEW_PID\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfile = g_file_new_for_commandline_arg (file);
|
|
||||||
|
|
||||||
if (!(bytes = g_file_load_bytes (gfile, NULL, NULL, &error)))
|
|
||||||
{
|
|
||||||
g_printerr ("error: %s\n", error->message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rewrite_pid ((guint8 *)g_bytes_get_data (bytes, NULL),
|
|
||||||
g_bytes_get_size (bytes),
|
|
||||||
old, new);
|
|
||||||
|
|
||||||
if (!g_file_set_contents (file,
|
|
||||||
(const char *)g_bytes_get_data (bytes, NULL),
|
|
||||||
g_bytes_get_size (bytes),
|
|
||||||
&error))
|
|
||||||
{
|
|
||||||
g_printerr ("error: %s\n", error->message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -1,118 +0,0 @@
|
|||||||
/* sysprof-cat.c
|
|
||||||
*
|
|
||||||
* Copyright 2018-2019 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define G_LOG_DOMAIN "sysprof-cat"
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <glib/gstdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sysprof-capture.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "../libsysprof/sysprof-capture-autocleanups.h"
|
|
||||||
#include "sysprof-capture-util-private.h"
|
|
||||||
|
|
||||||
gint
|
|
||||||
main (gint argc,
|
|
||||||
gchar *argv[])
|
|
||||||
{
|
|
||||||
g_autoptr(SysprofCaptureWriter) writer = NULL;
|
|
||||||
g_autofree gchar *contents = NULL;
|
|
||||||
g_autofree gchar *tmpname = NULL;
|
|
||||||
gsize len;
|
|
||||||
gint fd;
|
|
||||||
|
|
||||||
if (argc == 1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (isatty (STDOUT_FILENO))
|
|
||||||
{
|
|
||||||
g_printerr ("stdout is a TTY, refusing to write binary data to stdout.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (guint i = 1; i < argc; i++)
|
|
||||||
{
|
|
||||||
if (!g_file_test (argv[i], G_FILE_TEST_IS_REGULAR))
|
|
||||||
{
|
|
||||||
g_printerr ("\"%s\" is not a regular file.\n", argv[i]);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-1 == (fd = g_file_open_tmp (".sysprof-cat-XXXXXX", &tmpname, NULL)))
|
|
||||||
{
|
|
||||||
g_printerr ("Failed to create memfd for capture file.\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer = sysprof_capture_writer_new_from_fd (fd, 4096*4);
|
|
||||||
|
|
||||||
for (guint i = 1; i < argc; i++)
|
|
||||||
{
|
|
||||||
g_autoptr(SysprofCaptureReader) reader = NULL;
|
|
||||||
|
|
||||||
if (!(reader = sysprof_capture_reader_new (argv[i])))
|
|
||||||
{
|
|
||||||
int errsv = errno;
|
|
||||||
g_printerr ("Failed to create reader for \"%s\": %s\n",
|
|
||||||
argv[i], g_strerror (errsv));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sysprof_capture_writer_cat (writer, reader))
|
|
||||||
{
|
|
||||||
int errsv = errno;
|
|
||||||
g_printerr ("Failed to join \"%s\": %s\n",
|
|
||||||
argv[i], g_strerror (errsv));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_file_get_contents (tmpname, &contents, &len, NULL))
|
|
||||||
{
|
|
||||||
const gchar *buf = contents;
|
|
||||||
gsize to_write = len;
|
|
||||||
|
|
||||||
while (to_write > 0)
|
|
||||||
{
|
|
||||||
gssize n_written;
|
|
||||||
|
|
||||||
n_written = _sysprof_write (STDOUT_FILENO, buf, to_write);
|
|
||||||
|
|
||||||
if (n_written < 0)
|
|
||||||
{
|
|
||||||
g_printerr ("%s\n", g_strerror (errno));
|
|
||||||
g_unlink (tmpname);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf += n_written;
|
|
||||||
to_write -= n_written;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_unlink (tmpname);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user