tree: start on massive tree refactor

The big thing going on here is that we are going to split up the libraries
a bit better, and remove GObject from the capture library. The libsysprof
library will bring in the capture library statically, so we can export the
symbols we want.

Eventually, we will bump the version to sysprof-3, but not yet.
This commit is contained in:
Christian Hergert
2019-05-07 20:52:05 -07:00
parent 5323cffdb3
commit 1708ad1b48
193 changed files with 1400 additions and 1136 deletions

View File

@ -0,0 +1,53 @@
libsysprof_capture_headers = [
'sp-capture-condition.h',
'sp-capture-cursor.h',
'sp-capture-reader.h',
'sp-capture-types.h',
'sp-capture-writer.h',
'sysprof-capture.h',
]
libsysprof_capture_sources = [
'sp-capture-condition.c',
'sp-capture-cursor.c',
'sp-capture-reader.c',
'sp-capture-writer.c',
]
configure_file(
input: 'sysprof-version.h.in',
output: 'sysprof-version.h',
configuration: sysprof_version_conf,
install_dir: join_paths(get_option('includedir'), sysprof_header_subdir),
)
libsysprof_capture_deps = [
dependency('glib-2.0', version: glib_req_version),
libshared_dep,
]
install_headers(libsysprof_capture_headers, subdir: sysprof_header_subdir)
libsysprof_capture = static_library('sysprof-capture-@0@'.format(libsysprof_api_version),
libsysprof_capture_sources,
dependencies: libsysprof_capture_deps,
c_args: [ '-DSYSPROF_CAPTURE_COMPILATION' ],
install_dir: get_option('libdir'),
install: true,
)
libsysprof_capture_dep = declare_dependency(
link_whole: libsysprof_capture,
dependencies: libsysprof_capture_deps,
include_directories: include_directories('.'),
)
pkgconfig.generate(
subdirs: [ sysprof_header_subdir ],
version: meson.project_version(),
name: 'sysprof-capture-@0@'.format(libsysprof_api_version),
filebase: 'sysprof-capture-@0@'.format(libsysprof_api_version),
description: 'The static capture library for tools that generate profiling capture data',
install_dir: join_paths(get_option('libdir'), 'pkgconfig'),
requires: [ 'glib-2.0' ],
)

View File

@ -0,0 +1,357 @@
/* sp-capture-condition.c
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
*/
#define G_LOG_DOMAIN "sp-capture-condition"
#include "config.h"
#include <string.h>
#include "sp-capture-condition.h"
/**
* SECTION:sp-capture-condition
* @title: SpCaptureCondition
*
* The #SpCaptureCondition type is an abstraction on an operation
* for a sort of AST to the #SpCaptureCursor. The goal is that if
* we abstract the types of fields we want to match in the cursor
* that we can opportunistically add indexes to speed up the operation
* later on without changing the implementation of cursor consumers.
*/
typedef enum
{
SP_CAPTURE_CONDITION_AND,
SP_CAPTURE_CONDITION_WHERE_TYPE_IN,
SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN,
SP_CAPTURE_CONDITION_WHERE_PID_IN,
SP_CAPTURE_CONDITION_WHERE_COUNTER_IN,
} SpCaptureConditionType;
struct _SpCaptureCondition
{
volatile gint ref_count;
SpCaptureConditionType type;
union {
GArray *where_type_in;
struct {
gint64 begin;
gint64 end;
} where_time_between;
GArray *where_pid_in;
GArray *where_counter_in;
struct {
SpCaptureCondition *left;
SpCaptureCondition *right;
} and;
} u;
};
gboolean
sp_capture_condition_match (const SpCaptureCondition *self,
const SpCaptureFrame *frame)
{
g_assert (self != NULL);
g_assert (frame != NULL);
switch (self->type)
{
case SP_CAPTURE_CONDITION_AND:
return sp_capture_condition_match (self->u.and.left, frame) &&
sp_capture_condition_match (self->u.and.right, frame);
case SP_CAPTURE_CONDITION_WHERE_TYPE_IN:
for (guint i = 0; i < self->u.where_type_in->len; i++)
{
if (frame->type == g_array_index (self->u.where_type_in, SpCaptureFrameType, i))
return TRUE;
}
return FALSE;
case SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN:
return (frame->time >= self->u.where_time_between.begin && frame->time <= self->u.where_time_between.end);
case SP_CAPTURE_CONDITION_WHERE_PID_IN:
for (guint i = 0; i < self->u.where_pid_in->len; i++)
{
if (frame->pid == g_array_index (self->u.where_pid_in, gint32, i))
return TRUE;
}
return FALSE;
case SP_CAPTURE_CONDITION_WHERE_COUNTER_IN:
if (frame->type == SP_CAPTURE_FRAME_CTRSET)
{
const SpCaptureFrameCounterSet *set = (SpCaptureFrameCounterSet *)frame;
for (guint i = 0; i < self->u.where_counter_in->len; i++)
{
guint counter = g_array_index (self->u.where_counter_in, guint, i);
for (guint j = 0; j < set->n_values; j++)
{
if (counter == set->values[j].ids[0] ||
counter == set->values[j].ids[1] ||
counter == set->values[j].ids[2] ||
counter == set->values[j].ids[3] ||
counter == set->values[j].ids[4] ||
counter == set->values[j].ids[5] ||
counter == set->values[j].ids[6] ||
counter == set->values[j].ids[7])
return TRUE;
}
}
}
else if (frame->type == SP_CAPTURE_FRAME_CTRDEF)
{
const SpCaptureFrameCounterDefine *def = (SpCaptureFrameCounterDefine *)frame;
for (guint i = 0; i < self->u.where_counter_in->len; i++)
{
guint counter = g_array_index (self->u.where_counter_in, guint, i);
for (guint j = 0; j < def->n_counters; j++)
{
if (def->counters[j].id == counter)
return TRUE;
}
}
}
return FALSE;
default:
break;
}
g_assert_not_reached ();
return FALSE;
}
static SpCaptureCondition *
sp_capture_condition_init (void)
{
SpCaptureCondition *self;
self = g_slice_new0 (SpCaptureCondition);
self->ref_count = 1;
return g_steal_pointer (&self);
}
SpCaptureCondition *
sp_capture_condition_copy (const SpCaptureCondition *self)
{
SpCaptureCondition *copy;
copy = sp_capture_condition_init ();
copy->type = self->type;
switch (self->type)
{
case SP_CAPTURE_CONDITION_AND:
return sp_capture_condition_new_and (
sp_capture_condition_copy (self->u.and.left),
sp_capture_condition_copy (self->u.and.right));
case SP_CAPTURE_CONDITION_WHERE_TYPE_IN:
return sp_capture_condition_new_where_type_in (
self->u.where_type_in->len,
(const SpCaptureFrameType *)(gpointer)self->u.where_type_in->data);
case SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN:
break;
case SP_CAPTURE_CONDITION_WHERE_PID_IN:
return sp_capture_condition_new_where_pid_in (
self->u.where_pid_in->len,
(const gint32 *)(gpointer)self->u.where_pid_in->data);
case SP_CAPTURE_CONDITION_WHERE_COUNTER_IN:
return sp_capture_condition_new_where_counter_in (
self->u.where_counter_in->len,
(const guint *)(gpointer)self->u.where_counter_in->data);
default:
g_assert_not_reached ();
break;
}
return copy;
}
static void
sp_capture_condition_finalize (SpCaptureCondition *self)
{
switch (self->type)
{
case SP_CAPTURE_CONDITION_AND:
sp_capture_condition_unref (self->u.and.left);
sp_capture_condition_unref (self->u.and.right);
break;
case SP_CAPTURE_CONDITION_WHERE_TYPE_IN:
g_array_free (self->u.where_type_in, TRUE);
break;
case SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN:
break;
case SP_CAPTURE_CONDITION_WHERE_PID_IN:
g_array_free (self->u.where_pid_in, TRUE);
break;
case SP_CAPTURE_CONDITION_WHERE_COUNTER_IN:
g_array_free (self->u.where_counter_in, TRUE);
break;
default:
g_assert_not_reached ();
break;
}
g_slice_free (SpCaptureCondition, self);
}
SpCaptureCondition *
sp_capture_condition_ref (SpCaptureCondition *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
g_atomic_int_inc (&self->ref_count);
return self;
}
void
sp_capture_condition_unref (SpCaptureCondition *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sp_capture_condition_finalize (self);
}
SpCaptureCondition *
sp_capture_condition_new_where_type_in (guint n_types,
const SpCaptureFrameType *types)
{
SpCaptureCondition *self;
g_return_val_if_fail (types != NULL, NULL);
self = sp_capture_condition_init ();
self->type = SP_CAPTURE_CONDITION_WHERE_TYPE_IN;
self->u.where_type_in = g_array_sized_new (FALSE, FALSE, sizeof (SpCaptureFrameType), n_types);
g_array_set_size (self->u.where_type_in, n_types);
memcpy (self->u.where_type_in->data, types, sizeof (SpCaptureFrameType) * n_types);
return self;
}
SpCaptureCondition *
sp_capture_condition_new_where_time_between (gint64 begin_time,
gint64 end_time)
{
SpCaptureCondition *self;
if G_UNLIKELY (begin_time > end_time)
{
gint64 tmp = begin_time;
begin_time = end_time;
end_time = tmp;
}
self = sp_capture_condition_init ();
self->type = SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN;
self->u.where_time_between.begin = begin_time;
self->u.where_time_between.end = end_time;
return self;
}
SpCaptureCondition *
sp_capture_condition_new_where_pid_in (guint n_pids,
const gint32 *pids)
{
SpCaptureCondition *self;
g_return_val_if_fail (pids != NULL, NULL);
self = sp_capture_condition_init ();
self->type = SP_CAPTURE_CONDITION_WHERE_PID_IN;
self->u.where_pid_in = g_array_sized_new (FALSE, FALSE, sizeof (gint32), n_pids);
g_array_set_size (self->u.where_pid_in, n_pids);
memcpy (self->u.where_pid_in->data, pids, sizeof (gint32) * n_pids);
return self;
}
SpCaptureCondition *
sp_capture_condition_new_where_counter_in (guint n_counters,
const guint *counters)
{
SpCaptureCondition *self;
g_return_val_if_fail (counters != NULL || n_counters == 0, NULL);
self = sp_capture_condition_init ();
self->type = SP_CAPTURE_CONDITION_WHERE_COUNTER_IN;
self->u.where_counter_in = g_array_sized_new (FALSE, FALSE, sizeof (guint), n_counters);
if (n_counters > 0)
{
g_array_set_size (self->u.where_counter_in, n_counters);
memcpy (self->u.where_counter_in->data, counters, sizeof (guint) * n_counters);
}
return self;
}
/**
* sp_capture_condition_new_and:
* @left: (transfer full): An #SpCaptureCondition
* @right: (transfer full): An #SpCaptureCondition
*
* Creates a new #SpCaptureCondition that requires both left and right
* to evaluate to %TRUE.
*
* Returns: (transfer full): A new #SpCaptureCondition.
*/
SpCaptureCondition *
sp_capture_condition_new_and (SpCaptureCondition *left,
SpCaptureCondition *right)
{
SpCaptureCondition *self;
g_return_val_if_fail (left != NULL, NULL);
g_return_val_if_fail (right != NULL, NULL);
self = sp_capture_condition_init ();
self->type = SP_CAPTURE_CONDITION_AND;
self->u.and.left = left;
self->u.and.right = right;
return self;
}

