| 1 |
/* sysprof-process-info.c |
| 2 |
* |
| 3 |
* Copyright 2023 Christian Hergert <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "sysprof-process-info-private.h" |
| 24 |
#include "sysprof-symbol-private.h" |
| 25 |
|
| 26 |
G_DEFINE_BOXED_TYPE (SysprofProcessInfo, |
| 27 |
sysprof_process_info, |
| 28 |
sysprof_process_info_ref, |
| 29 |
sysprof_process_info_unref) |
| 30 |
|
| 31 |
SysprofProcessInfo * |
| 32 |
sysprof_process_info_new (SysprofMountNamespace *mount_namespace, |
| 33 |
int pid) |
| 34 |
{ |
| 35 |
SysprofProcessInfo *self; |
| 36 |
char pidstr[32]; |
| 37 |
char symname[32]; |
| 38 |
|
| 39 |
g_snprintf (symname, sizeof symname, "Process %d", pid); |
| 40 |
g_snprintf (pidstr, sizeof pidstr, "(%d)", pid); |
| 41 |
|
| 42 |
self = g_atomic_rc_box_new0 (SysprofProcessInfo); |
| 43 |
self->pid = pid; |
| 44 |
self->address_layout = sysprof_address_layout_new (); |
| 45 |
self->symbol_cache = sysprof_symbol_cache_new (); |
| 46 |
self->mount_namespace = mount_namespace; |
| 47 |
self->thread_ids = egg_bitset_new_empty (); |
| 48 |
self->fallback_symbol = _sysprof_symbol_new (g_ref_string_new (symname), |
| 49 |
NULL, |
| 50 |
g_ref_string_new (pidstr), |
| 51 |
0, 0, |
| 52 |
SYSPROF_SYMBOL_KIND_PROCESS); |
| 53 |
|
| 54 |
if (pid == 0) |
| 55 |
self->fallback_symbol->is_kernel_process = TRUE; |
| 56 |
|
| 57 |
if (pid > 0) |
| 58 |
egg_bitset_add (self->thread_ids, pid); |
| 59 |
|
| 60 |
return self; |
| 61 |
} |
| 62 |
|
| 63 |
SysprofProcessInfo * |
| 64 |
sysprof_process_info_ref (SysprofProcessInfo *self) |
| 65 |
{ |
| 66 |
return g_atomic_rc_box_acquire (self); |
| 67 |
} |
| 68 |
|
| 69 |
static void |
| 70 |
sysprof_process_info_finalize (gpointer data) |
| 71 |
{ |
| 72 |
SysprofProcessInfo *self = data; |
| 73 |
|
| 74 |
g_clear_object (&self->address_layout); |
| 75 |
g_clear_object (&self->symbol_cache); |
| 76 |
g_clear_object (&self->mount_namespace); |
| 77 |
g_clear_object (&self->fallback_symbol); |
| 78 |
g_clear_object (&self->shared_symbol); |
| 79 |
g_clear_object (&self->symbol); |
| 80 |
g_clear_pointer (&self->thread_ids, egg_bitset_unref); |
| 81 |
|
| 82 |
self->pid = 0; |
| 83 |
} |
| 84 |
|
| 85 |
void |
| 86 |
sysprof_process_info_unref (SysprofProcessInfo *self) |
| 87 |
{ |
| 88 |
g_atomic_rc_box_release_full (self, sysprof_process_info_finalize); |
| 89 |
} |