mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-analyze: add API for intern'ing strings in document
We will want to re-use strings as much as we can for resolving symbols, tags, etc.
This commit is contained in:
28
src/libsysprof-analyze/sysprof-document-private.h
Normal file
28
src/libsysprof-analyze/sysprof-document-private.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* sysprof-document-private.h
|
||||
*
|
||||
* Copyright 2023 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
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
const char *sysprof_document_intern_string (SysprofDocument *self,
|
||||
const char *name);
|
||||
|
||||
G_END_DECLS
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user