View File

@ -0,0 +1,45 @@
/* sp-capture-condition.h
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include "sp-capture-types.h"
G_BEGIN_DECLS
SpCaptureCondition *sp_capture_condition_copy (const SpCaptureCondition *self);
void sp_capture_condition_unref (SpCaptureCondition *self);
SpCaptureCondition *sp_capture_condition_ref (SpCaptureCondition *self);
SpCaptureCondition *sp_capture_condition_new_and (SpCaptureCondition *left,
SpCaptureCondition *right);
SpCaptureCondition *sp_capture_condition_new_where_type_in (guint n_types,
const SpCaptureFrameType *types);
SpCaptureCondition *sp_capture_condition_new_where_time_between (gint64 begin_time,
gint64 end_time);
SpCaptureCondition *sp_capture_condition_new_where_pid_in (guint n_pids,
const gint32 *pids);
SpCaptureCondition *sp_capture_condition_new_where_counter_in (guint n_counters,
const guint *counters);
gboolean sp_capture_condition_match (const SpCaptureCondition *self,
const SpCaptureFrame *frame);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SpCaptureCondition, sp_capture_condition_unref)
G_END_DECLS

View File

@ -0,0 +1,265 @@
/* sp-capture-cursor.c
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
*/
#define G_LOG_DOMAIN "sp-capture-cursor"
#include "config.h"
#include "sp-capture-condition.h"
#include "sp-capture-cursor.h"
#include "sp-capture-reader.h"
#define READ_DELEGATE(f) ((ReadDelegate)(f))
typedef const SpCaptureFrame *(*ReadDelegate) (SpCaptureReader *);
struct _SpCaptureCursor
{
volatile gint ref_count;
GPtrArray *conditions;
SpCaptureReader *reader;
guint reversed : 1;
};
static void
sp_capture_cursor_finalize (SpCaptureCursor *self)
{
g_clear_pointer (&self->conditions, g_ptr_array_unref);
g_clear_pointer (&self->reader, sp_capture_reader_unref);
g_slice_free (SpCaptureCursor, self);
}
static SpCaptureCursor *
sp_capture_cursor_init (void)
{
SpCaptureCursor *self;
self = g_slice_new0 (SpCaptureCursor);
self->conditions = g_ptr_array_new_with_free_func ((GDestroyNotify) sp_capture_condition_unref);
self->ref_count = 1;
return g_steal_pointer (&self);
}
/**
* sp_capture_cursor_ref:
* @self: a #SpCaptureCursor
*
* Returns: (transfer full): @self
*
* Since: 3.34
*/
SpCaptureCursor *
sp_capture_cursor_ref (SpCaptureCursor *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
g_atomic_int_inc (&self->ref_count);
return self;
}
/**
* sp_capture_cursor_unref:
* @self: a #SpCaptureCursor
*
* Since: 3.34
*/
void
sp_capture_cursor_unref (SpCaptureCursor *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sp_capture_cursor_finalize (self);
}
/**
* sp_capture_cursor_foreach:
* @self: a #SpCaptureCursor
* @callback: (scope call): a closure to execute
* @user_data: user data for @callback
*
*/
void
sp_capture_cursor_foreach (SpCaptureCursor *self,
SpCaptureCursorCallback callback,
gpointer user_data)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->reader != NULL);
g_return_if_fail (callback != NULL);
for (;;)
{
const SpCaptureFrame *frame;
SpCaptureFrameType type = 0;
ReadDelegate delegate = NULL;
if (!sp_capture_reader_peek_type (self->reader, &type))
return;
switch (type)
{
case SP_CAPTURE_FRAME_TIMESTAMP:
delegate = READ_DELEGATE (sp_capture_reader_read_timestamp);
break;
case SP_CAPTURE_FRAME_SAMPLE:
delegate = READ_DELEGATE (sp_capture_reader_read_sample);
break;
case SP_CAPTURE_FRAME_MAP:
delegate = READ_DELEGATE (sp_capture_reader_read_map);
break;
case SP_CAPTURE_FRAME_MARK:
delegate = READ_DELEGATE (sp_capture_reader_read_mark);
break;
case SP_CAPTURE_FRAME_PROCESS:
delegate = READ_DELEGATE (sp_capture_reader_read_process);
break;
case SP_CAPTURE_FRAME_FORK:
delegate = READ_DELEGATE (sp_capture_reader_read_fork);
break;
case SP_CAPTURE_FRAME_EXIT:
delegate = READ_DELEGATE (sp_capture_reader_read_exit);
break;
case SP_CAPTURE_FRAME_JITMAP:
delegate = READ_DELEGATE (sp_capture_reader_read_jitmap);
break;
case SP_CAPTURE_FRAME_CTRDEF:
delegate = READ_DELEGATE (sp_capture_reader_read_counter_define);
break;
case SP_CAPTURE_FRAME_CTRSET:
delegate = READ_DELEGATE (sp_capture_reader_read_counter_set);
break;
default:
if (!sp_capture_reader_skip (self->reader))
return;
delegate = NULL;
break;
}
if (delegate == NULL)
continue;
if (NULL == (frame = delegate (self->reader)))
return;
if (self->conditions->len == 0)
{
if (!callback (frame, user_data))
return;
}
else
{
for (guint i = 0; i < self->conditions->len; i++)
{
const SpCaptureCondition *condition = g_ptr_array_index (self->conditions, i);
if (sp_capture_condition_match (condition, frame))
{
if (!callback (frame, user_data))
return;
break;
}
}
}
}
}
void
sp_capture_cursor_reset (SpCaptureCursor *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->reader != NULL);
sp_capture_reader_reset (self->reader);
}
void
sp_capture_cursor_reverse (SpCaptureCursor *self)
{
g_return_if_fail (self != NULL);
self->reversed = !self->reversed;
}
/**
* sp_capture_cursor_add_condition:
* @self: An #SpCaptureCursor
* @condition: (transfer full): An #SpCaptureCondition
*
* Adds the condition to the cursor. This condition must evaluate to
* true or a given #SpCapureFrame will not be matched.
*/
void
sp_capture_cursor_add_condition (SpCaptureCursor *self,
SpCaptureCondition *condition)
{
g_return_if_fail (self != NULL);
g_return_if_fail (condition != NULL);
g_ptr_array_add (self->conditions, condition);
}
/**
* sp_capture_cursor_new:
* @self: a #SpCaptureCursor
*
* Returns: (transfer full): a new cursor for @reader
*/
SpCaptureCursor *
sp_capture_cursor_new (SpCaptureReader *reader)
{
SpCaptureCursor *self;
g_return_val_if_fail (reader != NULL, NULL);
self = sp_capture_cursor_init ();
self->reader = sp_capture_reader_copy (reader);
sp_capture_reader_reset (self->reader);
return self;
}
/**
* sp_capture_cursor_get_reader:
*
* Gets the underlying reader that is used by the cursor.
*
* Returns: (transfer none): An #SpCaptureReader
*/
SpCaptureReader *
sp_capture_cursor_get_reader (SpCaptureCursor *self)
{
g_return_val_if_fail (self != NULL, NULL);
return self->reader;
}

