diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index 469104c9..972a65a0 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -3,6 +3,7 @@ libsysprof_analyze_public_sources = [ 'sysprof-document.c', 'sysprof-document-allocation.c', 'sysprof-document-counter.c', + 'sysprof-document-ctrdef.c', 'sysprof-document-exit.c', 'sysprof-document-file.c', 'sysprof-document-file-chunk.c', @@ -50,6 +51,7 @@ libsysprof_analyze_public_headers = [ 'sysprof-document.h', 'sysprof-document-allocation.h', 'sysprof-document-counter.h', + 'sysprof-document-ctrdef.h', 'sysprof-document-exit.h', 'sysprof-document-file.h', 'sysprof-document-file-chunk.h', diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index 2ac5ae6d..5488e86d 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS # include "sysprof-document.h" # include "sysprof-document-allocation.h" # include "sysprof-document-counter.h" +# include "sysprof-document-ctrdef.h" # include "sysprof-document-exit.h" # include "sysprof-document-file.h" # include "sysprof-document-file-chunk.h" diff --git a/src/libsysprof-analyze/sysprof-document-ctrdef.c b/src/libsysprof-analyze/sysprof-document-ctrdef.c new file mode 100644 index 00000000..a6bba826 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-ctrdef.c @@ -0,0 +1,105 @@ +/* sysprof-document-ctrdef.c + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-document-frame-private.h" +#include "sysprof-document-ctrdef.h" + +struct _SysprofDocumentCtrdef +{ + SysprofDocumentFrame parent_instance; +}; + +struct _SysprofDocumentCtrdefClass +{ + SysprofDocumentFrameClass parent_class; +}; + +G_DEFINE_FINAL_TYPE (SysprofDocumentCtrdef, sysprof_document_ctrdef, SYSPROF_TYPE_DOCUMENT_FRAME) + +static void +sysprof_document_ctrdef_class_init (SysprofDocumentCtrdefClass *klass) +{ +} + +static void +sysprof_document_ctrdef_init (SysprofDocumentCtrdef *self) +{ +} + +guint +sysprof_document_ctrdef_get_n_counters (SysprofDocumentCtrdef *self) +{ + const SysprofCaptureCounterDefine *ctrdef; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_CTRDEF (self), 0); + + ctrdef = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureCounterDefine); + + return SYSPROF_DOCUMENT_FRAME_UINT16 (self, ctrdef->n_counters); +} + +/** + * sysprof_document_ctrdef_get_counter: + * @self: a #SysprofDocumentCtrdef + * @nth: a value between 0 and sysprof_document_ctrdef_get_n_counters() + * @id: (out): a location for the id of the counter + * @type: (out): a location for either %SYSPROF_CAPTURE_COUNTER_INT64 + * or %SYSPROF_CAPTURE_COUNTER_DOUBLE + * @category: (out): a location for the category + * @name: (out): a location for the name + * @description: (out): a location for the description + * + * Gets information about a counter defined in @self. + */ +void +sysprof_document_ctrdef_get_counter (SysprofDocumentCtrdef *self, + guint nth, + guint *id, + guint *type, + const char **category, + const char **name, + const char **description) +{ + const SysprofCaptureCounterDefine *ctrdef; + const SysprofCaptureCounter *ctr; + + g_return_if_fail (SYSPROF_IS_DOCUMENT_CTRDEF (self)); + g_return_if_fail (nth < sysprof_document_ctrdef_get_n_counters (self)); + + ctrdef = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureCounterDefine); + ctr = &ctrdef->counters[nth]; + + if (id != NULL) + *id = SYSPROF_DOCUMENT_FRAME_UINT32 (self, ctr->id); + + if (type != NULL) + *type = ctr->type; + + if (category != NULL) + *category = SYSPROF_DOCUMENT_FRAME_CSTRING (self, ctr->category); + + if (name != NULL) + *name = SYSPROF_DOCUMENT_FRAME_CSTRING (self, ctr->name); + + if (description != NULL) + *description = SYSPROF_DOCUMENT_FRAME_CSTRING (self, ctr->description); +} diff --git a/src/libsysprof-analyze/sysprof-document-ctrdef.h b/src/libsysprof-analyze/sysprof-document-ctrdef.h new file mode 100644 index 00000000..c8e1a652 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-ctrdef.h @@ -0,0 +1,53 @@ +/* sysprof-document-ctrdef.h + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include "sysprof-document-frame.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_DOCUMENT_CTRDEF (sysprof_document_ctrdef_get_type()) +#define SYSPROF_IS_DOCUMENT_CTRDEF(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_CTRDEF) +#define SYSPROF_DOCUMENT_CTRDEF(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_CTRDEF, SysprofDocumentCtrdef) +#define SYSPROF_DOCUMENT_CTRDEF_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_CTRDEF, SysprofDocumentCtrdefClass) + +typedef struct _SysprofDocumentCtrdef SysprofDocumentCtrdef; +typedef struct _SysprofDocumentCtrdefClass SysprofDocumentCtrdefClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_document_ctrdef_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +guint sysprof_document_ctrdef_get_n_counters (SysprofDocumentCtrdef *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_document_ctrdef_get_counter (SysprofDocumentCtrdef *self, + guint nth, + guint *id, + guint *type, + const char **category, + const char **name, + const char **description); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentCtrdef, g_object_unref) + +G_END_DECLS + diff --git a/src/libsysprof-analyze/sysprof-document-frame.c b/src/libsysprof-analyze/sysprof-document-frame.c index 09664eab..ee44b9b4 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.c +++ b/src/libsysprof-analyze/sysprof-document-frame.c @@ -23,6 +23,7 @@ #include "sysprof-document-frame-private.h" #include "sysprof-document-allocation.h" +#include "sysprof-document-ctrdef.h" #include "sysprof-document-exit.h" #include "sysprof-document-file-chunk.h" #include "sysprof-document-fork.h" @@ -178,6 +179,10 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, gtype = SYSPROF_TYPE_DOCUMENT_JITMAP; break; + case SYSPROF_CAPTURE_FRAME_CTRDEF: + gtype = SYSPROF_TYPE_DOCUMENT_CTRDEF; + break; + default: gtype = SYSPROF_TYPE_DOCUMENT_FRAME; break; diff --git a/src/libsysprof-analyze/tests/test-capture-model.c b/src/libsysprof-analyze/tests/test-capture-model.c index aa5dd0f9..ac94872f 100644 --- a/src/libsysprof-analyze/tests/test-capture-model.c +++ b/src/libsysprof-analyze/tests/test-capture-model.c @@ -84,6 +84,25 @@ main (int argc, else if (SYSPROF_IS_DOCUMENT_JITMAP (frame)) g_print (" n_jitmaps=%u", sysprof_document_jitmap_get_size (SYSPROF_DOCUMENT_JITMAP (frame))); + else if (SYSPROF_IS_DOCUMENT_CTRDEF (frame)) + { + guint n_counters = sysprof_document_ctrdef_get_n_counters (SYSPROF_DOCUMENT_CTRDEF (frame)); + + g_print (" n_counters=%u", n_counters); + + for (guint j = 0; j < n_counters; j++) + { + const char *category, *name; + guint id, type; + + sysprof_document_ctrdef_get_counter (SYSPROF_DOCUMENT_CTRDEF (frame), + j, &id, &type, &category, &name, NULL); + g_print (" [%u<%s>:%s.%s]", + id, + type == SYSPROF_CAPTURE_COUNTER_INT64 ? "i64" : "f64", + category, name); + } + } else if (SYSPROF_IS_DOCUMENT_ALLOCATION (frame)) { if (sysprof_document_allocation_is_free (SYSPROF_DOCUMENT_ALLOCATION (frame)))