mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-capture: add flush_delay for auto flushing
This can be useful in scenarios where you need to kill the application using a signal so that data is not lost in the buffer.
This commit is contained in:
@ -133,6 +133,9 @@ struct _SysprofCaptureWriter
|
|||||||
gsize pos;
|
gsize pos;
|
||||||
gsize len;
|
gsize len;
|
||||||
|
|
||||||
|
/* GSource for periodic flush */
|
||||||
|
GSource *periodic_flush;
|
||||||
|
|
||||||
/* counter id sequence */
|
/* counter id sequence */
|
||||||
gint next_counter_id;
|
gint next_counter_id;
|
||||||
|
|
||||||
@ -164,6 +167,8 @@ sysprof_capture_writer_finalize (SysprofCaptureWriter *self)
|
|||||||
{
|
{
|
||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
{
|
||||||
|
g_clear_pointer (&self->periodic_flush, g_source_destroy);
|
||||||
|
|
||||||
sysprof_capture_writer_flush (self);
|
sysprof_capture_writer_flush (self);
|
||||||
|
|
||||||
if (self->fd != -1)
|
if (self->fd != -1)
|
||||||
@ -1469,3 +1474,39 @@ sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self,
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sysprof_capture_writer_auto_flush_cb (SysprofCaptureWriter *self)
|
||||||
|
{
|
||||||
|
g_assert (self != NULL);
|
||||||
|
|
||||||
|
sysprof_capture_writer_flush (self);
|
||||||
|
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self,
|
||||||
|
GMainContext *main_context,
|
||||||
|
guint timeout_seconds)
|
||||||
|
{
|
||||||
|
GSource *source;
|
||||||
|
|
||||||
|
g_return_if_fail (self != NULL);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->periodic_flush, g_source_destroy);
|
||||||
|
|
||||||
|
if (timeout_seconds == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
source = g_timeout_source_new_seconds (timeout_seconds);
|
||||||
|
g_source_set_name (source, "[sysprof-capture-writer-flush]");
|
||||||
|
g_source_set_priority (source, G_PRIORITY_LOW + 100);
|
||||||
|
g_source_set_callback (source,
|
||||||
|
(GSourceFunc) sysprof_capture_writer_auto_flush_cb,
|
||||||
|
self, NULL);
|
||||||
|
|
||||||
|
self->periodic_flush = g_steal_pointer (&source);
|
||||||
|
|
||||||
|
g_source_attach (self->periodic_flush, main_context);
|
||||||
|
}
|
||||||
|
|||||||
@ -81,6 +81,10 @@ SYSPROF_AVAILABLE_IN_ALL
|
|||||||
void sysprof_capture_writer_stat (SysprofCaptureWriter *self,
|
void sysprof_capture_writer_stat (SysprofCaptureWriter *self,
|
||||||
SysprofCaptureStat *stat);
|
SysprofCaptureStat *stat);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self,
|
||||||
|
GMainContext *main_context,
|
||||||
|
guint timeout_seconds);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
gboolean sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
|
gboolean sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
|
||||||
gint64 time,
|
gint64 time,
|
||||||
gint cpu,
|
gint cpu,
|
||||||
|
|||||||
Reference in New Issue
Block a user