View File

@ -0,0 +1,57 @@
/* sp-capture-cursor.h
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include "sp-capture-types.h"
G_BEGIN_DECLS
typedef struct _SpCaptureCursor SpCaptureCursor;
/**
* SpCaptureCursorCallback:
*
* This is the prototype for callbacks that are called for each frame
* matching the cursor query.
*
* Functions matching this typedef should return %TRUE if they want the
* the caller to stop iteration of cursor.
*
* Returns: %TRUE if iteration should stop, otherwise %FALSE.
*/
typedef gboolean (*SpCaptureCursorCallback) (const SpCaptureFrame *frame,
gpointer user_data);
SpCaptureCursor *sp_capture_cursor_new (SpCaptureReader *reader);
void sp_capture_cursor_unref (SpCaptureCursor *self);
SpCaptureCursor *sp_capture_cursor_ref (SpCaptureCursor *self);
SpCaptureReader *sp_capture_cursor_get_reader (SpCaptureCursor *self);
void sp_capture_cursor_foreach (SpCaptureCursor *self,
SpCaptureCursorCallback callback,
gpointer user_data);
void sp_capture_cursor_reset (SpCaptureCursor *self);
void sp_capture_cursor_reverse (SpCaptureCursor *self);
void sp_capture_cursor_add_condition (SpCaptureCursor *self,
SpCaptureCondition *condition);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SpCaptureCursor, sp_capture_cursor_unref)
G_END_DECLS

View File

