mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-09 22:50:54 +00:00
libsysprof-analyze: include time as fractions for marks
This allows more easily calculating the horizontal position of marks and their duration from charts.
This commit is contained in:
@ -42,11 +42,24 @@ struct _SysprofDocumentFrameClass
|
|||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _SysprofDocumentMark
|
||||||
|
{
|
||||||
|
SysprofDocumentFrame parent_instance;
|
||||||
|
double begin_fraction;
|
||||||
|
double end_fraction;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SysprofDocumentMarkClass
|
||||||
|
{
|
||||||
|
SysprofDocumentFrameClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
SysprofDocumentFrame *_sysprof_document_frame_new (GMappedFile *mapped,
|
SysprofDocumentFrame *_sysprof_document_frame_new (GMappedFile *mapped,
|
||||||
const SysprofCaptureFrame *frame,
|
const SysprofCaptureFrame *frame,
|
||||||
guint16 frame_len,
|
guint16 frame_len,
|
||||||
gboolean needs_swap,
|
gboolean needs_swap,
|
||||||
gint64 clock_at_start);
|
gint64 begin_time,
|
||||||
|
gint64 end_time);
|
||||||
|
|
||||||
#define SYSPROF_DOCUMENT_FRAME_ENDPTR(obj) \
|
#define SYSPROF_DOCUMENT_FRAME_ENDPTR(obj) \
|
||||||
(&((const guint8 *)SYSPROF_DOCUMENT_FRAME(obj)->frame)[SYSPROF_DOCUMENT_FRAME(obj)->frame_len])
|
(&((const guint8 *)SYSPROF_DOCUMENT_FRAME(obj)->frame)[SYSPROF_DOCUMENT_FRAME(obj)->frame_len])
|
||||||
|
|||||||
@ -142,9 +142,11 @@ _sysprof_document_frame_new (GMappedFile *mapped_file,
|
|||||||
const SysprofCaptureFrame *frame,
|
const SysprofCaptureFrame *frame,
|
||||||
guint16 frame_len,
|
guint16 frame_len,
|
||||||
gboolean needs_swap,
|
gboolean needs_swap,
|
||||||
gint64 begin_time)
|
gint64 begin_time,
|
||||||
|
gint64 end_time)
|
||||||
{
|
{
|
||||||
SysprofDocumentFrame *self;
|
SysprofDocumentFrame *self;
|
||||||
|
gint64 time_offset;
|
||||||
GType gtype;
|
GType gtype;
|
||||||
|
|
||||||
switch (frame->type)
|
switch (frame->type)
|
||||||
@ -206,12 +208,27 @@ _sysprof_document_frame_new (GMappedFile *mapped_file,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self = g_object_new (gtype, NULL);
|
self = g_object_new (gtype, NULL);
|
||||||
self->mapped_file = g_mapped_file_ref (mapped_file);
|
self->mapped_file = g_mapped_file_ref (mapped_file);
|
||||||
self->frame = frame;
|
self->frame = frame;
|
||||||
self->frame_len = frame_len;
|
self->frame_len = frame_len;
|
||||||
self->needs_swap = !!needs_swap;
|
self->needs_swap = !!needs_swap;
|
||||||
self->time_offset = CLAMP (sysprof_document_frame_get_time (self) - begin_time, 0, G_MAXINT64);
|
|
||||||
|
time_offset = CLAMP (sysprof_document_frame_get_time (self) - begin_time, 0, G_MAXINT64);
|
||||||
|
|
||||||
|
/* loose precision here after about 71 minutes */
|
||||||
|
self->time_offset = (guint)time_offset;
|
||||||
|
|
||||||
|
if (frame->type == SYSPROF_CAPTURE_FRAME_MARK)
|
||||||
|
{
|
||||||
|
SysprofDocumentMark *mark = (SysprofDocumentMark *)self;
|
||||||
|
gint64 capture_duration = end_time - begin_time;
|
||||||
|
gint64 duration = sysprof_document_mark_get_duration (mark);
|
||||||
|
|
||||||
|
mark->begin_fraction = time_offset / (double)capture_duration;
|
||||||
|
mark->end_fraction = (time_offset + duration) / (double)capture_duration;
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,16 +23,6 @@
|
|||||||
#include "sysprof-document-frame-private.h"
|
#include "sysprof-document-frame-private.h"
|
||||||
#include "sysprof-document-mark.h"
|
#include "sysprof-document-mark.h"
|
||||||
|
|
||||||
struct _SysprofDocumentMark
|
|
||||||
{
|
|
||||||
SysprofDocumentFrame parent_instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _SysprofDocumentMarkClass
|
|
||||||
{
|
|
||||||
SysprofDocumentFrameClass parent_class;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_DURATION,
|
PROP_DURATION,
|
||||||
@ -48,9 +38,9 @@ static GParamSpec *properties [N_PROPS];
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_document_mark_get_property (GObject *object,
|
sysprof_document_mark_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
SysprofDocumentMark *self = SYSPROF_DOCUMENT_MARK (object);
|
SysprofDocumentMark *self = SYSPROF_DOCUMENT_MARK (object);
|
||||||
|
|
||||||
@ -159,3 +149,29 @@ sysprof_document_mark_get_message (SysprofDocumentMark *self)
|
|||||||
|
|
||||||
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mark->message);
|
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, mark->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_document_mark_get_time_fraction:
|
||||||
|
* @self: a #SysprofDocumentMark
|
||||||
|
* @begin_fraction: (out) (nullable): a location for the begin
|
||||||
|
* time as a fraction
|
||||||
|
* @end_fraction: (out) (nullable): a location for the end
|
||||||
|
* time as a fraction
|
||||||
|
*
|
||||||
|
* Gets the begin/end time of the mark as a fraction between 0 and 1.
|
||||||
|
*
|
||||||
|
* 0 is the beginning of the capture, 1 is the end of the capture.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sysprof_document_mark_get_time_fraction (SysprofDocumentMark *self,
|
||||||
|
double *begin_fraction,
|
||||||
|
double *end_fraction)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SYSPROF_IS_DOCUMENT_MARK (self));
|
||||||
|
|
||||||
|
if (begin_fraction)
|
||||||
|
*begin_fraction = self->begin_fraction;
|
||||||
|
|
||||||
|
if (end_fraction)
|
||||||
|
*end_fraction = self->end_fraction;
|
||||||
|
}
|
||||||
|
|||||||
@ -33,15 +33,19 @@ typedef struct _SysprofDocumentMark SysprofDocumentMark;
|
|||||||
typedef struct _SysprofDocumentMarkClass SysprofDocumentMarkClass;
|
typedef struct _SysprofDocumentMarkClass SysprofDocumentMarkClass;
|
||||||
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GType sysprof_document_mark_get_type (void) G_GNUC_CONST;
|
GType sysprof_document_mark_get_type (void) G_GNUC_CONST;
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
gint64 sysprof_document_mark_get_duration (SysprofDocumentMark *self);
|
gint64 sysprof_document_mark_get_duration (SysprofDocumentMark *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
const char *sysprof_document_mark_get_group (SysprofDocumentMark *self);
|
const char *sysprof_document_mark_get_group (SysprofDocumentMark *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
const char *sysprof_document_mark_get_name (SysprofDocumentMark *self);
|
const char *sysprof_document_mark_get_name (SysprofDocumentMark *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
const char *sysprof_document_mark_get_message (SysprofDocumentMark *self);
|
const char *sysprof_document_mark_get_message (SysprofDocumentMark *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_document_mark_get_time_fraction (SysprofDocumentMark *self,
|
||||||
|
double *begin_fraction,
|
||||||
|
double *end_fraction);
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentMark, g_object_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentMark, g_object_unref)
|
||||||
|
|
||||||
|
|||||||
@ -125,7 +125,8 @@ sysprof_document_get_item (GListModel *model,
|
|||||||
(gconstpointer)&self->base[ptr->offset],
|
(gconstpointer)&self->base[ptr->offset],
|
||||||
ptr->length,
|
ptr->length,
|
||||||
self->needs_swap,
|
self->needs_swap,
|
||||||
self->header.time);
|
self->header.time,
|
||||||
|
self->header.end_time);
|
||||||
|
|
||||||
/* Annotate processes with pre-calculated info */
|
/* Annotate processes with pre-calculated info */
|
||||||
if (SYSPROF_IS_DOCUMENT_PROCESS (ret))
|
if (SYSPROF_IS_DOCUMENT_PROCESS (ret))
|
||||||
|
|||||||
Reference in New Issue
Block a user