Debian Codegraph @

src/libsysprof/sysprof-document-traceable.c

raw
1 /*
2 * sysprof-document-traceable.c
3 *
4 * Copyright 2023 Christian Hergert <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GPL-3.0-or-later
20 */
21
22 #include "config.h"
23
24 #include "sysprof-document-traceable.h"
25
26 G_DEFINE_INTERFACE (SysprofDocumentTraceable, sysprof_document_traceable, SYSPROF_TYPE_DOCUMENT_FRAME)
27
28 static void
29 sysprof_document_traceable_default_init (SysprofDocumentTraceableInterface *iface)
30 {
31 /**
32 * SysprofDocumentTraceable:stack-depth:
33 *
34 * The "stack-depth" property contains the number of addresses collected
35 * in the backtrace.
36 *
37 * You may use this value to retrieve the addresses from 0 to ("stack-depth"-1)
38 * by calling sysprof_document_traceable_get_stack_address().
39 *
40 * Since: 45
41 */
42 g_object_interface_install_property (iface,
43 g_param_spec_uint ("stack-depth", NULL, NULL,
44 0, G_MAXUINT16, 0,
45 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
46
47 /**
48 * SysprofDocumentTraceable:thread-id:
49 *
50 * The "thread-id" property contains the thread identifier for the traceable.
51 *
52 * Since: 45
53 */
54 g_object_interface_install_property (iface,
55 g_param_spec_int ("thread-id", NULL, NULL,
56 -1, G_MAXINT, -1,
57 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
58 }
59
60 guint
61 sysprof_document_traceable_get_stack_depth (SysprofDocumentTraceable *self)
62 {
63 return SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_stack_depth (self);
64 }
65
66 guint64
67 sysprof_document_traceable_get_stack_address (SysprofDocumentTraceable *self,
68 guint position)
69 {
70 return SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_stack_address (self, position);
71 }
72
73 int
74 sysprof_document_traceable_get_thread_id (SysprofDocumentTraceable *self)
75 {
76 return SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_thread_id (self);
77 }
78
79 guint
80 sysprof_document_traceable_get_stack_addresses (SysprofDocumentTraceable *self,
81 guint64 *addresses,
82 guint n_addresses)
83 {
84 g_return_val_if_fail (SYSPROF_IS_DOCUMENT_TRACEABLE (self), 0);
85
86 if (addresses == NULL || n_addresses == 0)
87 return 0;
88
89 return SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_stack_addresses (self, addresses, n_addresses);
90 }