@ -0,0 +1,950 @@
/* sp-capture-reader.c
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
*/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "sp-capture-reader.h"
#include "sp-capture-util-private.h"
#include "sp-capture-writer.h"
struct _SpCaptureReader
{
volatile gint ref_count;
gchar *filename;
guint8 *buf;
gsize bufsz;
gsize len;
gsize pos;
gsize fd_off;
int fd;
gint endian;
SpCaptureFileHeader header;
gint64 end_time;
};
#ifdef SP_ENABLE_GOBJECT
G_DEFINE_BOXED_TYPE (SpCaptureReader, sp_capture_reader,
sp_capture_reader_ref, sp_capture_reader_unref)
#endif
static gboolean
sp_capture_reader_read_file_header (SpCaptureReader *self,
SpCaptureFileHeader *header,
GError **error)
{
g_assert (self != NULL);
g_assert (header != NULL);
if (sizeof *header != _sp_pread (self->fd, header, sizeof *header, 0L))
{
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
"%s", g_strerror (errno));
return FALSE;
}
if (header->magic != SP_CAPTURE_MAGIC)
{
g_set_error (error,
G_FILE_ERROR,
G_FILE_ERROR_FAILED,
"Capture file magic does not match");
return FALSE;
}
header->capture_time[sizeof header->capture_time - 1] = '\0';
return TRUE;
}
static void
sp_capture_reader_finalize (SpCaptureReader *self)
{
if (self != NULL)
{
close (self->fd);
g_free (self->buf);
g_free (self->filename);
g_free (self);
}
}
const gchar *
sp_capture_reader_get_time (SpCaptureReader *self)
{
g_return_val_if_fail (self != NULL, NULL);
return self->header.capture_time;
}
const gchar *
sp_capture_reader_get_filename (SpCaptureReader *self)
{
g_return_val_if_fail (self != NULL, NULL);
return self->filename;
}
/**
* sp_capture_reader_new_from_fd:
* @fd: an fd to take ownership from
* @error: a location for a #GError or %NULL
*
* Creates a new reader using the file-descriptor.
*
* This is useful if you don't necessarily have access to the filename itself.
*
* Returns: (transfer full): an #SpCaptureReader or %NULL upon failure.
*/
SpCaptureReader *
sp_capture_reader_new_from_fd (int fd,
GError **error)
{
SpCaptureReader *self;
g_assert (fd > -1);
self = g_new0 (SpCaptureReader, 1);
self->ref_count = 1;
self->bufsz = G_MAXUSHORT * 2;
self->buf = g_malloc (self->bufsz);
self->len = 0;
self->pos = 0;
self->fd = fd;
self->fd_off = sizeof (SpCaptureFileHeader);
if (!sp_capture_reader_read_file_header (self, &self->header, error))
{
sp_capture_reader_finalize (self);
return NULL;
}
if (self->header.little_endian)
self->endian = G_LITTLE_ENDIAN;
else
self->endian = G_BIG_ENDIAN;
return self;
}
SpCaptureReader *
sp_capture_reader_new (const gchar *filename,
GError **error)
{
SpCaptureReader *self;
int fd;
g_assert (filename != NULL);
if (-1 == (fd = open (filename, O_RDONLY, 0)))
{
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
"%s", g_strerror (errno));
return NULL;
}
if (NULL == (self = sp_capture_reader_new_from_fd (fd, error)))
{
close (fd);
return NULL;
}
self->filename = g_strdup (filename);
return self;
}
static inline void
sp_capture_reader_bswap_frame (SpCaptureReader *self,
SpCaptureFrame *frame)
{
g_assert (self != NULL);
g_assert (frame!= NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
frame->len = GUINT16_SWAP_LE_BE (frame->len);
frame->cpu = GUINT16_SWAP_LE_BE (frame->cpu);
frame->pid = GUINT32_SWAP_LE_BE (frame->pid);
frame->time = GUINT64_SWAP_LE_BE (frame->time);
}
}
static inline void
sp_capture_reader_bswap_map (SpCaptureReader *self,
SpCaptureMap *map)
{
g_assert (self != NULL);
g_assert (map != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
map->start = GUINT64_SWAP_LE_BE (map->start);
map->end = GUINT64_SWAP_LE_BE (map->end);
map->offset = GUINT64_SWAP_LE_BE (map->offset);
map->inode = GUINT64_SWAP_LE_BE (map->inode);
}
}
static inline void
sp_capture_reader_bswap_mark (SpCaptureReader *self,
SpCaptureMark *mark)
{
g_assert (self != NULL);
g_assert (mark != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
mark->duration = GUINT64_SWAP_LE_BE (mark->duration);
}
static inline void
sp_capture_reader_bswap_jitmap (SpCaptureReader *self,
SpCaptureJitmap *jitmap)
{
g_assert (self != NULL);
g_assert (jitmap != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
jitmap->n_jitmaps = GUINT64_SWAP_LE_BE (jitmap->n_jitmaps);
}
static gboolean
sp_capture_reader_ensure_space_for (SpCaptureReader *self,
gsize len)
{
g_assert (self != NULL);
g_assert (self->pos <= self->len);
g_assert (len > 0);
if ((self->len - self->pos) < len)
{
gssize r;
if (self->len > self->pos)
memmove (self->buf, &self->buf[self->pos], self->len - self->pos);
self->len -= self->pos;
self->pos = 0;
while (self->len < len)
{
g_assert ((self->pos + self->len) < self->bufsz);
g_assert (self->len < self->bufsz);
/* Read into our buffer after our current read position */
r = _sp_pread (self->fd,
&self->buf[self->len],
self->bufsz - self->len,
self->fd_off);
if (r <= 0)
break;
self->fd_off += r;
self->len += r;
}
}
return (self->len - self->pos) >= len;
}
gboolean
sp_capture_reader_skip (SpCaptureReader *self)
{
SpCaptureFrame *frame;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
if (!sp_capture_reader_ensure_space_for (self, sizeof (SpCaptureFrame)))
return FALSE;
frame = (SpCaptureFrame *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, frame);
if (frame->len < sizeof (SpCaptureFrame))
return FALSE;
if (!sp_capture_reader_ensure_space_for (self, frame->len))
return FALSE;
frame = (SpCaptureFrame *)(gpointer)&self->buf[self->pos];
self->pos += frame->len;
if ((self->pos % SP_CAPTURE_ALIGN) != 0)
return FALSE;
return TRUE;
}
gboolean
sp_capture_reader_peek_frame (SpCaptureReader *self,
SpCaptureFrame *frame)
{
SpCaptureFrame *real_frame;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->len);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *real_frame))
return FALSE;
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
real_frame = (SpCaptureFrame *)(gpointer)&self->buf[self->pos];
*frame = *real_frame;
sp_capture_reader_bswap_frame (self, frame);
if (frame->time > self->end_time)
self->end_time = frame->time;
return TRUE;
}
gboolean
sp_capture_reader_peek_type (SpCaptureReader *self,
SpCaptureFrameType *type)
{
SpCaptureFrame frame;
g_assert (self != NULL);
g_assert (type != NULL);
if (!sp_capture_reader_peek_frame (self, &frame))
return FALSE;
*type = frame.type;
return TRUE;
}
static const SpCaptureFrame *
sp_capture_reader_read_basic (SpCaptureReader *self,
SpCaptureFrameType type,
gsize extra)
{
SpCaptureFrame *frame;
gsize len = sizeof *frame + extra;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, len))
return NULL;
frame = (SpCaptureFrame *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, frame);
if (frame->len < len)
return NULL;
if (frame->type != type)
return NULL;
self->pos += frame->len;
return frame;
}
const SpCaptureTimestamp *
sp_capture_reader_read_timestamp (SpCaptureReader *self)
{
return (SpCaptureTimestamp *)
sp_capture_reader_read_basic (self, SP_CAPTURE_FRAME_TIMESTAMP, 0);
}
const SpCaptureExit *
sp_capture_reader_read_exit (SpCaptureReader *self)
{
return (SpCaptureExit *)
sp_capture_reader_read_basic (self, SP_CAPTURE_FRAME_EXIT, 0);
}
const SpCaptureFork *
sp_capture_reader_read_fork (SpCaptureReader *self)
{
SpCaptureFork *fk;
g_assert (self != NULL);
fk = (SpCaptureFork *)
sp_capture_reader_read_basic (self, SP_CAPTURE_FRAME_FORK, sizeof(guint32));
if (fk != NULL)
{
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
fk->child_pid = GUINT32_SWAP_LE_BE (fk->child_pid);
}
return fk;
}
const SpCaptureMap *
sp_capture_reader_read_map (SpCaptureReader *self)
{
SpCaptureMap *map;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *map))
return NULL;
map = (SpCaptureMap *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, &map->frame);
if (map->frame.type != SP_CAPTURE_FRAME_MAP)
return NULL;
if (map->frame.len < (sizeof *map + 1))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, map->frame.len))
return NULL;
map = (SpCaptureMap *)(gpointer)&self->buf[self->pos];
if (self->buf[self->pos + map->frame.len - 1] != '\0')
return NULL;
sp_capture_reader_bswap_map (self, map);
self->pos += map->frame.len;
if ((self->pos % SP_CAPTURE_ALIGN) != 0)
return NULL;
return map;
}
const SpCaptureMark *
sp_capture_reader_read_mark (SpCaptureReader *self)
{
SpCaptureMark *mark;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *mark))
return NULL;
mark = (SpCaptureMark *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, &mark->frame);
if (mark->frame.type != SP_CAPTURE_FRAME_MARK)
return NULL;
if (mark->frame.len < (sizeof *mark + 1))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, mark->frame.len))
return NULL;
mark = (SpCaptureMark *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_mark (self, mark);
self->pos += mark->frame.len;
if ((self->pos % SP_CAPTURE_ALIGN) != 0)
return NULL;
/* Ensure trailing \0 in name and message */
mark->name[sizeof mark->name - 1] = 0;
self->buf[self->pos + mark->frame.len - 1] = 0;
return mark;
}
const SpCaptureProcess *
sp_capture_reader_read_process (SpCaptureReader *self)
{
SpCaptureProcess *process;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *process))
return NULL;
process = (SpCaptureProcess *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, &process->frame);
if (process->frame.type != SP_CAPTURE_FRAME_PROCESS)
return NULL;
if (process->frame.len < (sizeof *process + 1))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, process->frame.len))
return NULL;
process = (SpCaptureProcess *)(gpointer)&self->buf[self->pos];
if (self->buf[self->pos + process->frame.len - 1] != '\0')
return NULL;
self->pos += process->frame.len;
if ((self->pos % SP_CAPTURE_ALIGN) != 0)
return NULL;
return process;
}
GHashTable *
sp_capture_reader_read_jitmap (SpCaptureReader *self)
{
g_autoptr(GHashTable) ret = NULL;
SpCaptureJitmap *jitmap;
guint8 *buf;
guint8 *endptr;
guint i;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *jitmap))
return NULL;
jitmap = (SpCaptureJitmap *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, &jitmap->frame);
if (jitmap->frame.type != SP_CAPTURE_FRAME_JITMAP)
return NULL;
if (jitmap->frame.len < sizeof *jitmap)
return NULL;
if (!sp_capture_reader_ensure_space_for (self, jitmap->frame.len))
return NULL;
jitmap = (SpCaptureJitmap *)(gpointer)&self->buf[self->pos];
ret = g_hash_table_new_full (NULL, NULL, NULL, g_free);
buf = jitmap->data;
endptr = &self->buf[self->pos + jitmap->frame.len];
for (i = 0; i < jitmap->n_jitmaps; i++)
{
SpCaptureAddress addr;
const gchar *str;
if (buf + sizeof addr >= endptr)
return NULL;
memcpy (&addr, buf, sizeof addr);
buf += sizeof addr;
str = (gchar *)buf;
buf = memchr (buf, '\0', (endptr - buf));
if (buf == NULL)
return NULL;
buf++;
g_hash_table_insert (ret, GSIZE_TO_POINTER (addr), g_strdup (str));
}
sp_capture_reader_bswap_jitmap (self, jitmap);
self->pos += jitmap->frame.len;
return g_steal_pointer (&ret);
}
const SpCaptureSample *
sp_capture_reader_read_sample (SpCaptureReader *self)
{
SpCaptureSample *sample;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *sample))
return NULL;
sample = (SpCaptureSample *)(gpointer)&self->buf[self->pos];
sp_capture_reader_bswap_frame (self, &sample->frame);
if (sample->frame.type != SP_CAPTURE_FRAME_SAMPLE)
return NULL;
if (sample->frame.len < sizeof *sample)
return NULL;
if (self->endian != G_BYTE_ORDER)
sample->n_addrs = GUINT16_SWAP_LE_BE (sample->n_addrs);
if (sample->frame.len < (sizeof *sample + (sizeof(SpCaptureAddress) * sample->n_addrs)))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, sample->frame.len))
return NULL;
sample = (SpCaptureSample *)(gpointer)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
guint i;
for (i = 0; i < sample->n_addrs; i++)
sample->addrs[i] = GUINT64_SWAP_LE_BE (sample->addrs[i]);
}
self->pos += sample->frame.len;
return sample;
}
const SpCaptureFrameCounterDefine *
sp_capture_reader_read_counter_define (SpCaptureReader *self)
{
SpCaptureFrameCounterDefine *def;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *def))
return NULL;
def = (SpCaptureFrameCounterDefine *)(gpointer)&self->buf[self->pos];
if (def->frame.type != SP_CAPTURE_FRAME_CTRDEF)
return NULL;
if (def->frame.len < sizeof *def)
return NULL;
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
def->n_counters = GUINT16_SWAP_LE_BE (def->n_counters);
if (def->frame.len < (sizeof *def + (sizeof (SpCaptureFrameCounterDefine) * def->n_counters)))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, def->frame.len))
return NULL;
def = (SpCaptureFrameCounterDefine *)(gpointer)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
guint i;
for (i = 0; i < def->n_counters; i++)
{
def->counters[i].id = GUINT32_SWAP_LE_BE (def->counters[i].id);
def->counters[i].value.v64 = GUINT64_SWAP_LE_BE (def->counters[i].value.v64);
}
}
self->pos += def->frame.len;
return def;
}
const SpCaptureFrameCounterSet *
sp_capture_reader_read_counter_set (SpCaptureReader *self)
{
SpCaptureFrameCounterSet *set;
g_assert (self != NULL);
g_assert ((self->pos % SP_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
if (!sp_capture_reader_ensure_space_for (self, sizeof *set))
return NULL;
set = (SpCaptureFrameCounterSet *)(gpointer)&self->buf[self->pos];
if (set->frame.type != SP_CAPTURE_FRAME_CTRSET)
return NULL;
if (set->frame.len < sizeof *set)
return NULL;
if (self->endian != G_BYTE_ORDER)
set->n_values = GUINT16_SWAP_LE_BE (set->n_values);
if (set->frame.len < (sizeof *set + (sizeof (SpCaptureCounterValues) * set->n_values)))
return NULL;
if (!sp_capture_reader_ensure_space_for (self, set->frame.len))
return NULL;
set = (SpCaptureFrameCounterSet *)(gpointer)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
guint i;
for (i = 0; i < set->n_values; i++)
{
guint j;
for (j = 0; j < G_N_ELEMENTS (set->values[0].values); j++)
{
set->values[i].ids[j] = GUINT32_SWAP_LE_BE (set->values[i].ids[j]);
set->values[i].values[j].v64 = GUINT64_SWAP_LE_BE (set->values[i].values[j].v64);
}
}
}
self->pos += set->frame.len;
return set;
}
gboolean
sp_capture_reader_reset (SpCaptureReader *self)
{
g_assert (self != NULL);
self->fd_off = sizeof (SpCaptureFileHeader);
self->pos = 0;
self->len = 0;
return TRUE;
}
SpCaptureReader *
sp_capture_reader_ref (SpCaptureReader *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
return self;
}
void
sp_capture_reader_unref (SpCaptureReader *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sp_capture_reader_finalize (self);
}
gboolean
sp_capture_reader_splice (SpCaptureReader *self,
SpCaptureWriter *dest,
GError **error)
{
g_assert (self != NULL);
g_assert (self->fd != -1);
g_assert (dest != NULL);
/* Flush before writing anything to ensure consistency */
if (!sp_capture_writer_flush (dest))
{
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
"%s", g_strerror (errno));
return FALSE;
}
/*
* We don't need to track position because writer will
* track the current position to avoid reseting it.
*/
/* Perform the splice */
return _sp_capture_writer_splice_from_fd (dest, self->fd, error);
}
/**
* sp_capture_reader_save_as:
* @self: An #SpCaptureReader
* @filename: the file to save the capture as
* @error: a location for a #GError or %NULL.
*
* This is a convenience function for copying a capture file for which
* you may have already discarded the writer for.
*
* Returns: %TRUE on success; otherwise %FALSE and @error is set.
*/
gboolean
sp_capture_reader_save_as (SpCaptureReader *self,
const gchar *filename,
GError **error)
{
struct stat stbuf;
off_t in_off;
gsize to_write;
int fd = -1;
g_assert (self != NULL);
g_assert (filename != NULL);
if (-1 == (fd = open (filename, O_CREAT | O_WRONLY, 0640)))
goto handle_errno;
if (-1 == fstat (self->fd, &stbuf))
goto handle_errno;
if (-1 == ftruncate (fd, stbuf.st_size))
goto handle_errno;
if ((off_t)-1 == lseek (fd, 0L, SEEK_SET))
goto handle_errno;
in_off = 0;
to_write = stbuf.st_size;
while (to_write > 0)
{
gssize written;
written = _sp_sendfile (fd, self->fd, &in_off, to_write);
if (written < 0)
goto handle_errno;
if (written == 0 && errno != EAGAIN)
goto handle_errno;
g_assert (written <= (gssize)to_write);
to_write -= written;
}
close (fd);
return TRUE;
handle_errno:
if (fd != -1)
close (fd);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errno),
"%s", g_strerror (errno));
return FALSE;
}
gint64
sp_capture_reader_get_start_time (SpCaptureReader *self)
{
g_return_val_if_fail (self != NULL, 0);
if (self->endian != G_BYTE_ORDER)
return GUINT64_SWAP_LE_BE (self->header.time);
return self->header.time;
}
/**
* sp_capture_reader_get_end_time:
*
* This function will return the end time for the capture, which is the
* same as the last event added to the capture.
*
* If the end time has been stored in the capture header, that will be used.
* Otherwise, the time is discovered from the last capture frame and therefore
* the caller must have read all frames to ensure this value is accurate.
*
* Captures created by sysprof versions containing this API will have the
* end time set if the output capture file-descriptor supports seeking.
*
* Since: 3.22.1
*/
gint64
sp_capture_reader_get_end_time (SpCaptureReader *self)
{
g_return_val_if_fail (self != NULL, 0);
if (self->header.end_time != 0)
{
if (self->endian != G_BYTE_ORDER)
return GUINT64_SWAP_LE_BE (self->header.end_time);
return self->header.end_time;
}
return self->end_time;
}
/**
* sp_capture_reader_copy:
*
* This function makes a copy of the reader. Since readers use
* positioned reads with pread(), this allows you to have multiple
* readers with the shared file descriptor. This uses dup() to create
* another file descriptor.
*
* Returns: (transfer full): A copy of @self with a new file-descriptor.
*/
SpCaptureReader *
sp_capture_reader_copy (SpCaptureReader *self)
{
SpCaptureReader *copy;
int fd;
g_return_val_if_fail (self != NULL, NULL);
if (-1 == (fd = dup (self->fd)))
return NULL;
copy = g_new0 (SpCaptureReader, 1);
*copy = *self;
copy->ref_count = 1;
copy->filename = g_strdup (self->filename);
copy->fd = fd;
copy->buf = g_malloc (self->bufsz);
memcpy (copy->buf, self->buf, self->bufsz);
return copy;
}

