diff --git a/src/libsysprof-ui/sysprof-battery-aid.c b/src/libsysprof-ui/sysprof-battery-aid.c index ab44a281..8bef1979 100644 --- a/src/libsysprof-ui/sysprof-battery-aid.c +++ b/src/libsysprof-ui/sysprof-battery-aid.c @@ -81,7 +81,7 @@ sysprof_battery_aid_prepare (SysprofAid *self, #endif } -static gboolean +static bool collect_battery_counters (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-callgraph-aid.c b/src/libsysprof-ui/sysprof-callgraph-aid.c index 5b0ebb07..f12be766 100644 --- a/src/libsysprof-ui/sysprof-callgraph-aid.c +++ b/src/libsysprof-ui/sysprof-callgraph-aid.c @@ -114,7 +114,7 @@ sysprof_callgraph_aid_prepare (SysprofAid *self, #endif } -static gboolean +static bool discover_samples_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-counters-aid.c b/src/libsysprof-ui/sysprof-counters-aid.c index 2324569e..c1d855bb 100644 --- a/src/libsysprof-ui/sysprof-counters-aid.c +++ b/src/libsysprof-ui/sysprof-counters-aid.c @@ -123,7 +123,7 @@ build_title (const SysprofCaptureCounter *ctr) return g_string_free (str, FALSE); } -static gboolean +static bool collect_counters (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-cpu-aid.c b/src/libsysprof-ui/sysprof-cpu-aid.c index 39029576..56094888 100644 --- a/src/libsysprof-ui/sysprof-cpu-aid.c +++ b/src/libsysprof-ui/sysprof-cpu-aid.c @@ -85,7 +85,7 @@ sysprof_cpu_aid_prepare (SysprofAid *self, #endif } -static gboolean +static bool collect_info (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-depth-visualizer.c b/src/libsysprof-ui/sysprof-depth-visualizer.c index 118489d7..a3a4df5f 100644 --- a/src/libsysprof-ui/sysprof-depth-visualizer.c +++ b/src/libsysprof-ui/sysprof-depth-visualizer.c @@ -62,7 +62,7 @@ state_free (State *st) g_slice_free (State, st); } -static gboolean +static bool discover_max_n_addr (const SysprofCaptureFrame *frame, gpointer user_data) { @@ -78,7 +78,7 @@ discover_max_n_addr (const SysprofCaptureFrame *frame, return TRUE; } -static gboolean +static bool build_point_cache_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-details-page.c b/src/libsysprof-ui/sysprof-details-page.c index 3f9fcbda..0c41ec46 100644 --- a/src/libsysprof-ui/sysprof-details-page.c +++ b/src/libsysprof-ui/sysprof-details-page.c @@ -135,7 +135,7 @@ update_cpu_info_cb (GObject *object, gtk_label_set_label (self->cpu_label, str); } -static gboolean +static bool cpu_info_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-diskstat-aid.c b/src/libsysprof-ui/sysprof-diskstat-aid.c index aff40ecd..c87cb3e7 100644 --- a/src/libsysprof-ui/sysprof-diskstat-aid.c +++ b/src/libsysprof-ui/sysprof-diskstat-aid.c @@ -80,7 +80,7 @@ sysprof_diskstat_aid_prepare (SysprofAid *self, sysprof_profiler_add_source (profiler, source); } -static gboolean +static bool collect_diskstat_counters (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c index e9886d5a..6be5faf1 100644 --- a/src/libsysprof-ui/sysprof-display.c +++ b/src/libsysprof-ui/sysprof-display.c @@ -143,7 +143,7 @@ sysprof_display_profiler_stopped_cb (SysprofDisplay *self, g_autoptr(SysprofCaptureReader) reader = NULL; g_autoptr(GError) error = NULL; - if (!(reader = sysprof_capture_writer_create_reader (writer, &error))) + if (!(reader = sysprof_capture_writer_create_reader_with_error (writer, &error))) { g_warning ("Failed to create capture creader: %s\n", error->message); gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->failed_view)); @@ -1071,7 +1071,7 @@ sysprof_display_open (SysprofDisplay *self, g_set_object (&priv->file, file); - if (!(reader = sysprof_capture_reader_new (path, &error))) + if (!(reader = sysprof_capture_reader_new_with_error (path, &error))) { GtkWidget *dialog; GtkWidget *window; @@ -1229,7 +1229,7 @@ sysprof_display_save (SysprofDisplay *self) g_autofree gchar *path = g_file_get_path (file); g_autoptr(GError) error = NULL; - if (!sysprof_capture_reader_save_as (priv->reader, path, &error)) + if (!sysprof_capture_reader_save_as_with_error (priv->reader, path, &error)) { GtkWidget *msg; diff --git a/src/libsysprof-ui/sysprof-duplex-visualizer.c b/src/libsysprof-ui/sysprof-duplex-visualizer.c index 82bdca03..1901258a 100644 --- a/src/libsysprof-ui/sysprof-duplex-visualizer.c +++ b/src/libsysprof-ui/sysprof-duplex-visualizer.c @@ -73,7 +73,7 @@ typedef struct G_DEFINE_TYPE (SysprofDuplexVisualizer, sysprof_duplex_visualizer, SYSPROF_TYPE_VISUALIZER) -static gboolean +static bool collect_ranges_cb (const SysprofCaptureFrame *frame, gpointer data) { @@ -126,7 +126,7 @@ collect_ranges_cb (const SysprofCaptureFrame *frame, return TRUE; } -static gboolean +static bool collect_values_cb (const SysprofCaptureFrame *frame, gpointer data) { diff --git a/src/libsysprof-ui/sysprof-line-visualizer.c b/src/libsysprof-ui/sysprof-line-visualizer.c index 188b2e1f..5075a4f9 100644 --- a/src/libsysprof-ui/sysprof-line-visualizer.c +++ b/src/libsysprof-ui/sysprof-line-visualizer.c @@ -613,7 +613,7 @@ calc_y_int64 (gint64 lower, return (gdouble)(value - lower) / (gdouble)(upper - lower); } -static gboolean +static bool sysprof_line_visualizer_load_data_frame_cb (const SysprofCaptureFrame *frame, gpointer user_data) { @@ -655,7 +655,7 @@ sysprof_line_visualizer_load_data_frame_cb (const SysprofCaptureFrame *frame, return TRUE; } -static gboolean +static bool sysprof_line_visualizer_load_data_range_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-log-model.c b/src/libsysprof-ui/sysprof-log-model.c index 276ea063..8d67254f 100644 --- a/src/libsysprof-ui/sysprof-log-model.c +++ b/src/libsysprof-ui/sysprof-log-model.c @@ -289,7 +289,7 @@ sysprof_log_model_init (SysprofLogModel *self) self->items = g_array_new (FALSE, FALSE, sizeof (Item)); } -static gboolean +static bool cursor_foreach_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-logs-aid.c b/src/libsysprof-ui/sysprof-logs-aid.c index 466eab3e..8807cbe5 100644 --- a/src/libsysprof-ui/sysprof-logs-aid.c +++ b/src/libsysprof-ui/sysprof-logs-aid.c @@ -80,7 +80,7 @@ sysprof_logs_aid_new (void) return g_object_new (SYSPROF_TYPE_LOGS_AID, NULL); } -static gboolean +static bool find_marks_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-marks-aid.c b/src/libsysprof-ui/sysprof-marks-aid.c index a8f79b48..66b2c258 100644 --- a/src/libsysprof-ui/sysprof-marks-aid.c +++ b/src/libsysprof-ui/sysprof-marks-aid.c @@ -84,7 +84,7 @@ sysprof_marks_aid_new (void) return g_object_new (SYSPROF_TYPE_MARKS_AID, NULL); } -static gboolean +static bool find_marks_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-marks-model.c b/src/libsysprof-ui/sysprof-marks-model.c index fa5772af..08000641 100644 --- a/src/libsysprof-ui/sysprof-marks-model.c +++ b/src/libsysprof-ui/sysprof-marks-model.c @@ -301,7 +301,7 @@ sysprof_marks_model_init (SysprofMarksModel *self) self->items = g_array_new (FALSE, FALSE, sizeof (Item)); } -static gboolean +static bool cursor_foreach_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-memprof-aid.c b/src/libsysprof-ui/sysprof-memprof-aid.c index 6299b54f..21325177 100644 --- a/src/libsysprof-ui/sysprof-memprof-aid.c +++ b/src/libsysprof-ui/sysprof-memprof-aid.c @@ -87,7 +87,7 @@ sysprof_memprof_aid_prepare (SysprofAid *self, #endif } -static gboolean +static bool discover_samples_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-netdev-aid.c b/src/libsysprof-ui/sysprof-netdev-aid.c index f4a75a7a..c6970fd2 100644 --- a/src/libsysprof-ui/sysprof-netdev-aid.c +++ b/src/libsysprof-ui/sysprof-netdev-aid.c @@ -79,7 +79,7 @@ sysprof_netdev_aid_prepare (SysprofAid *self, sysprof_profiler_add_source (profiler, source); } -static gboolean +static bool collect_netdev_counters (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-procs-visualizer.c b/src/libsysprof-ui/sysprof-procs-visualizer.c index b4d34d29..c82007e5 100644 --- a/src/libsysprof-ui/sysprof-procs-visualizer.c +++ b/src/libsysprof-ui/sysprof-procs-visualizer.c @@ -65,7 +65,7 @@ discovery_ref (Discovery *d) return d; } -static gboolean +static bool discover_max_cb (const SysprofCaptureFrame *frame, gpointer user_data) { @@ -85,7 +85,7 @@ discover_max_cb (const SysprofCaptureFrame *frame, return TRUE; } -static gboolean +static bool calc_points_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-rapl-aid.c b/src/libsysprof-ui/sysprof-rapl-aid.c index 9da61d56..c5d11e61 100644 --- a/src/libsysprof-ui/sysprof-rapl-aid.c +++ b/src/libsysprof-ui/sysprof-rapl-aid.c @@ -69,7 +69,7 @@ sysprof_rapl_aid_new (void) return g_object_new (SYSPROF_TYPE_RAPL_AID, NULL); } -static gboolean +static bool collect_info (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-time-visualizer.c b/src/libsysprof-ui/sysprof-time-visualizer.c index cb1d01a7..01d32f23 100644 --- a/src/libsysprof-ui/sysprof-time-visualizer.c +++ b/src/libsysprof-ui/sysprof-time-visualizer.c @@ -382,7 +382,7 @@ calc_x (gint64 lower, return (gdouble)(value - lower) / (gdouble)(upper - lower); } -static gboolean +static bool sysprof_time_visualizer_load_data_frame_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.c b/src/libsysprof-ui/sysprof-visualizers-frame.c index 95b990ca..96da31b9 100644 --- a/src/libsysprof-ui/sysprof-visualizers-frame.c +++ b/src/libsysprof-ui/sysprof-visualizers-frame.c @@ -608,7 +608,7 @@ compare_gint64 (const gint64 *a, return 0; } -static gboolean +static bool index_frame_times_frame_cb (const SysprofCaptureFrame *frame, gpointer user_data) { diff --git a/src/libsysprof/sysprof-capture-gobject.c b/src/libsysprof/sysprof-capture-gobject.c index dbd7cf2a..4e6f660d 100644 --- a/src/libsysprof/sysprof-capture-gobject.c +++ b/src/libsysprof/sysprof-capture-gobject.c @@ -20,10 +20,73 @@ #include "config.h" -#include "sysprof-capture-gobject.h" - +#include #include +#include "sysprof-capture-gobject.h" + G_DEFINE_BOXED_TYPE (SysprofCaptureReader, sysprof_capture_reader, (GBoxedCopyFunc)sysprof_capture_reader_ref, (GBoxedFreeFunc)sysprof_capture_reader_unref) G_DEFINE_BOXED_TYPE (SysprofCaptureWriter, sysprof_capture_writer, (GBoxedCopyFunc)sysprof_capture_writer_ref, (GBoxedFreeFunc)sysprof_capture_writer_unref) G_DEFINE_BOXED_TYPE (SysprofCaptureCursor, sysprof_capture_cursor, (GBoxedCopyFunc)sysprof_capture_cursor_ref, (GBoxedFreeFunc)sysprof_capture_cursor_unref) + +SysprofCaptureReader * +sysprof_capture_reader_new_with_error (const char *filename, + GError **error) +{ + SysprofCaptureReader *ret; + + if (!(ret = sysprof_capture_reader_new (filename))) + g_set_error_literal (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + g_strerror (errno)); + + return ret; +} + +SysprofCaptureReader * +sysprof_capture_reader_new_from_fd_with_error (int fd, + GError **error) +{ + SysprofCaptureReader *ret; + + if (!(ret = sysprof_capture_reader_new_from_fd (fd))) + g_set_error_literal (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + g_strerror (errno)); + + return ret; +} + +SysprofCaptureReader * +sysprof_capture_writer_create_reader_with_error (SysprofCaptureWriter *self, + GError **error) +{ + SysprofCaptureReader *ret; + + if (!(ret = sysprof_capture_writer_create_reader (self))) + g_set_error_literal (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + g_strerror (errno)); + + return ret; +} + +bool +sysprof_capture_reader_save_as_with_error (SysprofCaptureReader *self, + const char *filename, + GError **error) +{ + if (!sysprof_capture_reader_save_as (self, filename)) + { + g_set_error_literal (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + g_strerror (errno)); + return false; + } + + return true; +} diff --git a/src/libsysprof/sysprof-capture-gobject.h b/src/libsysprof/sysprof-capture-gobject.h index 80a2f4c2..ca6fbe23 100644 --- a/src/libsysprof/sysprof-capture-gobject.h +++ b/src/libsysprof/sysprof-capture-gobject.h @@ -41,4 +41,18 @@ GType sysprof_capture_writer_get_type (void); SYSPROF_AVAILABLE_IN_ALL GType sysprof_capture_cursor_get_type (void); +SYSPROF_AVAILABLE_IN_3_38 +SysprofCaptureReader *sysprof_capture_reader_new_with_error (const char *filename, + GError **error); +SYSPROF_AVAILABLE_IN_3_38 +SysprofCaptureReader *sysprof_capture_reader_new_from_fd_with_error (int fd, + GError **error); +SYSPROF_AVAILABLE_IN_3_38 +SysprofCaptureReader *sysprof_capture_writer_create_reader_with_error (SysprofCaptureWriter *self, + GError **error); +SYSPROF_AVAILABLE_IN_3_38 +bool sysprof_capture_reader_save_as_with_error (SysprofCaptureReader *self, + const char *filename, + GError **error); + G_END_DECLS diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h index c9164f72..5abe64b6 100644 --- a/src/libsysprof/sysprof.h +++ b/src/libsysprof/sysprof.h @@ -18,6 +18,7 @@ #pragma once +#include #include G_BEGIN_DECLS diff --git a/src/tests/test-capture-view.c b/src/tests/test-capture-view.c index 1dca19aa..9768ca18 100644 --- a/src/tests/test-capture-view.c +++ b/src/tests/test-capture-view.c @@ -37,7 +37,7 @@ main (gint argc, return 1; } - if (!(reader = sysprof_capture_reader_new (argv[1], &error))) + if (!(reader = sysprof_capture_reader_new_with_error (argv[1], &error))) { g_printerr ("Failed to load reader: %s\n", error->message); return 1;