libsysprof-analyze: move timespan to analyze library

That way we can use it for the document itself, and have it update the
timespan of the recording in case it didn't get updated due to ctrl+c or
something prematurely stopping.
This commit is contained in:
Christian Hergert
2023-06-15 16:43:17 -07:00
parent 9eca425a25
commit d4da036f73
7 changed files with 92 additions and 35 deletions

View File

@ -32,6 +32,7 @@ libsysprof_analyze_public_sources = [
'sysprof-no-symbolizer.c', 'sysprof-no-symbolizer.c',
'sysprof-symbol.c', 'sysprof-symbol.c',
'sysprof-symbolizer.c', 'sysprof-symbolizer.c',
'sysprof-time-span.c',
] ]
libsysprof_analyze_private_sources = [ libsysprof_analyze_private_sources = [
@ -47,6 +48,7 @@ libsysprof_analyze_private_sources = [
'sysprof-process-info.c', 'sysprof-process-info.c',
'sysprof-strings.c', 'sysprof-strings.c',
'sysprof-symbol-cache.c', 'sysprof-symbol-cache.c',
'sysprof-time-span.h',
] ]
libsysprof_analyze_public_headers = [ libsysprof_analyze_public_headers = [

View File

@ -56,6 +56,8 @@ struct _SysprofDocument
{ {
GObject parent_instance; GObject parent_instance;
SysprofTimeSpan time_span;
GArray *frames; GArray *frames;
GMappedFile *mapped_file; GMappedFile *mapped_file;
const guint8 *base; const guint8 *base;
@ -97,6 +99,14 @@ typedef struct _SysprofDocumentFramePointer
guint64 length : 16; guint64 length : 16;
} SysprofDocumentFramePointer; } SysprofDocumentFramePointer;
enum {
PROP_0,
PROP_TIME_SPAN,
N_PROPS
};
static GParamSpec *properties[N_PROPS];
static GType static GType
sysprof_document_get_item_type (GListModel *model) sysprof_document_get_item_type (GListModel *model)
{ {
@ -244,12 +254,40 @@ sysprof_document_finalize (GObject *object)
G_OBJECT_CLASS (sysprof_document_parent_class)->finalize (object); G_OBJECT_CLASS (sysprof_document_parent_class)->finalize (object);
} }
static void
sysprof_document_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofDocument *self = SYSPROF_DOCUMENT (object);
switch (prop_id)
{
case PROP_TIME_SPAN:
g_value_set_boxed (value, sysprof_document_get_time_span (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void static void
sysprof_document_class_init (SysprofDocumentClass *klass) sysprof_document_class_init (SysprofDocumentClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = sysprof_document_finalize; object_class->finalize = sysprof_document_finalize;
object_class->get_property = sysprof_document_get_property;
properties [PROP_TIME_SPAN] =
g_param_spec_boxed ("time-span", NULL, NULL,
SYSPROF_TYPE_TIME_SPAN,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
} }
static void static void
@ -659,11 +697,15 @@ sysprof_document_load_worker (GTask *task,
self->header.end_time = GUINT64_SWAP_LE_BE (self->header.end_time); self->header.end_time = GUINT64_SWAP_LE_BE (self->header.end_time);
} }
self->time_span.begin_nsec = self->header.time;
self->time_span.end_nsec = self->header.end_time;
pos = sizeof self->header; pos = sizeof self->header;
while (pos < (len - sizeof(guint16))) while (pos < (len - sizeof(guint16)))
{ {
const SysprofCaptureFrame *tainted; const SysprofCaptureFrame *tainted;
SysprofDocumentFramePointer ptr; SysprofDocumentFramePointer ptr;
gint64 t;
guint16 frame_len; guint16 frame_len;
int pid; int pid;
@ -680,6 +722,10 @@ sysprof_document_load_worker (GTask *task,
tainted = (const SysprofCaptureFrame *)(gpointer)&self->base[pos]; tainted = (const SysprofCaptureFrame *)(gpointer)&self->base[pos];
pid = self->needs_swap ? GUINT32_SWAP_LE_BE (tainted->pid) : tainted->pid; pid = self->needs_swap ? GUINT32_SWAP_LE_BE (tainted->pid) : tainted->pid;
t = self->needs_swap ? GUINT64_SWAP_LE_BE (tainted->time) : tainted->time;
if (t > self->time_span.end_nsec)
self->time_span.end_nsec = t;
egg_bitset_add (self->pids, pid); egg_bitset_add (self->pids, pid);
@ -1514,3 +1560,11 @@ sysprof_document_catalog_marks (SysprofDocument *self)
return G_LIST_MODEL (store); return G_LIST_MODEL (store);
} }
const SysprofTimeSpan *
sysprof_document_get_time_span (SysprofDocument *self)
{
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
return &self->time_span;
}

View File

@ -29,6 +29,7 @@
#include "sysprof-document-traceable.h" #include "sysprof-document-traceable.h"
#include "sysprof-mark-catalog.h" #include "sysprof-mark-catalog.h"
#include "sysprof-symbol.h" #include "sysprof-symbol.h"
#include "sysprof-time-span.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -38,51 +39,51 @@ SYSPROF_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (SysprofDocument, sysprof_document, SYSPROF, DOCUMENT, GObject) G_DECLARE_FINAL_TYPE (SysprofDocument, sysprof_document, SYSPROF, DOCUMENT, GObject)
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gint64 sysprof_document_get_clock_at_start (SysprofDocument *self); const SysprofTimeSpan *sysprof_document_get_time_span (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofDocumentFile *sysprof_document_lookup_file (SysprofDocument *self, SysprofDocumentFile *sysprof_document_lookup_file (SysprofDocument *self,
const char *path); const char *path);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_files (SysprofDocument *self); GListModel *sysprof_document_list_files (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_traceables (SysprofDocument *self); GListModel *sysprof_document_list_traceables (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_allocations (SysprofDocument *self); GListModel *sysprof_document_list_allocations (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_samples (SysprofDocument *self); GListModel *sysprof_document_list_samples (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_processes (SysprofDocument *self); GListModel *sysprof_document_list_processes (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_jitmaps (SysprofDocument *self); GListModel *sysprof_document_list_jitmaps (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_counters (SysprofDocument *self); GListModel *sysprof_document_list_counters (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_marks (SysprofDocument *self); GListModel *sysprof_document_list_marks (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_catalog_marks (SysprofDocument *self); GListModel *sysprof_document_catalog_marks (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_symbols_in_traceable (SysprofDocument *self, GListModel *sysprof_document_list_symbols_in_traceable (SysprofDocument *self,
SysprofDocumentTraceable *traceable); SysprofDocumentTraceable *traceable);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
guint sysprof_document_symbolize_traceable (SysprofDocument *self, guint sysprof_document_symbolize_traceable (SysprofDocument *self,
SysprofDocumentTraceable *traceable, SysprofDocumentTraceable *traceable,
SysprofSymbol **symbols, SysprofSymbol **symbols,
guint n_symbols, guint n_symbols,
SysprofAddressContext *final_context); SysprofAddressContext *final_context);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_document_callgraph_async (SysprofDocument *self, void sysprof_document_callgraph_async (SysprofDocument *self,
SysprofCallgraphFlags flags, SysprofCallgraphFlags flags,
GListModel *traceables, GListModel *traceables,
gsize augment_size, gsize augment_size,
SysprofAugmentationFunc augment_func, SysprofAugmentationFunc augment_func,
gpointer augment_func_data, gpointer augment_func_data,
GDestroyNotify augment_func_data_destroy, GDestroyNotify augment_func_data_destroy,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCallgraph *sysprof_document_callgraph_finish (SysprofDocument *self, SysprofCallgraph *sysprof_document_callgraph_finish (SysprofDocument *self,
GAsyncResult *result, GAsyncResult *result,
GError **error); GError **error);
G_END_DECLS G_END_DECLS

View File

@ -27,6 +27,9 @@ G_DEFINE_BOXED_TYPE (SysprofTimeSpan, sysprof_time_span, sysprof_time_span_copy,
SysprofTimeSpan * SysprofTimeSpan *
sysprof_time_span_copy (const SysprofTimeSpan *self) sysprof_time_span_copy (const SysprofTimeSpan *self)
{ {
if (self == NULL)
return NULL;
return g_memdup2 (self, sizeof *self); return g_memdup2 (self, sizeof *self);
} }

View File

@ -3,7 +3,6 @@ libsysprof_gtk_public_sources = [
'sysprof-mark-chart.c', 'sysprof-mark-chart.c',
'sysprof-mark-table.c', 'sysprof-mark-table.c',
'sysprof-session.c', 'sysprof-session.c',
'sysprof-time-span.c',
'sysprof-weighted-callgraph-view.c', 'sysprof-weighted-callgraph-view.c',
] ]
@ -22,7 +21,6 @@ libsysprof_gtk_public_headers = [
'sysprof-mark-chart.h', 'sysprof-mark-chart.h',
'sysprof-mark-table.h', 'sysprof-mark-table.h',
'sysprof-session.h', 'sysprof-session.h',
'sysprof-time-span.h',
'sysprof-weighted-callgraph-view.h', 'sysprof-weighted-callgraph-view.h',
] ]

View File

@ -27,7 +27,6 @@ G_BEGIN_DECLS
# include "sysprof-mark-chart.h" # include "sysprof-mark-chart.h"
# include "sysprof-mark-table.h" # include "sysprof-mark-table.h"
# include "sysprof-session.h" # include "sysprof-session.h"
# include "sysprof-time-span.h"
# include "sysprof-weighted-callgraph-view.h" # include "sysprof-weighted-callgraph-view.h"
#undef SYSPROF_GTK_INSIDE #undef SYSPROF_GTK_INSIDE