View File

@ -0,0 +1,72 @@
/* sp-capture-reader.h
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include "sp-capture-types.h"
G_BEGIN_DECLS
typedef struct _SpCaptureReader SpCaptureReader;
SpCaptureReader *sp_capture_reader_new (const gchar *filename,
GError **error);
SpCaptureReader *sp_capture_reader_new_from_fd (int fd,
GError **error);
SpCaptureReader *sp_capture_reader_copy (SpCaptureReader *self);
SpCaptureReader *sp_capture_reader_ref (SpCaptureReader *self);
void sp_capture_reader_unref (SpCaptureReader *self);
const gchar *sp_capture_reader_get_filename (SpCaptureReader *self);
const gchar *sp_capture_reader_get_time (SpCaptureReader *self);
gint64 sp_capture_reader_get_start_time (SpCaptureReader *self);
gint64 sp_capture_reader_get_end_time (SpCaptureReader *self);
gboolean sp_capture_reader_skip (SpCaptureReader *self);
gboolean sp_capture_reader_peek_type (SpCaptureReader *self,
SpCaptureFrameType *type);
gboolean sp_capture_reader_peek_frame (SpCaptureReader *self,
SpCaptureFrame *frame);
const SpCaptureMap *sp_capture_reader_read_map (SpCaptureReader *self);
const SpCaptureMark *sp_capture_reader_read_mark (SpCaptureReader *self);
const SpCaptureExit *sp_capture_reader_read_exit (SpCaptureReader *self);
const SpCaptureFork *sp_capture_reader_read_fork (SpCaptureReader *self);
const SpCaptureTimestamp *sp_capture_reader_read_timestamp (SpCaptureReader *self);
const SpCaptureProcess *sp_capture_reader_read_process (SpCaptureReader *self);
const SpCaptureSample *sp_capture_reader_read_sample (SpCaptureReader *self);
GHashTable *sp_capture_reader_read_jitmap (SpCaptureReader *self);
const SpCaptureFrameCounterDefine *sp_capture_reader_read_counter_define (SpCaptureReader *self);
const SpCaptureFrameCounterSet *sp_capture_reader_read_counter_set (SpCaptureReader *self);
gboolean sp_capture_reader_reset (SpCaptureReader *self);
gboolean sp_capture_reader_splice (SpCaptureReader *self,
SpCaptureWriter *dest,
GError **error);
gboolean sp_capture_reader_save_as (SpCaptureReader *self,
const gchar *filename,
GError **error);
#ifdef SP_ENABLE_GOBJECT
# define SP_TYPE_CAPTURE_READER (sp_capture_reader_get_type())
GType sp_capture_reader_get_type (void);
#endif
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SpCaptureReader, sp_capture_reader_unref)
#endif
G_END_DECLS

View File

@ -0,0 +1,256 @@
/* sp-capture-types.h
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include <glib.h>
#include "sp-clock.h"
G_BEGIN_DECLS
#define SP_CAPTURE_MAGIC (GUINT32_TO_LE(0xFDCA975E))
#define SP_CAPTURE_ALIGN (sizeof(SpCaptureAddress))
#if defined(_MSC_VER)
# define SP_ALIGNED_BEGIN(_N) __declspec(align (_N))
# define SP_ALIGNED_END(_N)
#else
# define SP_ALIGNED_BEGIN(_N)
# define SP_ALIGNED_END(_N) __attribute__((aligned ((_N))))
#endif
#if GLIB_SIZEOF_VOID_P == 8
# define SP_CAPTURE_JITMAP_MARK G_GUINT64_CONSTANT(0xE000000000000000)
# define SP_CAPTURE_ADDRESS_FORMAT "0x%016lx"
#elif GLIB_SIZEOF_VOID_P == 4
# define SP_CAPTURE_JITMAP_MARK G_GUINT64_CONSTANT(0xE0000000)
# define SP_CAPTURE_ADDRESS_FORMAT "0x%016llx"
#else
#error Unknown GLIB_SIZEOF_VOID_P
#endif
#define SP_CAPTURE_CURRENT_TIME (sp_clock_get_current_time())
#define SP_CAPTURE_COUNTER_INT64 0
#define SP_CAPTURE_COUNTER_DOUBLE 1
typedef struct _SpCaptureReader SpCaptureReader;
typedef struct _SpCaptureWriter SpCaptureWriter;
typedef struct _SpCaptureCursor SpCaptureCursor;
typedef struct _SpCaptureCondition SpCaptureCondition;
typedef guint64 SpCaptureAddress;
typedef union
{
gint64 v64;
gdouble vdbl;
} SpCaptureCounterValue;
typedef enum
{
SP_CAPTURE_FRAME_TIMESTAMP = 1,
SP_CAPTURE_FRAME_SAMPLE = 2,
SP_CAPTURE_FRAME_MAP = 3,
SP_CAPTURE_FRAME_PROCESS = 4,
SP_CAPTURE_FRAME_FORK = 5,
SP_CAPTURE_FRAME_EXIT = 6,
SP_CAPTURE_FRAME_JITMAP = 7,
SP_CAPTURE_FRAME_CTRDEF = 8,
SP_CAPTURE_FRAME_CTRSET = 9,
SP_CAPTURE_FRAME_MARK = 10,
} SpCaptureFrameType;
SP_ALIGNED_BEGIN(1)
typedef struct
{
guint32 magic;
guint32 version : 8;
guint32 little_endian : 1;
guint32 padding : 23;
gchar capture_time[64];
gint64 time;
gint64 end_time;
gchar suffix[168];
} SpCaptureFileHeader
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
guint16 len;
gint16 cpu;
gint32 pid;
gint64 time;
guint32 type : 8;
guint32 padding1 : 24;
guint32 padding2;
guint8 data[0];
} SpCaptureFrame
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
guint64 start;
guint64 end;
guint64 offset;
guint64 inode;
gchar filename[0];
} SpCaptureMap
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
guint32 n_jitmaps;
guint8 data[0];
} SpCaptureJitmap
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
gchar cmdline[0];
} SpCaptureProcess
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
guint32 n_addrs : 16;
guint32 padding1 : 16;
guint32 padding2;
SpCaptureAddress addrs[0];
} SpCaptureSample
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
gint32 child_pid;
} SpCaptureFork
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
} SpCaptureExit
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
} SpCaptureTimestamp
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
gchar category[32];
gchar name[32];
gchar description[52];
guint32 id : 24;
guint32 type : 8;
SpCaptureCounterValue value;
} SpCaptureCounter
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
guint32 n_counters : 16;
guint32 padding1 : 16;
guint32 padding2;
SpCaptureCounter counters[0];
} SpCaptureFrameCounterDefine
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
/*
* 96 bytes might seem a bit odd, but the counter frame header is 32
* bytes. So this makes a nice 2-cacheline aligned size which is
* useful when the number of counters is rather small.
*/
guint32 ids[8];
SpCaptureCounterValue values[8];
} SpCaptureCounterValues
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
guint32 n_values : 16;
guint32 padding1 : 16;
guint32 padding2;
SpCaptureCounterValues values[0];
} SpCaptureFrameCounterSet
SP_ALIGNED_END(1);
SP_ALIGNED_BEGIN(1)
typedef struct
{
SpCaptureFrame frame;
gint64 duration;
gchar group[24];
gchar name[40];
gchar message[0];
} SpCaptureMark
SP_ALIGNED_END(1);
G_STATIC_ASSERT (sizeof (SpCaptureFileHeader) == 256);
G_STATIC_ASSERT (sizeof (SpCaptureFrame) == 24);
G_STATIC_ASSERT (sizeof (SpCaptureMap) == 56);
G_STATIC_ASSERT (sizeof (SpCaptureJitmap) == 28);
G_STATIC_ASSERT (sizeof (SpCaptureProcess) == 24);
G_STATIC_ASSERT (sizeof (SpCaptureSample) == 32);
G_STATIC_ASSERT (sizeof (SpCaptureFork) == 28);
G_STATIC_ASSERT (sizeof (SpCaptureExit) == 24);
G_STATIC_ASSERT (sizeof (SpCaptureTimestamp) == 24);
G_STATIC_ASSERT (sizeof (SpCaptureCounter) == 128);
G_STATIC_ASSERT (sizeof (SpCaptureCounterValues) == 96);
G_STATIC_ASSERT (sizeof (SpCaptureFrameCounterDefine) == 32);
G_STATIC_ASSERT (sizeof (SpCaptureFrameCounterSet) == 32);
G_STATIC_ASSERT (sizeof (SpCaptureMark) == 96);
static inline gint
sp_capture_address_compare (SpCaptureAddress a,
SpCaptureAddress b)
{
if (a < b)
return -1;
if (a > b)
return 1;
else
return 0;
}
G_END_DECLS

