[sysprof] libsysprof-ui: stub out model
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] libsysprof-ui: stub out model
- Date: Wed, 29 May 2019 22:24:17 +0000 (UTC)
commit 2a8ffea841163b12f4e28f89c801f6e9efe5401f
Author: Christian Hergert <chergert redhat com>
Date: Sun May 12 18:10:01 2019 -0700
libsysprof-ui: stub out model
src/libsysprof-ui/meson.build | 1 +
src/libsysprof-ui/sysprof-marks-model.c | 144 ++++++++++++++++++++++++++++++++
src/libsysprof-ui/sysprof-marks-model.h | 46 ++++++++++
3 files changed, 191 insertions(+)
---
diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build
index 9fa810d..7066ec4 100644
--- a/src/libsysprof-ui/meson.build
+++ b/src/libsysprof-ui/meson.build
@@ -23,6 +23,7 @@ libsysprof_ui_private_sources = [
'pointcache.c',
'rectangles.c',
'sysprof-cell-renderer-percent.c',
+ 'sysprof-marks-model.c',
'sysprof-theme-manager.c',
'../stackstash.c',
]
diff --git a/src/libsysprof-ui/sysprof-marks-model.c b/src/libsysprof-ui/sysprof-marks-model.c
new file mode 100644
index 0000000..85323eb
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-marks-model.c
@@ -0,0 +1,144 @@
+/* sysprof-marks-model.c
+ *
+ * Copyright 2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "sysprof-marks-model"
+
+#include "config.h"
+
+#include "sysprof-marks-model.h"
+
+struct _SysprofMarksModel
+{
+ GObject parent_instance;
+ GStringChunk *chunks;
+ GArray *items;
+};
+
+typedef struct
+{
+ gint64 begin_time;
+ gint64 end_time;
+} Item;
+
+static void
+tree_model_iface_init (GtkTreeModelIface *iface)
+{
+}
+
+G_DEFINE_TYPE_WITH_CODE (SysprofMarksModel, sysprof_marks_model, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, tree_model_iface_init))
+
+static void
+sysprof_marks_model_finalize (GObject *object)
+{
+ SysprofMarksModel *self = (SysprofMarksModel *)object;
+
+ g_clear_pointer (&self->items, g_array_unref);
+ g_clear_pointer (&self->chunks, g_string_chunk_free);
+
+ G_OBJECT_CLASS (sysprof_marks_model_parent_class)->finalize (object);
+}
+
+static void
+sysprof_marks_model_class_init (SysprofMarksModelClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = sysprof_marks_model_finalize;
+}
+
+static void
+sysprof_marks_model_init (SysprofMarksModel *self)
+{
+ self->chunks = g_string_chunk_new (4096*16);
+ self->items = g_array_new (FALSE, FALSE, sizeof (Item));
+}
+
+static gboolean
+cursor_foreach_cb (const SysprofCaptureFrame *frame,
+ gpointer user_data)
+{
+ SysprofMarksModel *self = user_data;
+ SysprofCaptureMark *mark = (SysprofCaptureMark *)frame;
+ Item item;
+
+ g_assert (SYSPROF_IS_MARKS_MODEL (self));
+ g_assert (frame->type == SYSPROF_CAPTURE_FRAME_MARK);
+
+ item.begin_time = frame->time;
+ item.end_time = item.begin_time + mark->duration;
+
+ g_array_append_val (self->items, item);
+
+ return FALSE;
+}
+
+static void
+sysprof_marks_model_new_worker (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_MARK };
+ SysprofCaptureReader *reader = task_data;
+ g_autoptr(SysprofCaptureCondition) condition = NULL;
+ g_autoptr(SysprofCaptureCursor) cursor = NULL;
+ g_autoptr(SysprofMarksModel) self = NULL;
+
+ g_assert (G_IS_TASK (task));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ self = g_object_new (SYSPROF_TYPE_MARKS_MODEL, NULL);
+
+ cursor = sysprof_capture_cursor_new (reader);
+ condition = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types);
+ sysprof_capture_cursor_add_condition (cursor, condition);
+ sysprof_capture_cursor_foreach (cursor, cursor_foreach_cb, self);
+
+ g_task_return_pointer (task, g_steal_pointer (&self), g_object_unref);
+}
+
+void
+sysprof_marks_model_new_async (SysprofCaptureReader *reader,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(GTask) task = NULL;
+
+ g_return_if_fail (reader != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = g_task_new (NULL, cancellable, callback, user_data);
+ g_task_set_source_tag (task, sysprof_marks_model_new_async);
+ g_task_set_task_data (task,
+ sysprof_capture_reader_copy (reader),
+ (GDestroyNotify) sysprof_capture_reader_unref);
+ g_task_run_in_thread (task, sysprof_marks_model_new_worker);
+}
+
+SysprofMarksModel *
+sysprof_marks_model_new_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (G_IS_TASK (result), NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
diff --git a/src/libsysprof-ui/sysprof-marks-model.h b/src/libsysprof-ui/sysprof-marks-model.h
new file mode 100644
index 0000000..d0a70be
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-marks-model.h
@@ -0,0 +1,46 @@
+/* sysprof-marks-model.h
+ *
+ * Copyright 2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include <sysprof-capture.h>
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_MARKS_MODEL (sysprof_marks_model_get_type())
+
+typedef enum
+{
+ SYSPROF_MARKS_MODEL_COLUMN_TEXT,
+ SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME,
+ SYSPROF_MARKS_MODEL_COLUMN_END_TIME,
+} SysprofMarksModelColumn;
+
+G_DECLARE_FINAL_TYPE (SysprofMarksModel, sysprof_marks_model, SYSPROF, MARKS_MODEL, GObject)
+
+void sysprof_marks_model_new_async (SysprofCaptureReader *reader,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+SysprofMarksModel *sysprof_marks_model_new_finish (GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]