diff --git a/src/libsysprof-analyze/sysprof-document-private.h b/src/libsysprof-analyze/sysprof-document-private.h new file mode 100644 index 00000000..9be91cd4 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-private.h @@ -0,0 +1,28 @@ +/* sysprof-document-private.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 + +G_BEGIN_DECLS + +const char *sysprof_document_intern_string (SysprofDocument *self, + const char *name); + +G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index 9b9ed75b..5b06838a 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -30,9 +30,14 @@ struct _SysprofDocument { GObject parent_instance; + GArray *frames; GMappedFile *mapped_file; const guint8 *base; + + GMutex strings_mutex; + GStringChunk *strings; + SysprofCaptureFileHeader header; guint needs_swap : 1; }; @@ -91,6 +96,9 @@ sysprof_document_finalize (GObject *object) g_clear_pointer (&self->mapped_file, g_mapped_file_unref); g_clear_pointer (&self->frames, g_array_unref); + g_clear_pointer (&self->strings, g_string_chunk_free); + + g_mutex_clear (&self->strings_mutex); G_OBJECT_CLASS (sysprof_document_parent_class)->finalize (object); } @@ -106,6 +114,8 @@ static void sysprof_document_init (SysprofDocument *self) { self->frames = g_array_new (FALSE, FALSE, sizeof (SysprofDocumentFramePointer)); + self->strings = g_string_chunk_new (4096L * 4); + g_mutex_init (&self->strings_mutex); } static gboolean @@ -236,3 +246,19 @@ sysprof_document_new (const char *filename, return g_steal_pointer (&self); } + +const char * +sysprof_document_intern_string (SysprofDocument *self, + const char *name) +{ + g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL); + + if (name == NULL) + return NULL; + + g_mutex_lock (&self->strings_mutex); + name = g_string_chunk_insert_const (self->strings, name); + g_mutex_unlock (&self->strings_mutex); + + return name; +}