View File

@ -0,0 +1,56 @@
/* sp-capture-util-private.h
*
* Copyright 2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include <glib.h>
#ifdef __linux__
# include <sys/sendfile.h>
#endif
#include <unistd.h>
#ifdef __linux__
# define _sp_getpagesize getpagesize
# define _sp_pread pread
# define _sp_pwrite pwrite
# define _sp_write write
# define _sp_getpid getpid
# define _sp_sendfile sendfile
#else
size_t _sp_getpagesize (void);
ssize_t _sp_pread (int fd,
void *buf,
size_t count,
off_t offset);
ssize_t _sp_pwrite (int fd,
const void *buf,
size_t count,
off_t offset);
ssize_t _sp_write (int fd,
const void *buf,
size_t count);
gint32 _sp_getpid (void);
ssize_t _sp_sendfile (int out_fd,
int in_fd,
off_t *offset,
size_t count);
#endif

View File

@ -0,0 +1,195 @@
/* sp-capture-util.c
*
* Copyright 2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
*/
#include <errno.h>
#include <glib.h>
#ifdef G_OS_WIN32
# include <process.h>
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#include "sp-capture-util-private.h"
#ifdef G_OS_WIN32
static G_LOCK_DEFINE (_sp_io_sync);
#endif
size_t
_sp_getpagesize (void)
{
static size_t pgsz = 0;
if G_UNLIKELY (pgsz == 0)
{
#ifdef G_OS_WIN32
SYSTEM_INFO system_info;
GetSystemInfo (&system_info);
pgsz = system_info.dwPageSize;
#else
pgsz = getpagesize ();
#endif
}
return pgsz;
}
ssize_t
_sp_pread (int fd,
void *buf,
size_t count,
off_t offset)
{
#ifdef G_OS_WIN32
ssize_t ret = -1;
G_LOCK (_sp_io_sync);
errno = 0;
if (lseek (fd, offset, SEEK_SET) != -1)
ret = read (fd, buf, count);
G_UNLOCK (_sp_io_sync);
return ret;
#else
errno = 0;
return pread (fd, buf, count, offset);
#endif
}
ssize_t
_sp_pwrite (int fd,
const void *buf,
size_t count,
off_t offset)
{
#ifdef G_OS_WIN32
ssize_t ret = -1;
G_LOCK (_sp_io_sync);
errno = 0;
if (lseek (fd, offset, SEEK_SET) != -1)
ret = write (fd, buf, count);
G_UNLOCK (_sp_io_sync);
return ret;
#else
errno = 0;
return pwrite (fd, buf, count, offset);
#endif
}
ssize_t
_sp_write (int fd,
const void *buf,
size_t count)
{
#ifdef G_OS_WIN32
ssize_t ret = -1;
G_LOCK (_sp_io_sync);
errno = 0;
ret = write (fd, buf, count);
G_UNLOCK (_sp_io_sync);
return ret;
#else
errno = 0;
return write (fd, buf, count);
#endif
}
gint32
_sp_getpid (void)
{
#ifdef G_OS_WIN32
return _getpid ();
#else
return getpid ();
#endif
}
ssize_t
_sp_sendfile (int out_fd,
int in_fd,
off_t *offset,
size_t count)
{
ssize_t total = 0;
off_t wpos = 0;
off_t rpos = 0;
errno = 0;
if (offset != NULL && *offset > 0)
wpos = rpos = *offset;
while (count > 0)
{
unsigned char buf[4096*4];
ssize_t n_written = 0;
ssize_t n_read;
off_t off = 0;
size_t to_read;
/* Try to page align */
if ((rpos % 4096) != 0)
to_read = 4096 - rpos;
else
to_read = sizeof buf;
if (to_read > count)
to_read = count;
errno = 0;
n_read = _sp_pread (in_fd, buf, to_read, rpos);
if (n_read <= 0)
return -1;
g_assert (count >= n_read);
count -= n_read;
rpos += n_read;
while (wpos < rpos)
{
g_assert (off < sizeof buf);
errno = 0;
n_written = write (out_fd, &buf[off], rpos - wpos);
if (n_written <= 0)
return -1;
wpos += n_written;
off += n_written;
total += n_written;
}
}
g_assert (count == 0);
if (offset != NULL)
*offset = rpos;
errno = 0;
return total;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,134 @@
/* sp-capture-writer.h
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include "sp-capture-types.h"
G_BEGIN_DECLS
typedef struct _SpCaptureWriter SpCaptureWriter;
typedef struct
{
/*
* The number of frames indexed by SpCaptureFrameType
*/
gsize frame_count[16];
/*
* Padding for future expansion.
*/
gsize padding[48];
} SpCaptureStat;
SpCaptureWriter *sp_capture_writer_new_from_env (gsize buffer_size);
SpCaptureWriter *sp_capture_writer_new (const gchar *filename,
gsize buffer_size);
SpCaptureWriter *sp_capture_writer_new_from_fd (int fd,
gsize buffer_size);
SpCaptureWriter *sp_capture_writer_ref (SpCaptureWriter *self);
void sp_capture_writer_unref (SpCaptureWriter *self);
void sp_capture_writer_stat (SpCaptureWriter *self,
SpCaptureStat *stat);
gboolean sp_capture_writer_add_map (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
guint64 start,
guint64 end,
guint64 offset,
guint64 inode,
const gchar *filename);
gboolean sp_capture_writer_add_mark (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
guint64 duration,
const gchar *group,
const gchar *name,
const gchar *message);
guint64 sp_capture_writer_add_jitmap (SpCaptureWriter *self,
const gchar *name);
gboolean sp_capture_writer_add_process (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
const gchar *cmdline);
gboolean sp_capture_writer_add_sample (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
const SpCaptureAddress *addrs,
guint n_addrs);
gboolean sp_capture_writer_add_fork (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
gint32 child_pid);
gboolean sp_capture_writer_add_exit (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid);
gboolean sp_capture_writer_add_timestamp (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid);
gboolean sp_capture_writer_define_counters (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
const SpCaptureCounter *counters,
guint n_counters);
gboolean sp_capture_writer_set_counters (SpCaptureWriter *self,
gint64 time,
gint cpu,
gint32 pid,
const guint *counters_ids,
const SpCaptureCounterValue *values,
guint n_counters);
gboolean sp_capture_writer_flush (SpCaptureWriter *self);
gboolean sp_capture_writer_save_as (SpCaptureWriter *self,
const gchar *filename,
GError **error);
guint sp_capture_writer_request_counter (SpCaptureWriter *self,
guint n_counters);
SpCaptureReader *sp_capture_writer_create_reader (SpCaptureWriter *self,
GError **error);
gboolean sp_capture_writer_splice (SpCaptureWriter *self,
SpCaptureWriter *dest,
GError **error);
gboolean _sp_capture_writer_splice_from_fd (SpCaptureWriter *self,
int fd,
GError **error) G_GNUC_INTERNAL;
gboolean _sp_capture_writer_set_time_range (SpCaptureWriter *self,
gint64 start_time,
gint64 end_time) G_GNUC_INTERNAL;
#ifdef SP_ENABLE_GOBJECT
# define SP_TYPE_CAPTURE_WRITER (sp_capture_writer_get_type())
GType sp_capture_writer_get_type (void);
#endif
#if GLIB_CHECK_VERSION(2, 44, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SpCaptureWriter, sp_capture_writer_unref)
#endif
G_END_DECLS

