File: sp-profiler.c

package info (click to toggle)
sysprof 3.30.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,616 kB
  • sloc: ansic: 20,056; xml: 96; cpp: 23; sh: 18; makefile: 9
file content (291 lines) | stat: -rw-r--r-- 8,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* sp-profiler.c
 *
 * Copyright (C) 2016 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/>.
 */

#include "profiler/sp-profiler.h"

G_DEFINE_INTERFACE (SpProfiler, sp_profiler, G_TYPE_OBJECT)

enum {
  FAILED,
  STOPPED,
  N_SIGNALS
};

static guint signals [N_SIGNALS];

static void
sp_profiler_default_init (SpProfilerInterface *iface)
{
  signals [FAILED] = g_signal_new ("failed",
                                   G_TYPE_FROM_INTERFACE (iface),
                                   G_SIGNAL_RUN_LAST,
                                   G_STRUCT_OFFSET (SpProfilerInterface, failed),
                                   NULL, NULL, NULL,
                                   G_TYPE_NONE, 1, G_TYPE_ERROR);

  signals [STOPPED] = g_signal_new ("stopped",
                                    G_TYPE_FROM_INTERFACE (iface),
                                    G_SIGNAL_RUN_LAST,
                                    G_STRUCT_OFFSET (SpProfilerInterface, stopped),
                                    NULL, NULL, NULL,
                                    G_TYPE_NONE, 0);

  g_object_interface_install_property (iface,
      g_param_spec_double ("elapsed",
                           "Elapsed",
                           "The amount of elapsed time profiling",
                           0,
                           G_MAXDOUBLE,
                           0,
                           (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boolean ("is-running",
                            "Is Running",
                            "If the profiler is currently running.",
                            FALSE,
                            (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boolean ("is-mutable",
                            "Is Mutable",
                            "If the profiler can still be prepared.",
                            TRUE,
                            (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boolean ("spawn-inherit-environ",
                            "Spawn Inherit Environ",
                            "If the spawned child should inherit the parents environment",
                            TRUE,
                            (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boolean ("whole-system",
                            "Whole System",
                            "If the whole system should be profiled",
                            TRUE,
                            (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boolean ("spawn",
                            "Spawn",
                            "If configured child should be spawned",
                            TRUE,
                            (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boxed ("spawn-argv",
                          "Spawn Argv",
                          "The arguments for the spawn child",
                          G_TYPE_STRV,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

  g_object_interface_install_property (iface,
      g_param_spec_boxed ("spawn-env",
                          "Spawn Environment",
                          "The environment for the spawn child",
                          G_TYPE_STRV,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}

gdouble
sp_profiler_get_elapsed (SpProfiler *self)
{
  gdouble value = 0.0;
  g_return_val_if_fail (SP_IS_PROFILER (self), 0.0);
  g_object_get (self, "elapsed", &value, NULL);
  return value;
}

gboolean
sp_profiler_get_is_running (SpProfiler *self)
{
  gboolean is_running = FALSE;
  g_return_val_if_fail (SP_IS_PROFILER (self), FALSE);
  g_object_get (self, "is-running", &is_running, NULL);
  return is_running;
}

gboolean
sp_profiler_get_is_mutable (SpProfiler *self)
{
  gboolean is_mutable = FALSE;
  g_return_val_if_fail (SP_IS_PROFILER (self), FALSE);
  g_object_get (self, "is-mutable", &is_mutable, NULL);
  return is_mutable;
}

gboolean
sp_profiler_get_spawn_inherit_environ (SpProfiler *self)
{
  gboolean spawn_inherit_environ = FALSE;
  g_return_val_if_fail (SP_IS_PROFILER (self), FALSE);
  g_object_get (self, "spawn-inherit-environ", &spawn_inherit_environ, NULL);
  return spawn_inherit_environ;
}

void
sp_profiler_set_spawn_inherit_environ (SpProfiler *self,
                                       gboolean    spawn_inherit_environ)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_object_set (self, "spawn-inherit-environ", !!spawn_inherit_environ, NULL);
}

gboolean
sp_profiler_get_spawn (SpProfiler *self)
{
  gboolean spawn = FALSE;
  g_return_val_if_fail (SP_IS_PROFILER (self), FALSE);
  g_object_get (self, "spawn", &spawn, NULL);
  return spawn;
}

void
sp_profiler_set_spawn (SpProfiler *self,
                       gboolean    spawn)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_object_set (self, "spawn", !!spawn, NULL);
}

gboolean
sp_profiler_get_whole_system (SpProfiler *self)
{
  gboolean whole_system = FALSE;
  g_return_val_if_fail (SP_IS_PROFILER (self), FALSE);
  g_object_get (self, "whole-system", &whole_system, NULL);
  return whole_system;
}

void
sp_profiler_set_whole_system (SpProfiler *self,
                              gboolean    whole_system)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_object_set (self, "whole-system", !!whole_system, NULL);
}

void
sp_profiler_set_spawn_argv (SpProfiler          *self,
                            const gchar * const *spawn_argv)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_object_set (self, "spawn-argv", spawn_argv, NULL);
}

void
sp_profiler_set_spawn_env (SpProfiler          *self,
                           const gchar * const *spawn_env)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_object_set (self, "spawn-env", spawn_env, NULL);
}

void
sp_profiler_add_source (SpProfiler *self,
                        SpSource   *source)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_return_if_fail (SP_IS_SOURCE (source));

  SP_PROFILER_GET_IFACE (self)->add_source (self, source);
}

void
sp_profiler_set_writer (SpProfiler      *self,
                        SpCaptureWriter *writer)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_return_if_fail (writer != NULL);

  SP_PROFILER_GET_IFACE (self)->set_writer (self, writer);
}

SpCaptureWriter *
sp_profiler_get_writer (SpProfiler *self)
{
  g_return_val_if_fail (SP_IS_PROFILER (self), NULL);

  return SP_PROFILER_GET_IFACE (self)->get_writer (self);
}

void
sp_profiler_start (SpProfiler *self)
{
  g_return_if_fail (SP_IS_PROFILER (self));

  SP_PROFILER_GET_IFACE (self)->start (self);
}

void
sp_profiler_stop (SpProfiler *self)
{
  g_return_if_fail (SP_IS_PROFILER (self));

  SP_PROFILER_GET_IFACE (self)->stop (self);
}

void
sp_profiler_add_pid (SpProfiler *self,
                     GPid        pid)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_return_if_fail (pid > -1);

  SP_PROFILER_GET_IFACE (self)->add_pid (self, pid);
}

void
sp_profiler_remove_pid (SpProfiler *self,
                        GPid        pid)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_return_if_fail (pid > -1);

  SP_PROFILER_GET_IFACE (self)->remove_pid (self, pid);
}

const GPid *
sp_profiler_get_pids (SpProfiler *self,
                      guint      *n_pids)
{
  g_return_val_if_fail (SP_IS_PROFILER (self), NULL);
  g_return_val_if_fail (n_pids != NULL, NULL);

  return SP_PROFILER_GET_IFACE (self)->get_pids (self, n_pids);
}

void
sp_profiler_emit_failed (SpProfiler   *self,
                         const GError *error)
{
  g_return_if_fail (SP_IS_PROFILER (self));
  g_return_if_fail (error != NULL);

  g_signal_emit (self, signals [FAILED], 0, error);
}

void
sp_profiler_emit_stopped (SpProfiler *self)
{
  g_return_if_fail (SP_IS_PROFILER (self));

  g_signal_emit (self, signals [STOPPED], 0);
}