Debian Codegraph @

src/libsysprof/sysprof-recording-private.h

raw
1 /* sysprof-recording-private.h
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 #pragma once
22
23 #include <libdex.h>
24
25 #include "sysprof-diagnostic-private.h"
26 #include "sysprof-instrument-private.h"
27 #include "sysprof-recording.h"
28 #include "sysprof-spawnable.h"
29
30 G_BEGIN_DECLS
31
32 typedef enum _SysprofRecordingCommand
33 {
34 SYSPROF_RECORDING_COMMAND_STOP = 1,
35 } SysprofRecordingCommand;
36
37 struct _SysprofRecording
38 {
39 GObject parent_instance;
40
41 /* Used to calculate the duration of the recording */
42 gint64 start_time;
43 gint64 end_time;
44
45 /* Used to calculate event count */
46 SysprofCaptureStat stat;
47
48 /* Diagnostics that may be added by instruments during the recording.
49 * Some may be fatal, meaning that they stop the recording when the
50 * diagnostic is submitted. That can happen in situations like
51 * miss-configuration or failed authorization.
52 */
53 GListStore *diagnostics;
54
55 /* If we are spawning a process as part of this recording, this
56 * is the SysprofSpawnable used to spawn the process.
57 */
58 SysprofSpawnable *spawnable;
59
60 /* This is where all of the instruments will write to. They are
61 * expected to do this from the main-thread only. To work from
62 * additional threads they need to proxy that state to the
63 * main thread for writing.
64 */
65 SysprofCaptureWriter *writer;
66
67 /* An array of SysprofInstrument that are part of this recording */
68 GPtrArray *instruments;
69
70 /* A DexFiber that will complete when the recording has finished,
71 * been stopped, or failed.
72 */
73 DexFuture *fiber;
74
75 /* The channel is used ot send state change messages to the fiber
76 * from outside of the fiber.
77 */
78 DexChannel *channel;
79
80 /* The process we have spawned, if any */
81 GSubprocess *subprocess;
82
83 /* If we should preauth or otherwise use sysprofd to access
84 * privileges when setting up the recording.
85 */
86 guint use_sysprofd : 1;
87 };
88
89 SysprofRecording *_sysprof_recording_new (SysprofCaptureWriter *writer,
90 SysprofSpawnable *spawnable,
91 SysprofInstrument **instruments,
92 guint n_instruments,
93 gboolean use_sysprofd);
94 void _sysprof_recording_start (SysprofRecording *self);
95 SysprofSpawnable *_sysprof_recording_get_spawnable (SysprofRecording *self);
96 DexFuture *_sysprof_recording_add_file (SysprofRecording *self,
97 const char *path,
98 gboolean compress);
99 void _sysprof_recording_add_file_data (SysprofRecording *self,
100 const char *path,
101 const char *contents,
102 gssize length,
103 gboolean compress);
104 void _sysprof_recording_follow_process(SysprofRecording *self,
105 int pid,
106 const char *comm);
107 void _sysprof_recording_diagnostic (SysprofRecording *self,
108 const char *domain,
109 const char *format,
110 ...) G_GNUC_PRINTF (3, 4);
111 void _sysprof_recording_error (SysprofRecording *self,
112 const char *domain,
113 const char *format,
114 ...) G_GNUC_PRINTF (3, 4);
115
116 static inline SysprofCaptureWriter *
117 _sysprof_recording_writer (const SysprofRecording *self)
118 {
119 return self->writer;
120 }
121
122 G_END_DECLS