View File

@ -0,0 +1,40 @@
/* sysprof-capture.h
*
* Copyright 2018-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#include <glib.h>
G_BEGIN_DECLS
#define SYSPROF_CAPTURE_INSIDE
# include "sp-address.h"
# include "sp-capture-condition.h"
# include "sp-capture-cursor.h"
# include "sp-capture-reader.h"
# include "sp-capture-writer.h"
# include "sp-clock.h"
# include "sp-error.h"
# include "sysprof-version.h"
#undef SYSPROF_CAPTURE_INSIDE
G_END_DECLS

View File

@ -0,0 +1,97 @@
/* sysprof-version.h.in
*
* Copyright 2016-2019 Christian Hergert <chergert@redhat.com>
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser 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
#if !defined(SYSPROF_CAPTURE_INSIDE) && !defined(SYSPROF_CAPTURE_COMPILATION)
# error "Only <sysprof-capture.h> can be included directly."
#endif
/**
* SECTION:sysprof-version
* @short_description: sysprof version checking
*
* sysprof provides macros to check the version of the library
* at compile-time
*/
/**
* SYSPROF_MAJOR_VERSION:
*
* sysprof major version component (e.g. 1 if %SYSPROF_VERSION is 1.2.3)
*/
#define SYSPROF_MAJOR_VERSION (@MAJOR_VERSION@)
/**
* SYSPROF_MINOR_VERSION:
*
* sysprof minor version component (e.g. 2 if %SYSPROF_VERSION is 1.2.3)
*/
#define SYSPROF_MINOR_VERSION (@MINOR_VERSION@)
/**
* SYSPROF_MICRO_VERSION:
*
* sysprof micro version component (e.g. 3 if %SYSPROF_VERSION is 1.2.3)
*/
#define SYSPROF_MICRO_VERSION (@MICRO_VERSION@)
/**
* SYSPROF_VERSION
*
* sysprof version.
*/
#define SYSPROF_VERSION (@VERSION@)
/**
* SYSPROF_VERSION_S:
*
* sysprof version, encoded as a string, useful for printing and
* concatenation.
*/
#define SYSPROF_VERSION_S "@VERSION@"
#define SYSPROF_ENCODE_VERSION(major,minor,micro) \
((major) << 24 | (minor) << 16 | (micro) << 8)
/**
* SYSPROF_VERSION_HEX:
*
* sysprof version, encoded as an hexadecimal number, useful for
* integer comparisons.
*/
#define SYSPROF_VERSION_HEX \
(SYSPROF_ENCODE_VERSION (SYSPROF_MAJOR_VERSION, SYSPROF_MINOR_VERSION, SYSPROF_MICRO_VERSION))
/**
* SYSPROF_CHECK_VERSION:
* @major: required major version
* @minor: required minor version
* @micro: required micro version
*
* Compile-time version checking. Evaluates to %TRUE if the version
* of sysprof is greater than the required one.
*/
#define SYSPROF_CHECK_VERSION(major,minor,micro) \
(SYSPROF_MAJOR_VERSION > (major) || \
(SYSPROF_MAJOR_VERSION == (major) && SYSPROF_MINOR_VERSION > (minor)) || \
(SYSPROF_MAJOR_VERSION == (major) && SYSPROF_MINOR_VERSION == (minor) && \
SYSPROF_MICRO_VERSION >= (micro)))