libsysprof-capture: Use C11 types instead of GLib types

This is an almost entirely mechanical* conversion from (for example)
`gint` → `int`, `guint8` → `uint8_t`, etc.

It is not entirely complete, as many GLib functions are still used in
libsysprof-capture, which necessitate some use of GLib types.

It also avoids renaming `gboolean` → `bool` as that’s a slightly more
controversial change which will happen in the following commit.

*Code was manually realigned afterwards.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-01 15:04:51 +01:00
parent b449baa205
commit 2c2cbf6343
22 changed files with 616 additions and 599 deletions

View File

@ -22,6 +22,7 @@
#include "config.h" #include "config.h"
#include <stdint.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -32,7 +33,7 @@
#include "mapped-ring-buffer.h" #include "mapped-ring-buffer.h"
#define DEFAULT_N_PAGES 32 #define DEFAULT_N_PAGES 32
#define BUFFER_MAX_SIZE ((G_MAXUINT32/2)-_sysprof_getpagesize()) #define BUFFER_MAX_SIZE ((UINT32_MAX/2)-_sysprof_getpagesize())
enum { enum {
MODE_READER = 1, MODE_READER = 1,
@ -47,10 +48,10 @@ enum {
*/ */
typedef struct _MappedRingHeader typedef struct _MappedRingHeader
{ {
guint32 head; uint32_t head;
guint32 tail; uint32_t tail;
guint32 offset; uint32_t offset;
guint32 size; uint32_t size;
} MappedRingHeader; } MappedRingHeader;
G_STATIC_ASSERT (sizeof (MappedRingHeader) == 16); G_STATIC_ASSERT (sizeof (MappedRingHeader) == 16);
@ -61,12 +62,12 @@ G_STATIC_ASSERT (sizeof (MappedRingHeader) == 16);
*/ */
struct _MappedRingBuffer struct _MappedRingBuffer
{ {
volatile gint ref_count; volatile int ref_count;
int mode; int mode;
int fd; int fd;
void *map; void *map;
gsize body_size; size_t body_size;
gsize page_size; size_t page_size;
}; };
static inline MappedRingHeader * static inline MappedRingHeader *
@ -75,19 +76,19 @@ get_header (MappedRingBuffer *self)
return (MappedRingHeader *)self->map; return (MappedRingHeader *)self->map;
} }
static inline gpointer static inline void *
get_body_at_pos (MappedRingBuffer *self, get_body_at_pos (MappedRingBuffer *self,
gsize pos) size_t pos)
{ {
g_assert (pos < (self->body_size + self->body_size)); g_assert (pos < (self->body_size + self->body_size));
return (guint8 *)self->map + self->page_size + pos; return (uint8_t *)self->map + self->page_size + pos;
} }
static gpointer static void *
map_head_and_body_twice (int fd, map_head_and_body_twice (int fd,
gsize head_size, size_t head_size,
gsize body_size) size_t body_size)
{ {
void *map; void *map;
void *second; void *second;
@ -118,7 +119,7 @@ map_head_and_body_twice (int fd,
* By mmap()'ing over the old region, the previous region is automatically * By mmap()'ing over the old region, the previous region is automatically
* munmap()'d for us. * munmap()'d for us.
*/ */
second = mmap ((guint8 *)map + head_size + body_size, second = mmap ((uint8_t *)map + head_size + body_size,
body_size, body_size,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED, MAP_SHARED | MAP_FIXED,
@ -131,7 +132,7 @@ map_head_and_body_twice (int fd,
return NULL; return NULL;
} }
g_assert (second == (gpointer)((guint8 *)map + head_size + body_size)); g_assert (second == (void *)((uint8_t *)map + head_size + body_size));
return map; return map;
} }
@ -157,11 +158,11 @@ map_head_and_body_twice (int fd,
* Returns: (transfer full): a #MappedRingBuffer * Returns: (transfer full): a #MappedRingBuffer
*/ */
MappedRingBuffer * MappedRingBuffer *
mapped_ring_buffer_new_reader (gsize buffer_size) mapped_ring_buffer_new_reader (size_t buffer_size)
{ {
MappedRingBuffer *self; MappedRingBuffer *self;
MappedRingHeader *header; MappedRingHeader *header;
gsize page_size; size_t page_size;
void *map; void *map;
int fd; int fd;
@ -212,7 +213,7 @@ mapped_ring_buffer_new_reader (gsize buffer_size)
} }
MappedRingBuffer * MappedRingBuffer *
mapped_ring_buffer_new_readwrite (gsize buffer_size) mapped_ring_buffer_new_readwrite (size_t buffer_size)
{ {
MappedRingBuffer *self; MappedRingBuffer *self;
@ -234,12 +235,12 @@ mapped_ring_buffer_new_readwrite (gsize buffer_size)
* Returns: (transfer full) (nullable): a new #MappedRingBuffer * Returns: (transfer full) (nullable): a new #MappedRingBuffer
*/ */
MappedRingBuffer * MappedRingBuffer *
mapped_ring_buffer_new_writer (gint fd) mapped_ring_buffer_new_writer (int fd)
{ {
MappedRingBuffer *self; MappedRingBuffer *self;
MappedRingHeader *header; MappedRingHeader *header;
gssize buffer_size; ssize_t buffer_size;
gsize page_size; size_t page_size;
void *map; void *map;
g_return_val_if_fail (fd > -1, NULL); g_return_val_if_fail (fd > -1, NULL);
@ -346,7 +347,7 @@ mapped_ring_buffer_ref (MappedRingBuffer *self)
return self; return self;
} }
gint int
mapped_ring_buffer_get_fd (MappedRingBuffer *self) mapped_ring_buffer_get_fd (MappedRingBuffer *self)
{ {
g_return_val_if_fail (self != NULL, -1); g_return_val_if_fail (self != NULL, -1);
@ -377,13 +378,13 @@ mapped_ring_buffer_get_fd (MappedRingBuffer *self)
* Returns: (nullable): a pointer to data of at least @length bytes * Returns: (nullable): a pointer to data of at least @length bytes
* or %NULL if there is not enough space. * or %NULL if there is not enough space.
*/ */
gpointer void *
mapped_ring_buffer_allocate (MappedRingBuffer *self, mapped_ring_buffer_allocate (MappedRingBuffer *self,
gsize length) size_t length)
{ {
MappedRingHeader *header; MappedRingHeader *header;
gsize headpos; uint32_t headpos;
gsize tailpos; uint32_t tailpos;
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->mode & MODE_WRITER, NULL); g_return_val_if_fail (self->mode & MODE_WRITER, NULL);
@ -436,10 +437,10 @@ mapped_ring_buffer_allocate (MappedRingBuffer *self,
*/ */
void void
mapped_ring_buffer_advance (MappedRingBuffer *self, mapped_ring_buffer_advance (MappedRingBuffer *self,
gsize length) size_t length)
{ {
MappedRingHeader *header; MappedRingHeader *header;
guint32 tail; uint32_t tail;
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
g_return_if_fail (self->mode & MODE_WRITER); g_return_if_fail (self->mode & MODE_WRITER);
@ -480,11 +481,11 @@ mapped_ring_buffer_advance (MappedRingBuffer *self,
gboolean gboolean
mapped_ring_buffer_drain (MappedRingBuffer *self, mapped_ring_buffer_drain (MappedRingBuffer *self,
MappedRingBufferCallback callback, MappedRingBufferCallback callback,
gpointer user_data) void *user_data)
{ {
MappedRingHeader *header; MappedRingHeader *header;
gsize headpos; uint32_t headpos;
gsize tailpos; uint32_t tailpos;
g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (self->mode & MODE_READER, FALSE); g_return_val_if_fail (self->mode & MODE_READER, FALSE);
@ -510,8 +511,8 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
while (headpos < tailpos) while (headpos < tailpos)
{ {
gconstpointer data = get_body_at_pos (self, headpos); const void *data = get_body_at_pos (self, headpos);
gsize len = tailpos - headpos; size_t len = tailpos - headpos;
if (!callback (data, &len, user_data)) if (!callback (data, &len, user_data))
return FALSE; return FALSE;
@ -545,7 +546,7 @@ gboolean
mapped_ring_buffer_is_empty (MappedRingBuffer *self) mapped_ring_buffer_is_empty (MappedRingBuffer *self)
{ {
MappedRingHeader *header; MappedRingHeader *header;
guint32 headpos, tailpos; uint32_t headpos, tailpos;
header = get_header (self); header = get_header (self);

View File

@ -21,6 +21,7 @@
#pragma once #pragma once
#include <glib.h> #include <glib.h>
#include <stddef.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -49,18 +50,18 @@ typedef struct _MappedRingBuffer MappedRingBuffer;
* *
* Returns: %TRUE to coninue draining, otherwise %FALSE and draining stops * Returns: %TRUE to coninue draining, otherwise %FALSE and draining stops
*/ */
typedef gboolean (*MappedRingBufferCallback) (gconstpointer data, typedef gboolean (*MappedRingBufferCallback) (const void *data,
gsize *length, size_t *length,
gpointer user_data); void *user_data);
G_GNUC_INTERNAL G_GNUC_INTERNAL
MappedRingBuffer *mapped_ring_buffer_new_reader (gsize buffer_size); MappedRingBuffer *mapped_ring_buffer_new_reader (size_t buffer_size);
G_GNUC_INTERNAL G_GNUC_INTERNAL
MappedRingBuffer *mapped_ring_buffer_new_readwrite (gsize buffer_size); MappedRingBuffer *mapped_ring_buffer_new_readwrite (size_t buffer_size);
G_GNUC_INTERNAL G_GNUC_INTERNAL
MappedRingBuffer *mapped_ring_buffer_new_writer (gint fd); MappedRingBuffer *mapped_ring_buffer_new_writer (int fd);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gint mapped_ring_buffer_get_fd (MappedRingBuffer *self); int mapped_ring_buffer_get_fd (MappedRingBuffer *self);
G_GNUC_INTERNAL G_GNUC_INTERNAL
MappedRingBuffer *mapped_ring_buffer_ref (MappedRingBuffer *self); MappedRingBuffer *mapped_ring_buffer_ref (MappedRingBuffer *self);
G_GNUC_INTERNAL G_GNUC_INTERNAL
@ -68,15 +69,15 @@ void mapped_ring_buffer_unref (MappedRingBuffer
G_GNUC_INTERNAL G_GNUC_INTERNAL
void mapped_ring_buffer_clear (MappedRingBuffer *self); void mapped_ring_buffer_clear (MappedRingBuffer *self);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gpointer mapped_ring_buffer_allocate (MappedRingBuffer *self, void *mapped_ring_buffer_allocate (MappedRingBuffer *self,
gsize length); size_t length);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void mapped_ring_buffer_advance (MappedRingBuffer *self, void mapped_ring_buffer_advance (MappedRingBuffer *self,
gsize length); size_t length);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean mapped_ring_buffer_drain (MappedRingBuffer *self, gboolean mapped_ring_buffer_drain (MappedRingBuffer *self,
MappedRingBufferCallback callback, MappedRingBufferCallback callback,
gpointer user_data); void *user_data);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean mapped_ring_buffer_is_empty (MappedRingBuffer *self); gboolean mapped_ring_buffer_is_empty (MappedRingBuffer *self);

View File

@ -105,7 +105,7 @@ sysprof_address_is_context_switch (SysprofAddress address,
} }
} }
const gchar * const char *
sysprof_address_context_to_string (SysprofAddressContext context) sysprof_address_context_to_string (SysprofAddressContext context)
{ {
switch (context) switch (context)

View File

@ -56,13 +56,15 @@
#pragma once #pragma once
#include <stdint.h>
#include "sysprof-version-macros.h" #include "sysprof-version-macros.h"
G_BEGIN_DECLS G_BEGIN_DECLS
typedef guint64 SysprofAddress; typedef uint64_t SysprofAddress;
G_STATIC_ASSERT (sizeof (SysprofAddress) >= sizeof (gpointer)); G_STATIC_ASSERT (sizeof (SysprofAddress) >= sizeof (void *));
typedef enum typedef enum
{ {
@ -79,9 +81,9 @@ SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_address_is_context_switch (SysprofAddress address, gboolean sysprof_address_is_context_switch (SysprofAddress address,
SysprofAddressContext *context); SysprofAddressContext *context);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
const gchar *sysprof_address_context_to_string (SysprofAddressContext context); const char *sysprof_address_context_to_string (SysprofAddressContext context);
static inline gint static inline int
sysprof_address_compare (SysprofAddress a, sysprof_address_compare (SysprofAddress a,
SysprofAddress b) SysprofAddress b)
{ {

View File

@ -86,13 +86,13 @@ typedef enum
struct _SysprofCaptureCondition struct _SysprofCaptureCondition
{ {
volatile gint ref_count; volatile int ref_count;
SysprofCaptureConditionType type; SysprofCaptureConditionType type;
union { union {
GArray *where_type_in; GArray *where_type_in;
struct { struct {
gint64 begin; int64_t begin;
gint64 end; int64_t end;
} where_time_between; } where_time_between;
GArray *where_pid_in; GArray *where_pid_in;
GArray *where_counter_in; GArray *where_counter_in;
@ -100,7 +100,7 @@ struct _SysprofCaptureCondition
SysprofCaptureCondition *left; SysprofCaptureCondition *left;
SysprofCaptureCondition *right; SysprofCaptureCondition *right;
} and, or; } and, or;
gchar *where_file; char *where_file;
} u; } u;
}; };
@ -122,7 +122,7 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
sysprof_capture_condition_match (self->u.or.right, frame); sysprof_capture_condition_match (self->u.or.right, frame);
case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN: case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN:
for (guint i = 0; i < self->u.where_type_in->len; i++) for (size_t i = 0; i < self->u.where_type_in->len; i++)
{ {
if (frame->type == g_array_index (self->u.where_type_in, SysprofCaptureFrameType, i)) if (frame->type == g_array_index (self->u.where_type_in, SysprofCaptureFrameType, i))
return TRUE; return TRUE;
@ -133,9 +133,9 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
return (frame->time >= self->u.where_time_between.begin && frame->time <= self->u.where_time_between.end); return (frame->time >= self->u.where_time_between.begin && frame->time <= self->u.where_time_between.end);
case SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN: case SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN:
for (guint i = 0; i < self->u.where_pid_in->len; i++) for (size_t i = 0; i < self->u.where_pid_in->len; i++)
{ {
if (frame->pid == g_array_index (self->u.where_pid_in, gint32, i)) if (frame->pid == g_array_index (self->u.where_pid_in, int32_t, i))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -145,11 +145,11 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
{ {
const SysprofCaptureCounterSet *set = (SysprofCaptureCounterSet *)frame; const SysprofCaptureCounterSet *set = (SysprofCaptureCounterSet *)frame;
for (guint i = 0; i < self->u.where_counter_in->len; i++) for (size_t i = 0; i < self->u.where_counter_in->len; i++)
{ {
guint counter = g_array_index (self->u.where_counter_in, guint, i); unsigned int counter = g_array_index (self->u.where_counter_in, unsigned int, i);
for (guint j = 0; j < set->n_values; j++) for (unsigned int j = 0; j < set->n_values; j++)
{ {
if (counter == set->values[j].ids[0] || if (counter == set->values[j].ids[0] ||
counter == set->values[j].ids[1] || counter == set->values[j].ids[1] ||
@ -167,11 +167,11 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
{ {
const SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; const SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame;
for (guint i = 0; i < self->u.where_counter_in->len; i++) for (size_t i = 0; i < self->u.where_counter_in->len; i++)
{ {
guint counter = g_array_index (self->u.where_counter_in, guint, i); unsigned int counter = g_array_index (self->u.where_counter_in, unsigned int, i);
for (guint j = 0; j < def->n_counters; j++) for (unsigned int j = 0; j < def->n_counters; j++)
{ {
if (def->counters[j].id == counter) if (def->counters[j].id == counter)
return TRUE; return TRUE;
@ -225,7 +225,7 @@ sysprof_capture_condition_copy (const SysprofCaptureCondition *self)
case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN: case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN:
return sysprof_capture_condition_new_where_type_in ( return sysprof_capture_condition_new_where_type_in (
self->u.where_type_in->len, self->u.where_type_in->len,
(const SysprofCaptureFrameType *)(gpointer)self->u.where_type_in->data); (const SysprofCaptureFrameType *)(void *)self->u.where_type_in->data);
case SYSPROF_CAPTURE_CONDITION_WHERE_TIME_BETWEEN: case SYSPROF_CAPTURE_CONDITION_WHERE_TIME_BETWEEN:
return sysprof_capture_condition_new_where_time_between ( return sysprof_capture_condition_new_where_time_between (
@ -235,12 +235,12 @@ sysprof_capture_condition_copy (const SysprofCaptureCondition *self)
case SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN: case SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN:
return sysprof_capture_condition_new_where_pid_in ( return sysprof_capture_condition_new_where_pid_in (
self->u.where_pid_in->len, self->u.where_pid_in->len,
(const gint32 *)(gpointer)self->u.where_pid_in->data); (const int32_t *)(void *)self->u.where_pid_in->data);
case SYSPROF_CAPTURE_CONDITION_WHERE_COUNTER_IN: case SYSPROF_CAPTURE_CONDITION_WHERE_COUNTER_IN:
return sysprof_capture_condition_new_where_counter_in ( return sysprof_capture_condition_new_where_counter_in (
self->u.where_counter_in->len, self->u.where_counter_in->len,
(const guint *)(gpointer)self->u.where_counter_in->data); (const unsigned int *)(void *)self->u.where_counter_in->data);
case SYSPROF_CAPTURE_CONDITION_WHERE_FILE: case SYSPROF_CAPTURE_CONDITION_WHERE_FILE:
return sysprof_capture_condition_new_where_file (self->u.where_file); return sysprof_capture_condition_new_where_file (self->u.where_file);
@ -315,7 +315,7 @@ sysprof_capture_condition_unref (SysprofCaptureCondition *self)
} }
SysprofCaptureCondition * SysprofCaptureCondition *
sysprof_capture_condition_new_where_type_in (guint n_types, sysprof_capture_condition_new_where_type_in (unsigned int n_types,
const SysprofCaptureFrameType *types) const SysprofCaptureFrameType *types)
{ {
SysprofCaptureCondition *self; SysprofCaptureCondition *self;
@ -332,14 +332,14 @@ sysprof_capture_condition_new_where_type_in (guint n_types,
} }
SysprofCaptureCondition * SysprofCaptureCondition *
sysprof_capture_condition_new_where_time_between (gint64 begin_time, sysprof_capture_condition_new_where_time_between (int64_t begin_time,
gint64 end_time) int64_t end_time)
{ {
SysprofCaptureCondition *self; SysprofCaptureCondition *self;
if G_UNLIKELY (begin_time > end_time) if G_UNLIKELY (begin_time > end_time)
{ {
gint64 tmp = begin_time; int64_t tmp = begin_time;
begin_time = end_time; begin_time = end_time;
end_time = tmp; end_time = tmp;
} }
@ -353,8 +353,8 @@ sysprof_capture_condition_new_where_time_between (gint64 begin_time,
} }
SysprofCaptureCondition * SysprofCaptureCondition *
sysprof_capture_condition_new_where_pid_in (guint n_pids, sysprof_capture_condition_new_where_pid_in (unsigned int n_pids,
const gint32 *pids) const int32_t *pids)
{ {
SysprofCaptureCondition *self; SysprofCaptureCondition *self;
@ -362,16 +362,16 @@ sysprof_capture_condition_new_where_pid_in (guint n_pids,
self = sysprof_capture_condition_init (); self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN; self->type = SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN;
self->u.where_pid_in = g_array_sized_new (FALSE, FALSE, sizeof (gint32), n_pids); self->u.where_pid_in = g_array_sized_new (FALSE, FALSE, sizeof (int32_t), n_pids);
g_array_set_size (self->u.where_pid_in, 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); memcpy (self->u.where_pid_in->data, pids, sizeof (int32_t) * n_pids);
return self; return self;
} }
SysprofCaptureCondition * SysprofCaptureCondition *
sysprof_capture_condition_new_where_counter_in (guint n_counters, sysprof_capture_condition_new_where_counter_in (unsigned int n_counters,
const guint *counters) const unsigned int *counters)
{ {
SysprofCaptureCondition *self; SysprofCaptureCondition *self;
@ -379,12 +379,12 @@ sysprof_capture_condition_new_where_counter_in (guint n_counters,
self = sysprof_capture_condition_init (); self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_COUNTER_IN; self->type = SYSPROF_CAPTURE_CONDITION_WHERE_COUNTER_IN;
self->u.where_counter_in = g_array_sized_new (FALSE, FALSE, sizeof (guint), n_counters); self->u.where_counter_in = g_array_sized_new (FALSE, FALSE, sizeof (unsigned int), n_counters);
if (n_counters > 0) if (n_counters > 0)
{ {
g_array_set_size (self->u.where_counter_in, n_counters); g_array_set_size (self->u.where_counter_in, n_counters);
memcpy (self->u.where_counter_in->data, counters, sizeof (guint) * n_counters); memcpy (self->u.where_counter_in->data, counters, sizeof (unsigned int) * n_counters);
} }
return self; return self;
@ -454,7 +454,7 @@ sysprof_capture_condition_new_or (SysprofCaptureCondition *left,
* Returns: (transfer full): a new #SysprofCaptureCondition * Returns: (transfer full): a new #SysprofCaptureCondition
*/ */
SysprofCaptureCondition * SysprofCaptureCondition *
sysprof_capture_condition_new_where_file (const gchar *path) sysprof_capture_condition_new_where_file (const char *path)
{ {
SysprofCaptureCondition *self; SysprofCaptureCondition *self;

View File

@ -74,19 +74,19 @@ SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_or (SysprofCaptureCondition *left, SysprofCaptureCondition *sysprof_capture_condition_new_or (SysprofCaptureCondition *left,
SysprofCaptureCondition *right); SysprofCaptureCondition *right);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_where_type_in (guint n_types, SysprofCaptureCondition *sysprof_capture_condition_new_where_type_in (unsigned int n_types,
const SysprofCaptureFrameType *types); const SysprofCaptureFrameType *types);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_where_time_between (gint64 begin_time, SysprofCaptureCondition *sysprof_capture_condition_new_where_time_between (int64_t begin_time,
gint64 end_time); int64_t end_time);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_where_pid_in (guint n_pids, SysprofCaptureCondition *sysprof_capture_condition_new_where_pid_in (unsigned int n_pids,
const gint32 *pids); const int32_t *pids);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_where_counter_in (guint n_counters, SysprofCaptureCondition *sysprof_capture_condition_new_where_counter_in (unsigned int n_counters,
const guint *counters); const unsigned int *counters);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCondition *sysprof_capture_condition_new_where_file (const gchar *path); SysprofCaptureCondition *sysprof_capture_condition_new_where_file (const char *path);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_condition_match (const SysprofCaptureCondition *self, gboolean sysprof_capture_condition_match (const SysprofCaptureCondition *self,
const SysprofCaptureFrame *frame); const SysprofCaptureFrame *frame);

View File

@ -68,10 +68,10 @@ typedef const SysprofCaptureFrame *(*ReadDelegate) (SysprofCaptureReader *);
struct _SysprofCaptureCursor struct _SysprofCaptureCursor
{ {
volatile gint ref_count; volatile int ref_count;
GPtrArray *conditions; GPtrArray *conditions;
SysprofCaptureReader *reader; SysprofCaptureReader *reader;
guint reversed : 1; unsigned int reversed : 1;
}; };
static void static void
@ -138,7 +138,7 @@ sysprof_capture_cursor_unref (SysprofCaptureCursor *self)
void void
sysprof_capture_cursor_foreach (SysprofCaptureCursor *self, sysprof_capture_cursor_foreach (SysprofCaptureCursor *self,
SysprofCaptureCursorCallback callback, SysprofCaptureCursorCallback callback,
gpointer user_data) void *user_data)
{ {
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
g_return_if_fail (self->reader != NULL); g_return_if_fail (self->reader != NULL);
@ -231,7 +231,7 @@ sysprof_capture_cursor_foreach (SysprofCaptureCursor *self,
} }
else else
{ {
for (guint i = 0; i < self->conditions->len; i++) for (size_t i = 0; i < self->conditions->len; i++)
{ {
const SysprofCaptureCondition *condition = g_ptr_array_index (self->conditions, i); const SysprofCaptureCondition *condition = g_ptr_array_index (self->conditions, i);

View File

@ -75,7 +75,7 @@ typedef struct _SysprofCaptureCursor SysprofCaptureCursor;
* Returns: %TRUE if iteration should continue, otherwise %FALSE. * Returns: %TRUE if iteration should continue, otherwise %FALSE.
*/ */
typedef gboolean (*SysprofCaptureCursorCallback) (const SysprofCaptureFrame *frame, typedef gboolean (*SysprofCaptureCursorCallback) (const SysprofCaptureFrame *frame,
gpointer user_data); void *user_data);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureCursor *sysprof_capture_cursor_new (SysprofCaptureReader *reader); SysprofCaptureCursor *sysprof_capture_cursor_new (SysprofCaptureReader *reader);
@ -88,7 +88,7 @@ SysprofCaptureReader *sysprof_capture_cursor_get_reader (SysprofCaptureCursor
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_capture_cursor_foreach (SysprofCaptureCursor *self, void sysprof_capture_cursor_foreach (SysprofCaptureCursor *self,
SysprofCaptureCursorCallback callback, SysprofCaptureCursorCallback callback,
gpointer user_data); void *user_data);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_capture_cursor_reset (SysprofCaptureCursor *self); void sysprof_capture_cursor_reset (SysprofCaptureCursor *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL

View File

@ -60,6 +60,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -71,19 +72,19 @@
struct _SysprofCaptureReader struct _SysprofCaptureReader
{ {
volatile gint ref_count; volatile int ref_count;
gchar *filename; char *filename;
guint8 *buf; uint8_t *buf;
gsize bufsz; size_t bufsz;
gsize len; size_t len;
gsize pos; size_t pos;
gsize fd_off; size_t fd_off;
int fd; int fd;
gint endian; int endian;
SysprofCaptureFileHeader header; SysprofCaptureFileHeader header;
gint64 end_time; int64_t end_time;
SysprofCaptureStat st_buf; SysprofCaptureStat st_buf;
guint st_buf_set : 1; unsigned int st_buf_set : 1;
}; };
static gboolean static gboolean
@ -129,7 +130,7 @@ sysprof_capture_reader_finalize (SysprofCaptureReader *self)
} }
} }
const gchar * const char *
sysprof_capture_reader_get_time (SysprofCaptureReader *self) sysprof_capture_reader_get_time (SysprofCaptureReader *self)
{ {
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
@ -137,7 +138,7 @@ sysprof_capture_reader_get_time (SysprofCaptureReader *self)
return self->header.capture_time; return self->header.capture_time;
} }
const gchar * const char *
sysprof_capture_reader_get_filename (SysprofCaptureReader *self) sysprof_capture_reader_get_filename (SysprofCaptureReader *self)
{ {
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
@ -154,7 +155,7 @@ sysprof_capture_reader_discover_end_time (SysprofCaptureReader *self)
while (sysprof_capture_reader_peek_frame (self, &frame)) while (sysprof_capture_reader_peek_frame (self, &frame))
{ {
gint64 end_time = frame.time; int64_t end_time = frame.time;
switch (frame.type) switch (frame.type)
{ {
@ -215,7 +216,7 @@ sysprof_capture_reader_new_from_fd (int fd,
self = g_new0 (SysprofCaptureReader, 1); self = g_new0 (SysprofCaptureReader, 1);
self->ref_count = 1; self->ref_count = 1;
self->bufsz = G_MAXUSHORT * 2; self->bufsz = USHRT_MAX * 2;
self->buf = g_malloc (self->bufsz); self->buf = g_malloc (self->bufsz);
self->len = 0; self->len = 0;
self->pos = 0; self->pos = 0;
@ -244,7 +245,7 @@ sysprof_capture_reader_new_from_fd (int fd,
} }
SysprofCaptureReader * SysprofCaptureReader *
sysprof_capture_reader_new (const gchar *filename, sysprof_capture_reader_new (const char *filename,
GError **error) GError **error)
{ {
SysprofCaptureReader *self; SysprofCaptureReader *self;
@ -350,7 +351,7 @@ sysprof_capture_reader_bswap_jitmap (SysprofCaptureReader *self,
static gboolean static gboolean
sysprof_capture_reader_ensure_space_for (SysprofCaptureReader *self, sysprof_capture_reader_ensure_space_for (SysprofCaptureReader *self,
gsize len) size_t len)
{ {
g_assert (self != NULL); g_assert (self != NULL);
g_assert (self->pos <= self->len); g_assert (self->pos <= self->len);
@ -361,7 +362,7 @@ sysprof_capture_reader_ensure_space_for (SysprofCaptureReader *self,
if ((self->len - self->pos) < len) if ((self->len - self->pos) < len)
{ {
gssize r; ssize_t r;
if (self->len > self->pos) if (self->len > self->pos)
memmove (self->buf, &self->buf[self->pos], self->len - self->pos); memmove (self->buf, &self->buf[self->pos], self->len - self->pos);
@ -401,7 +402,7 @@ sysprof_capture_reader_skip (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof (SysprofCaptureFrame))) if (!sysprof_capture_reader_ensure_space_for (self, sizeof (SysprofCaptureFrame)))
return FALSE; return FALSE;
frame = (SysprofCaptureFrame *)(gpointer)&self->buf[self->pos]; frame = (SysprofCaptureFrame *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, frame); sysprof_capture_reader_bswap_frame (self, frame);
if (frame->len < sizeof (SysprofCaptureFrame)) if (frame->len < sizeof (SysprofCaptureFrame))
@ -410,7 +411,7 @@ sysprof_capture_reader_skip (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, frame->len)) if (!sysprof_capture_reader_ensure_space_for (self, frame->len))
return FALSE; return FALSE;
frame = (SysprofCaptureFrame *)(gpointer)&self->buf[self->pos]; frame = (SysprofCaptureFrame *)(void *)&self->buf[self->pos];
self->pos += frame->len; self->pos += frame->len;
@ -436,7 +437,7 @@ sysprof_capture_reader_peek_frame (SysprofCaptureReader *self,
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0); g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
real_frame = (SysprofCaptureFrame *)(gpointer)&self->buf[self->pos]; real_frame = (SysprofCaptureFrame *)(void *)&self->buf[self->pos];
*frame = *real_frame; *frame = *real_frame;
@ -472,10 +473,10 @@ sysprof_capture_reader_peek_type (SysprofCaptureReader *self,
static const SysprofCaptureFrame * static const SysprofCaptureFrame *
sysprof_capture_reader_read_basic (SysprofCaptureReader *self, sysprof_capture_reader_read_basic (SysprofCaptureReader *self,
SysprofCaptureFrameType type, SysprofCaptureFrameType type,
gsize extra) size_t extra)
{ {
SysprofCaptureFrame *frame; SysprofCaptureFrame *frame;
gsize len = sizeof *frame + extra; size_t len = sizeof *frame + extra;
g_assert (self != NULL); g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0); g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
@ -484,7 +485,7 @@ sysprof_capture_reader_read_basic (SysprofCaptureReader *self,
if (!sysprof_capture_reader_ensure_space_for (self, len)) if (!sysprof_capture_reader_ensure_space_for (self, len))
return NULL; return NULL;
frame = (SysprofCaptureFrame *)(gpointer)&self->buf[self->pos]; frame = (SysprofCaptureFrame *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, frame); sysprof_capture_reader_bswap_frame (self, frame);
@ -524,7 +525,7 @@ sysprof_capture_reader_read_fork (SysprofCaptureReader *self)
g_assert (self != NULL); g_assert (self != NULL);
fk = (SysprofCaptureFork *) fk = (SysprofCaptureFork *)
sysprof_capture_reader_read_basic (self, SYSPROF_CAPTURE_FRAME_FORK, sizeof(guint32)); sysprof_capture_reader_read_basic (self, SYSPROF_CAPTURE_FRAME_FORK, sizeof (uint32_t));
if (fk != NULL) if (fk != NULL)
{ {
@ -547,7 +548,7 @@ sysprof_capture_reader_read_map (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *map)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *map))
return NULL; return NULL;
map = (SysprofCaptureMap *)(gpointer)&self->buf[self->pos]; map = (SysprofCaptureMap *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &map->frame); sysprof_capture_reader_bswap_frame (self, &map->frame);
@ -560,7 +561,7 @@ sysprof_capture_reader_read_map (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, map->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, map->frame.len))
return NULL; return NULL;
map = (SysprofCaptureMap *)(gpointer)&self->buf[self->pos]; map = (SysprofCaptureMap *)(void *)&self->buf[self->pos];
if (self->buf[self->pos + map->frame.len - 1] != '\0') if (self->buf[self->pos + map->frame.len - 1] != '\0')
return NULL; return NULL;
@ -587,7 +588,7 @@ sysprof_capture_reader_read_log (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *log)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *log))
return NULL; return NULL;
log = (SysprofCaptureLog *)(gpointer)&self->buf[self->pos]; log = (SysprofCaptureLog *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &log->frame); sysprof_capture_reader_bswap_frame (self, &log->frame);
@ -600,7 +601,7 @@ sysprof_capture_reader_read_log (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, log->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, log->frame.len))
return NULL; return NULL;
log = (SysprofCaptureLog *)(gpointer)&self->buf[self->pos]; log = (SysprofCaptureLog *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_log (self, log); sysprof_capture_reader_bswap_log (self, log);
@ -612,7 +613,7 @@ sysprof_capture_reader_read_log (SysprofCaptureReader *self)
/* Ensure trailing \0 in domain and message */ /* Ensure trailing \0 in domain and message */
log->domain[sizeof log->domain - 1] = 0; log->domain[sizeof log->domain - 1] = 0;
if (log->frame.len > sizeof *log) if (log->frame.len > sizeof *log)
((gchar *)log)[log->frame.len - 1] = 0; ((char *)log)[log->frame.len - 1] = 0;
return log; return log;
} }
@ -629,7 +630,7 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *mark)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *mark))
return NULL; return NULL;
mark = (SysprofCaptureMark *)(gpointer)&self->buf[self->pos]; mark = (SysprofCaptureMark *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &mark->frame); sysprof_capture_reader_bswap_frame (self, &mark->frame);
@ -642,7 +643,7 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, mark->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, mark->frame.len))
return NULL; return NULL;
mark = (SysprofCaptureMark *)(gpointer)&self->buf[self->pos]; mark = (SysprofCaptureMark *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_mark (self, mark); sysprof_capture_reader_bswap_mark (self, mark);
@ -654,7 +655,7 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
/* Ensure trailing \0 in name and message */ /* Ensure trailing \0 in name and message */
mark->name[sizeof mark->name - 1] = 0; mark->name[sizeof mark->name - 1] = 0;
if (mark->frame.len > sizeof *mark) if (mark->frame.len > sizeof *mark)
((gchar *)mark)[mark->frame.len - 1] = 0; ((char *)mark)[mark->frame.len - 1] = 0;
/* Maybe update end-time */ /* Maybe update end-time */
if G_UNLIKELY ((mark->frame.time + mark->duration) > self->end_time) if G_UNLIKELY ((mark->frame.time + mark->duration) > self->end_time)
@ -675,7 +676,7 @@ sysprof_capture_reader_read_metadata (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *metadata)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *metadata))
return NULL; return NULL;
metadata = (SysprofCaptureMetadata *)(gpointer)&self->buf[self->pos]; metadata = (SysprofCaptureMetadata *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &metadata->frame); sysprof_capture_reader_bswap_frame (self, &metadata->frame);
@ -688,7 +689,7 @@ sysprof_capture_reader_read_metadata (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, metadata->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, metadata->frame.len))
return NULL; return NULL;
metadata = (SysprofCaptureMetadata *)(gpointer)&self->buf[self->pos]; metadata = (SysprofCaptureMetadata *)(void *)&self->buf[self->pos];
self->pos += metadata->frame.len; self->pos += metadata->frame.len;
@ -698,7 +699,7 @@ sysprof_capture_reader_read_metadata (SysprofCaptureReader *self)
/* Ensure trailing \0 in .id and .metadata */ /* Ensure trailing \0 in .id and .metadata */
metadata->id[sizeof metadata->id - 1] = 0; metadata->id[sizeof metadata->id - 1] = 0;
if (metadata->frame.len > sizeof *metadata) if (metadata->frame.len > sizeof *metadata)
((gchar *)metadata)[metadata->frame.len - 1] = 0; ((char *)metadata)[metadata->frame.len - 1] = 0;
return metadata; return metadata;
} }
@ -715,7 +716,7 @@ sysprof_capture_reader_read_process (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *process)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *process))
return NULL; return NULL;
process = (SysprofCaptureProcess *)(gpointer)&self->buf[self->pos]; process = (SysprofCaptureProcess *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &process->frame); sysprof_capture_reader_bswap_frame (self, &process->frame);
@ -728,7 +729,7 @@ sysprof_capture_reader_read_process (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, process->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, process->frame.len))
return NULL; return NULL;
process = (SysprofCaptureProcess *)(gpointer)&self->buf[self->pos]; process = (SysprofCaptureProcess *)(void *)&self->buf[self->pos];
if (self->buf[self->pos + process->frame.len - 1] != '\0') if (self->buf[self->pos + process->frame.len - 1] != '\0')
return NULL; return NULL;
@ -746,9 +747,9 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
{ {
g_autoptr(GHashTable) ret = NULL; g_autoptr(GHashTable) ret = NULL;
SysprofCaptureJitmap *jitmap; SysprofCaptureJitmap *jitmap;
guint8 *buf; uint8_t *buf;
guint8 *endptr; uint8_t *endptr;
guint i; unsigned int i;
g_assert (self != NULL); g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0); g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
@ -757,7 +758,7 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *jitmap)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *jitmap))
return NULL; return NULL;
jitmap = (SysprofCaptureJitmap *)(gpointer)&self->buf[self->pos]; jitmap = (SysprofCaptureJitmap *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &jitmap->frame); sysprof_capture_reader_bswap_frame (self, &jitmap->frame);
@ -780,7 +781,7 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
for (i = 0; i < jitmap->n_jitmaps; i++) for (i = 0; i < jitmap->n_jitmaps; i++)
{ {
SysprofCaptureAddress addr; SysprofCaptureAddress addr;
const gchar *str; const char *str;
if (buf + sizeof addr >= endptr) if (buf + sizeof addr >= endptr)
return NULL; return NULL;
@ -788,7 +789,7 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
memcpy (&addr, buf, sizeof addr); memcpy (&addr, buf, sizeof addr);
buf += sizeof addr; buf += sizeof addr;
str = (gchar *)buf; str = (char *)buf;
buf = memchr (buf, '\0', (endptr - buf)); buf = memchr (buf, '\0', (endptr - buf));
@ -819,7 +820,7 @@ sysprof_capture_reader_read_sample (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *sample)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *sample))
return NULL; return NULL;
sample = (SysprofCaptureSample *)(gpointer)&self->buf[self->pos]; sample = (SysprofCaptureSample *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &sample->frame); sysprof_capture_reader_bswap_frame (self, &sample->frame);
@ -838,11 +839,11 @@ sysprof_capture_reader_read_sample (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sample->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, sample->frame.len))
return NULL; return NULL;
sample = (SysprofCaptureSample *)(gpointer)&self->buf[self->pos]; sample = (SysprofCaptureSample *)(void *)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER)) if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{ {
guint i; unsigned int i;
for (i = 0; i < sample->n_addrs; i++) for (i = 0; i < sample->n_addrs; i++)
sample->addrs[i] = GUINT64_SWAP_LE_BE (sample->addrs[i]); sample->addrs[i] = GUINT64_SWAP_LE_BE (sample->addrs[i]);
@ -865,7 +866,7 @@ sysprof_capture_reader_read_counter_define (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *def)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *def))
return NULL; return NULL;
def = (SysprofCaptureCounterDefine *)(gpointer)&self->buf[self->pos]; def = (SysprofCaptureCounterDefine *)(void *)&self->buf[self->pos];
if (def->frame.type != SYSPROF_CAPTURE_FRAME_CTRDEF) if (def->frame.type != SYSPROF_CAPTURE_FRAME_CTRDEF)
return NULL; return NULL;
@ -882,11 +883,11 @@ sysprof_capture_reader_read_counter_define (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, def->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, def->frame.len))
return NULL; return NULL;
def = (SysprofCaptureCounterDefine *)(gpointer)&self->buf[self->pos]; def = (SysprofCaptureCounterDefine *)(void *)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER)) if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{ {
guint i; unsigned int i;
for (i = 0; i < def->n_counters; i++) for (i = 0; i < def->n_counters; i++)
{ {
@ -912,7 +913,7 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *set)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *set))
return NULL; return NULL;
set = (SysprofCaptureCounterSet *)(gpointer)&self->buf[self->pos]; set = (SysprofCaptureCounterSet *)(void *)&self->buf[self->pos];
if (set->frame.type != SYSPROF_CAPTURE_FRAME_CTRSET) if (set->frame.type != SYSPROF_CAPTURE_FRAME_CTRSET)
return NULL; return NULL;
@ -929,15 +930,15 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, set->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, set->frame.len))
return NULL; return NULL;
set = (SysprofCaptureCounterSet *)(gpointer)&self->buf[self->pos]; set = (SysprofCaptureCounterSet *)(void *)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER)) if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{ {
guint i; unsigned int i;
for (i = 0; i < set->n_values; i++) for (i = 0; i < set->n_values; i++)
{ {
guint j; unsigned int j;
for (j = 0; j < G_N_ELEMENTS (set->values[0].values); j++) for (j = 0; j < G_N_ELEMENTS (set->values[0].values); j++)
{ {
@ -1026,12 +1027,12 @@ sysprof_capture_reader_splice (SysprofCaptureReader *self,
*/ */
gboolean gboolean
sysprof_capture_reader_save_as (SysprofCaptureReader *self, sysprof_capture_reader_save_as (SysprofCaptureReader *self,
const gchar *filename, const char *filename,
GError **error) GError **error)
{ {
struct stat stbuf; struct stat stbuf;
off_t in_off; off_t in_off;
gsize to_write; size_t to_write;
int fd = -1; int fd = -1;
g_assert (self != NULL); g_assert (self != NULL);
@ -1054,7 +1055,7 @@ sysprof_capture_reader_save_as (SysprofCaptureReader *self,
while (to_write > 0) while (to_write > 0)
{ {
gssize written; ssize_t written;
written = _sysprof_sendfile (fd, self->fd, &in_off, to_write); written = _sysprof_sendfile (fd, self->fd, &in_off, to_write);
@ -1064,7 +1065,7 @@ sysprof_capture_reader_save_as (SysprofCaptureReader *self,
if (written == 0 && errno != EAGAIN) if (written == 0 && errno != EAGAIN)
goto handle_errno; goto handle_errno;
g_assert (written <= (gssize)to_write); g_assert (written <= (ssize_t)to_write);
to_write -= written; to_write -= written;
} }
@ -1088,7 +1089,7 @@ handle_errno:
return FALSE; return FALSE;
} }
gint64 int64_t
sysprof_capture_reader_get_start_time (SysprofCaptureReader *self) sysprof_capture_reader_get_start_time (SysprofCaptureReader *self)
{ {
g_return_val_if_fail (self != NULL, 0); g_return_val_if_fail (self != NULL, 0);
@ -1114,10 +1115,10 @@ sysprof_capture_reader_get_start_time (SysprofCaptureReader *self)
* *
* Since: 3.22.1 * Since: 3.22.1
*/ */
gint64 int64_t
sysprof_capture_reader_get_end_time (SysprofCaptureReader *self) sysprof_capture_reader_get_end_time (SysprofCaptureReader *self)
{ {
gint64 end_time = 0; int64_t end_time = 0;
g_return_val_if_fail (self != NULL, 0); g_return_val_if_fail (self != NULL, 0);
@ -1212,7 +1213,7 @@ sysprof_capture_reader_read_file (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *file_chunk)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *file_chunk))
return NULL; return NULL;
file_chunk = (SysprofCaptureFileChunk *)(gpointer)&self->buf[self->pos]; file_chunk = (SysprofCaptureFileChunk *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &file_chunk->frame); sysprof_capture_reader_bswap_frame (self, &file_chunk->frame);
@ -1225,7 +1226,7 @@ sysprof_capture_reader_read_file (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, file_chunk->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, file_chunk->frame.len))
return NULL; return NULL;
file_chunk = (SysprofCaptureFileChunk *)(gpointer)&self->buf[self->pos]; file_chunk = (SysprofCaptureFileChunk *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_file_chunk (self, file_chunk); sysprof_capture_reader_bswap_file_chunk (self, file_chunk);
@ -1244,7 +1245,7 @@ sysprof_capture_reader_read_file (SysprofCaptureReader *self)
return file_chunk; return file_chunk;
} }
gchar ** char **
sysprof_capture_reader_list_files (SysprofCaptureReader *self) sysprof_capture_reader_list_files (SysprofCaptureReader *self)
{ {
g_autoptr(GHashTable) files = NULL; g_autoptr(GHashTable) files = NULL;
@ -1280,13 +1281,13 @@ sysprof_capture_reader_list_files (SysprofCaptureReader *self)
g_ptr_array_add (ar, g_strdup (key)); g_ptr_array_add (ar, g_strdup (key));
g_ptr_array_add (ar, NULL); g_ptr_array_add (ar, NULL);
return (gchar **)g_ptr_array_free (g_steal_pointer (&ar), FALSE); return (char **)g_ptr_array_free (g_steal_pointer (&ar), FALSE);
} }
gboolean gboolean
sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self, sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
const gchar *path, const char *path,
gint fd) int fd)
{ {
g_assert (self != NULL); g_assert (self != NULL);
g_assert (path != NULL); g_assert (path != NULL);
@ -1296,8 +1297,8 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
{ {
SysprofCaptureFrameType type; SysprofCaptureFrameType type;
const SysprofCaptureFileChunk *file; const SysprofCaptureFileChunk *file;
const guint8 *buf; const uint8_t *buf;
gsize to_write; size_t to_write;
if (!sysprof_capture_reader_peek_type (self, &type)) if (!sysprof_capture_reader_peek_type (self, &type))
return FALSE; return FALSE;
@ -1316,7 +1317,7 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
while (to_write > 0) while (to_write > 0)
{ {
gssize written; ssize_t written;
written = _sysprof_write (fd, buf, to_write); written = _sysprof_write (fd, buf, to_write);
if (written < 0) if (written < 0)
@ -1325,7 +1326,7 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
if (written == 0 && errno != EAGAIN) if (written == 0 && errno != EAGAIN)
return FALSE; return FALSE;
g_assert (written <= (gssize)to_write); g_assert (written <= (ssize_t)to_write);
buf += written; buf += written;
to_write -= written; to_write -= written;
@ -1344,7 +1345,7 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
} }
gint int
sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self) sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self)
{ {
g_return_val_if_fail (self != NULL, 0); g_return_val_if_fail (self != NULL, 0);
@ -1354,7 +1355,7 @@ sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self)
const SysprofCaptureFileChunk * const SysprofCaptureFileChunk *
sysprof_capture_reader_find_file (SysprofCaptureReader *self, sysprof_capture_reader_find_file (SysprofCaptureReader *self,
const gchar *path) const char *path)
{ {
SysprofCaptureFrameType type; SysprofCaptureFrameType type;
@ -1395,7 +1396,7 @@ sysprof_capture_reader_read_allocation (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *ma)) if (!sysprof_capture_reader_ensure_space_for (self, sizeof *ma))
return NULL; return NULL;
ma = (SysprofCaptureAllocation *)(gpointer)&self->buf[self->pos]; ma = (SysprofCaptureAllocation *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &ma->frame); sysprof_capture_reader_bswap_frame (self, &ma->frame);
@ -1419,11 +1420,11 @@ sysprof_capture_reader_read_allocation (SysprofCaptureReader *self)
if (!sysprof_capture_reader_ensure_space_for (self, ma->frame.len)) if (!sysprof_capture_reader_ensure_space_for (self, ma->frame.len))
return NULL; return NULL;
ma = (SysprofCaptureAllocation *)(gpointer)&self->buf[self->pos]; ma = (SysprofCaptureAllocation *)(void *)&self->buf[self->pos];
if (G_UNLIKELY (self->endian != G_BYTE_ORDER)) if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{ {
for (guint i = 0; i < ma->n_addrs; i++) for (unsigned int i = 0; i < ma->n_addrs; i++)
ma->addrs[i] = GUINT64_SWAP_LE_BE (ma->addrs[i]); ma->addrs[i] = GUINT64_SWAP_LE_BE (ma->addrs[i]);
} }

View File

@ -64,7 +64,7 @@ G_BEGIN_DECLS
typedef struct _SysprofCaptureReader SysprofCaptureReader; typedef struct _SysprofCaptureReader SysprofCaptureReader;
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureReader *sysprof_capture_reader_new (const gchar *filename, SysprofCaptureReader *sysprof_capture_reader_new (const char *filename,
GError **error); GError **error);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureReader *sysprof_capture_reader_new_from_fd (int fd, SysprofCaptureReader *sysprof_capture_reader_new_from_fd (int fd,
@ -76,15 +76,15 @@ SysprofCaptureReader *sysprof_capture_reader_ref (
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_capture_reader_unref (SysprofCaptureReader *self); void sysprof_capture_reader_unref (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gint sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self); int sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
const gchar *sysprof_capture_reader_get_filename (SysprofCaptureReader *self); const char *sysprof_capture_reader_get_filename (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
const gchar *sysprof_capture_reader_get_time (SysprofCaptureReader *self); const char *sysprof_capture_reader_get_time (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gint64 sysprof_capture_reader_get_start_time (SysprofCaptureReader *self); int64_t sysprof_capture_reader_get_start_time (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gint64 sysprof_capture_reader_get_end_time (SysprofCaptureReader *self); int64_t sysprof_capture_reader_get_end_time (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_reader_skip (SysprofCaptureReader *self); gboolean sysprof_capture_reader_skip (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
@ -129,7 +129,7 @@ gboolean sysprof_capture_reader_splice (
GError **error); GError **error);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_reader_save_as (SysprofCaptureReader *self, gboolean sysprof_capture_reader_save_as (SysprofCaptureReader *self,
const gchar *filename, const char *filename,
GError **error); GError **error);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_reader_get_stat (SysprofCaptureReader *self, gboolean sysprof_capture_reader_get_stat (SysprofCaptureReader *self,
@ -139,13 +139,13 @@ void sysprof_capture_reader_set_stat (
const SysprofCaptureStat *st_buf); const SysprofCaptureStat *st_buf);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
const SysprofCaptureFileChunk *sysprof_capture_reader_find_file (SysprofCaptureReader *self, const SysprofCaptureFileChunk *sysprof_capture_reader_find_file (SysprofCaptureReader *self,
const gchar *path); const char *path);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gchar **sysprof_capture_reader_list_files (SysprofCaptureReader *self); char **sysprof_capture_reader_list_files (SysprofCaptureReader *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self, gboolean sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
const gchar *path, const char *path,
gint fd); int fd);
G_END_DECLS G_END_DECLS

View File

@ -57,6 +57,9 @@
#pragma once #pragma once
#include <glib.h> #include <glib.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include "sysprof-clock.h" #include "sysprof-clock.h"
@ -92,25 +95,25 @@ typedef struct _SysprofCaptureWriter SysprofCaptureWriter;
typedef struct _SysprofCaptureCursor SysprofCaptureCursor; typedef struct _SysprofCaptureCursor SysprofCaptureCursor;
typedef struct _SysprofCaptureCondition SysprofCaptureCondition; typedef struct _SysprofCaptureCondition SysprofCaptureCondition;
typedef guint64 SysprofCaptureAddress; typedef uint64_t SysprofCaptureAddress;
typedef struct typedef struct
{ {
/* /*
* The number of frames indexed by SysprofCaptureFrameType * The number of frames indexed by SysprofCaptureFrameType
*/ */
gsize frame_count[16]; size_t frame_count[16];
/* /*
* Padding for future expansion. * Padding for future expansion.
*/ */
gsize padding[48]; size_t padding[48];
} SysprofCaptureStat; } SysprofCaptureStat;
typedef union typedef union
{ {
gint64 v64; int64_t v64;
gdouble vdbl; double vdbl;
} SysprofCaptureCounterValue; } SysprofCaptureCounterValue;
typedef enum typedef enum
@ -137,28 +140,28 @@ typedef enum
SYSPROF_ALIGNED_BEGIN(1) SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
guint32 magic; uint32_t magic;
guint32 version : 8; uint32_t version : 8;
guint32 little_endian : 1; uint32_t little_endian : 1;
guint32 padding : 23; uint32_t padding : 23;
gchar capture_time[64]; char capture_time[64];
gint64 time; int64_t time;
gint64 end_time; int64_t end_time;
gchar suffix[168]; char suffix[168];
} SysprofCaptureFileHeader } SysprofCaptureFileHeader
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
SYSPROF_ALIGNED_BEGIN(1) SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
guint16 len; uint16_t len;
gint16 cpu; int16_t cpu;
gint32 pid; int32_t pid;
gint64 time; int64_t time;
guint32 type : 8; uint32_t type : 8;
guint32 padding1 : 24; uint32_t padding1 : 24;
guint32 padding2; uint32_t padding2;
guint8 data[0]; uint8_t data[0];
} SysprofCaptureFrame } SysprofCaptureFrame
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -166,11 +169,11 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint64 start; uint64_t start;
guint64 end; uint64_t end;
guint64 offset; uint64_t offset;
guint64 inode; uint64_t inode;
gchar filename[0]; char filename[0];
} SysprofCaptureMap } SysprofCaptureMap
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -178,8 +181,8 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 n_jitmaps; uint32_t n_jitmaps;
guint8 data[0]; uint8_t data[0];
} SysprofCaptureJitmap } SysprofCaptureJitmap
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -187,7 +190,7 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
gchar cmdline[0]; char cmdline[0];
} SysprofCaptureProcess } SysprofCaptureProcess
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -195,9 +198,9 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 n_addrs : 16; uint32_t n_addrs : 16;
guint32 padding1 : 16; uint32_t padding1 : 16;
gint32 tid; int32_t tid;
SysprofCaptureAddress addrs[0]; SysprofCaptureAddress addrs[0];
} SysprofCaptureSample } SysprofCaptureSample
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -206,7 +209,7 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
gint32 child_pid; int32_t child_pid;
} SysprofCaptureFork } SysprofCaptureFork
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -227,11 +230,11 @@ SYSPROF_ALIGNED_END(1);
SYSPROF_ALIGNED_BEGIN(1) SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
gchar category[32]; char category[32];
gchar name[32]; char name[32];
gchar description[52]; char description[52];
guint32 id : 24; uint32_t id : 24;
guint32 type : 8; uint32_t type : 8;
SysprofCaptureCounterValue value; SysprofCaptureCounterValue value;
} SysprofCaptureCounter } SysprofCaptureCounter
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -240,9 +243,9 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 n_counters : 16; uint32_t n_counters : 16;
guint32 padding1 : 16; uint32_t padding1 : 16;
guint32 padding2; uint32_t padding2;
SysprofCaptureCounter counters[0]; SysprofCaptureCounter counters[0];
} SysprofCaptureCounterDefine } SysprofCaptureCounterDefine
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -255,7 +258,7 @@ typedef struct
* bytes. So this makes a nice 2-cacheline aligned size which is * bytes. So this makes a nice 2-cacheline aligned size which is
* useful when the number of counters is rather small. * useful when the number of counters is rather small.
*/ */
guint32 ids[8]; uint32_t ids[8];
SysprofCaptureCounterValue values[8]; SysprofCaptureCounterValue values[8];
} SysprofCaptureCounterValues } SysprofCaptureCounterValues
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -264,9 +267,9 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 n_values : 16; uint32_t n_values : 16;
guint32 padding1 : 16; uint32_t padding1 : 16;
guint32 padding2; uint32_t padding2;
SysprofCaptureCounterValues values[0]; SysprofCaptureCounterValues values[0];
} SysprofCaptureCounterSet } SysprofCaptureCounterSet
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -275,10 +278,10 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
gint64 duration; int64_t duration;
gchar group[24]; char group[24];
gchar name[40]; char name[40];
gchar message[0]; char message[0];
} SysprofCaptureMark } SysprofCaptureMark
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -286,8 +289,8 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
gchar id[40]; char id[40];
gchar metadata[0]; char metadata[0];
} SysprofCaptureMetadata } SysprofCaptureMetadata
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -295,11 +298,11 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 severity : 16; uint32_t severity : 16;
guint32 padding1 : 16; uint32_t padding1 : 16;
guint32 padding2 : 32; uint32_t padding2 : 32;
gchar domain[32]; char domain[32];
gchar message[0]; char message[0];
} SysprofCaptureLog } SysprofCaptureLog
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -307,11 +310,11 @@ SYSPROF_ALIGNED_BEGIN(1)
typedef struct typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
guint32 is_last : 1; uint32_t is_last : 1;
guint32 padding1 : 15; uint32_t padding1 : 15;
guint32 len : 16; uint32_t len : 16;
gchar path[256]; char path[256];
guint8 data[0]; uint8_t data[0];
} SysprofCaptureFileChunk } SysprofCaptureFileChunk
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -320,10 +323,10 @@ typedef struct
{ {
SysprofCaptureFrame frame; SysprofCaptureFrame frame;
SysprofCaptureAddress alloc_addr; SysprofCaptureAddress alloc_addr;
gint64 alloc_size; int64_t alloc_size;
gint32 tid; int32_t tid;
guint32 n_addrs : 16; uint32_t n_addrs : 16;
guint32 padding1 : 16; uint32_t padding1 : 16;
SysprofCaptureAddress addrs[0]; SysprofCaptureAddress addrs[0];
} SysprofCaptureAllocation } SysprofCaptureAllocation
SYSPROF_ALIGNED_END(1); SYSPROF_ALIGNED_END(1);
@ -350,7 +353,7 @@ G_STATIC_ASSERT (sizeof (SysprofCaptureAllocation) == 48);
G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0); G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0);
G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0); G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0);
static inline gint static inline int
sysprof_capture_address_compare (SysprofCaptureAddress a, sysprof_capture_address_compare (SysprofCaptureAddress a,
SysprofCaptureAddress b) SysprofCaptureAddress b)
{ {

View File

@ -84,7 +84,7 @@ ssize_t _sysprof_pwrite (int fd,
ssize_t _sysprof_write (int fd, ssize_t _sysprof_write (int fd,
const void *buf, const void *buf,
size_t count); size_t count);
gint32 _sysprof_getpid (void); int32_t _sysprof_getpid (void);
ssize_t _sysprof_sendfile (int out_fd, ssize_t _sysprof_sendfile (int out_fd,
int in_fd, int in_fd,
off_t *offset, off_t *offset,

View File

@ -157,7 +157,7 @@ ssize_t
#endif #endif
} }
gint32 int32_t
(_sysprof_getpid) (void) (_sysprof_getpid) (void)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32

View File

@ -59,14 +59,15 @@
#include "config.h" #include "config.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <sysprof-capture.h> #include <sysprof-capture.h>
#include <unistd.h> #include <unistd.h>
typedef struct typedef struct
{ {
guint64 src; uint64_t src;
guint64 dst; uint64_t dst;
} TranslateItem; } TranslateItem;
enum { enum {
@ -77,14 +78,14 @@ enum {
static void static void
translate_table_clear (GArray **tables, translate_table_clear (GArray **tables,
guint table) unsigned int table)
{ {
g_clear_pointer (&tables[table], g_array_unref); g_clear_pointer (&tables[table], g_array_unref);
} }
static gint static int
compare_by_src (gconstpointer a, compare_by_src (const void *a,
gconstpointer b) const void *b)
{ {
const TranslateItem *itema = a; const TranslateItem *itema = a;
const TranslateItem *itemb = b; const TranslateItem *itemb = b;
@ -99,7 +100,7 @@ compare_by_src (gconstpointer a,
static void static void
translate_table_sort (GArray **tables, translate_table_sort (GArray **tables,
guint table) unsigned int table)
{ {
if (tables[table]) if (tables[table])
g_array_sort (tables[table], compare_by_src); g_array_sort (tables[table], compare_by_src);
@ -107,9 +108,9 @@ translate_table_sort (GArray **tables,
static void static void
translate_table_add (GArray **tables, translate_table_add (GArray **tables,
guint table, unsigned int table,
guint64 src, uint64_t src,
guint64 dst) uint64_t dst)
{ {
const TranslateItem item = { src, dst }; const TranslateItem item = { src, dst };
@ -119,10 +120,10 @@ translate_table_add (GArray **tables,
g_array_append_val (tables[table], item); g_array_append_val (tables[table], item);
} }
static guint64 static uint64_t
translate_table_translate (GArray **tables, translate_table_translate (GArray **tables,
guint table, unsigned int table,
guint64 src) uint64_t src)
{ {
const TranslateItem *item; const TranslateItem *item;
TranslateItem key = { src, 0 }; TranslateItem key = { src, 0 };
@ -152,9 +153,9 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
{ {
GArray *tables[N_TRANSLATE] = { NULL }; GArray *tables[N_TRANSLATE] = { NULL };
SysprofCaptureFrameType type; SysprofCaptureFrameType type;
gint64 start_time; int64_t start_time;
gint64 first_start_time = G_MAXINT64; int64_t first_start_time = INT64_MAX;
gint64 end_time = -1; int64_t end_time = -1;
g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (reader != NULL, FALSE); g_return_val_if_fail (reader != NULL, FALSE);
@ -176,8 +177,8 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
{ {
g_autoptr(GHashTable) jitmap = NULL; g_autoptr(GHashTable) jitmap = NULL;
GHashTableIter iter; GHashTableIter iter;
const gchar *name; const char *name;
guint64 addr; uint64_t addr;
if (type != SYSPROF_CAPTURE_FRAME_JITMAP) if (type != SYSPROF_CAPTURE_FRAME_JITMAP)
{ {
@ -192,7 +193,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
g_hash_table_iter_init (&iter, jitmap); g_hash_table_iter_init (&iter, jitmap);
while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&name)) while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&name))
{ {
guint64 replace = sysprof_capture_writer_add_jitmap (self, name); uint64_t replace = sysprof_capture_writer_add_jitmap (self, name);
/* We need to keep a table of replacement addresses so that /* We need to keep a table of replacement addresses so that
* we can translate the samples into the destination address * we can translate the samples into the destination address
* space that we synthesized for the address identifier. * space that we synthesized for the address identifier.
@ -378,7 +379,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
{ {
SysprofCaptureAddress addrs[frame->n_addrs]; SysprofCaptureAddress addrs[frame->n_addrs];
for (guint z = 0; z < frame->n_addrs; z++) for (unsigned int z = 0; z < frame->n_addrs; z++)
addrs[z] = translate_table_translate (tables, TRANSLATE_ADDR, frame->addrs[z]); addrs[z] = translate_table_translate (tables, TRANSLATE_ADDR, frame->addrs[z]);
sysprof_capture_writer_add_sample (self, sysprof_capture_writer_add_sample (self,
@ -403,10 +404,10 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
{ {
g_autoptr(GArray) counter = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); g_autoptr(GArray) counter = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter));
for (guint z = 0; z < frame->n_counters; z++) for (unsigned int z = 0; z < frame->n_counters; z++)
{ {
SysprofCaptureCounter c = frame->counters[z]; SysprofCaptureCounter c = frame->counters[z];
guint src = c.id; unsigned int src = c.id;
c.id = sysprof_capture_writer_request_counter (self, 1); c.id = sysprof_capture_writer_request_counter (self, 1);
@ -440,15 +441,15 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
g_autoptr(GArray) ids = g_array_new (FALSE, FALSE, sizeof (guint)); g_autoptr(GArray) ids = g_array_new (FALSE, FALSE, sizeof (guint));
g_autoptr(GArray) values = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounterValue)); g_autoptr(GArray) values = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounterValue));
for (guint z = 0; z < frame->n_values; z++) for (unsigned int z = 0; z < frame->n_values; z++)
{ {
const SysprofCaptureCounterValues *v = &frame->values[z]; const SysprofCaptureCounterValues *v = &frame->values[z];
for (guint y = 0; y < G_N_ELEMENTS (v->ids); y++) for (unsigned int y = 0; y < G_N_ELEMENTS (v->ids); y++)
{ {
if (v->ids[y]) if (v->ids[y])
{ {
guint dst = translate_table_translate (tables, TRANSLATE_CTR, v->ids[y]); unsigned int dst = translate_table_translate (tables, TRANSLATE_CTR, v->ids[y]);
SysprofCaptureCounterValue value = v->values[y]; SysprofCaptureCounterValue value = v->values[y];
g_array_append_val (ids, dst); g_array_append_val (ids, dst);
@ -463,8 +464,8 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
frame->frame.time, frame->frame.time,
frame->frame.cpu, frame->frame.cpu,
frame->frame.pid, frame->frame.pid,
(const guint *)(gpointer)ids->data, (const unsigned int *)(void *)ids->data,
(const SysprofCaptureCounterValue *)(gpointer)values->data, (const SysprofCaptureCounterValue *)(void *)values->data,
ids->len); ids->len);
} }

View File

@ -65,6 +65,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -83,10 +84,10 @@
typedef struct typedef struct
{ {
/* A pinter into the string buffer */ /* A pinter into the string buffer */
const gchar *str; const char *str;
/* The unique address for the string */ /* The unique address for the string */
guint64 addr; uint64_t addr;
} SysprofCaptureJitmapBucket; } SysprofCaptureJitmapBucket;
struct _SysprofCaptureWriter struct _SysprofCaptureWriter
@ -98,7 +99,7 @@ struct _SysprofCaptureWriter
* *
* This is paired with a closed hash table for deduplication. * This is paired with a closed hash table for deduplication.
*/ */
gchar addr_buf[4096*4]; char addr_buf[4096*4];
/* Our hashtable for deduplication. */ /* Our hashtable for deduplication. */
SysprofCaptureJitmapBucket addr_hash[512]; SysprofCaptureJitmapBucket addr_hash[512];
@ -107,38 +108,38 @@ struct _SysprofCaptureWriter
* alinged for the write buffer. This improves the performance of large * alinged for the write buffer. This improves the performance of large
* writes to the target file-descriptor. * writes to the target file-descriptor.
*/ */
volatile gint ref_count; volatile int ref_count;
/* /*
* Our address sequence counter. The value that comes from * Our address sequence counter. The value that comes from
* monotonically increasing this is OR'd with JITMAP_MARK to denote * monotonically increasing this is OR'd with JITMAP_MARK to denote
* the address name should come from the JIT map. * the address name should come from the JIT map.
*/ */
gsize addr_seq; size_t addr_seq;
/* Our position in addr_buf. */ /* Our position in addr_buf. */
gsize addr_buf_pos; size_t addr_buf_pos;
/* /*
* The number of hash table items in @addr_hash. This is an * The number of hash table items in @addr_hash. This is an
* optimization so that we can avoid calculating the number of strings * optimization so that we can avoid calculating the number of strings
* when flushing out the jitmap. * when flushing out the jitmap.
*/ */
guint addr_hash_size; unsigned int addr_hash_size;
/* Capture file handle */ /* Capture file handle */
int fd; int fd;
/* Our write buffer for fd */ /* Our write buffer for fd */
guint8 *buf; uint8_t *buf;
gsize pos; size_t pos;
gsize len; size_t len;
/* GSource for periodic flush */ /* GSource for periodic flush */
GSource *periodic_flush; GSource *periodic_flush;
/* counter id sequence */ /* counter id sequence */
gint next_counter_id; int next_counter_id;
/* Statistics while recording */ /* Statistics while recording */
SysprofCaptureStat stat; SysprofCaptureStat stat;
@ -146,10 +147,10 @@ struct _SysprofCaptureWriter
static inline void static inline void
sysprof_capture_writer_frame_init (SysprofCaptureFrame *frame_, sysprof_capture_writer_frame_init (SysprofCaptureFrame *frame_,
gint len, int len,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint64 time_, int64_t time_,
SysprofCaptureFrameType type) SysprofCaptureFrameType type)
{ {
g_assert (frame_ != NULL); g_assert (frame_ != NULL);
@ -207,9 +208,9 @@ sysprof_capture_writer_unref (SysprofCaptureWriter *self)
static gboolean static gboolean
sysprof_capture_writer_flush_data (SysprofCaptureWriter *self) sysprof_capture_writer_flush_data (SysprofCaptureWriter *self)
{ {
const guint8 *buf; const uint8_t *buf;
gssize written; ssize_t written;
gsize to_write; size_t to_write;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (self->pos <= self->len); g_assert (self->pos <= self->len);
@ -230,7 +231,7 @@ sysprof_capture_writer_flush_data (SysprofCaptureWriter *self)
if (written == 0 && errno != EAGAIN) if (written == 0 && errno != EAGAIN)
return FALSE; return FALSE;
g_assert (written <= (gssize)to_write); g_assert (written <= (ssize_t)to_write);
buf += written; buf += written;
to_write -= written; to_write -= written;
@ -242,17 +243,17 @@ sysprof_capture_writer_flush_data (SysprofCaptureWriter *self)
} }
static inline void static inline void
sysprof_capture_writer_realign (gsize *pos) sysprof_capture_writer_realign (size_t *pos)
{ {
*pos = (*pos + SYSPROF_CAPTURE_ALIGN - 1) & ~(SYSPROF_CAPTURE_ALIGN - 1); *pos = (*pos + SYSPROF_CAPTURE_ALIGN - 1) & ~(SYSPROF_CAPTURE_ALIGN - 1);
} }
static inline gboolean static inline gboolean
sysprof_capture_writer_ensure_space_for (SysprofCaptureWriter *self, sysprof_capture_writer_ensure_space_for (SysprofCaptureWriter *self,
gsize len) size_t len)
{ {
/* Check for max frame size */ /* Check for max frame size */
if (len > G_MAXUSHORT) if (len > USHRT_MAX)
return FALSE; return FALSE;
if ((self->len - self->pos) < len) if ((self->len - self->pos) < len)
@ -264,11 +265,11 @@ sysprof_capture_writer_ensure_space_for (SysprofCaptureWriter *self,
return TRUE; return TRUE;
} }
static inline gpointer static inline void *
sysprof_capture_writer_allocate (SysprofCaptureWriter *self, sysprof_capture_writer_allocate (SysprofCaptureWriter *self,
gsize *len) size_t *len)
{ {
gpointer p; void *p;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (len != NULL); g_assert (len != NULL);
@ -279,7 +280,7 @@ sysprof_capture_writer_allocate (SysprofCaptureWriter *self,
if (!sysprof_capture_writer_ensure_space_for (self, *len)) if (!sysprof_capture_writer_ensure_space_for (self, *len))
return NULL; return NULL;
p = (gpointer)&self->buf[self->pos]; p = (void *)&self->buf[self->pos];
self->pos += *len; self->pos += *len;
@ -292,8 +293,8 @@ static gboolean
sysprof_capture_writer_flush_jitmap (SysprofCaptureWriter *self) sysprof_capture_writer_flush_jitmap (SysprofCaptureWriter *self)
{ {
SysprofCaptureJitmap jitmap; SysprofCaptureJitmap jitmap;
gssize r; ssize_t r;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
@ -318,7 +319,7 @@ sysprof_capture_writer_flush_jitmap (SysprofCaptureWriter *self)
return FALSE; return FALSE;
r = _sysprof_write (self->fd, self->addr_buf, len - sizeof jitmap); r = _sysprof_write (self->fd, self->addr_buf, len - sizeof jitmap);
if (r < 0 || (gsize)r != (len - sizeof jitmap)) if (r < 0 || (size_t)r != (len - sizeof jitmap))
return FALSE; return FALSE;
self->addr_buf_pos = 0; self->addr_buf_pos = 0;
@ -332,11 +333,11 @@ sysprof_capture_writer_flush_jitmap (SysprofCaptureWriter *self)
static gboolean static gboolean
sysprof_capture_writer_lookup_jitmap (SysprofCaptureWriter *self, sysprof_capture_writer_lookup_jitmap (SysprofCaptureWriter *self,
const gchar *name, const char *name,
SysprofCaptureAddress *addr) SysprofCaptureAddress *addr)
{ {
guint hash; unsigned int hash;
guint i; unsigned int i;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (name != NULL); g_assert (name != NULL);
@ -377,13 +378,13 @@ sysprof_capture_writer_lookup_jitmap (SysprofCaptureWriter *self,
static SysprofCaptureAddress static SysprofCaptureAddress
sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self, sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
const gchar *str) const char *str)
{ {
SysprofCaptureAddress addr; SysprofCaptureAddress addr;
gchar *dst; char *dst;
gsize len; size_t len;
guint hash; unsigned int hash;
guint i; unsigned int i;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (str != NULL); g_assert (str != NULL);
@ -408,7 +409,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
addr = SYSPROF_CAPTURE_JITMAP_MARK | ++self->addr_seq; addr = SYSPROF_CAPTURE_JITMAP_MARK | ++self->addr_seq;
/* Copy the address into the buffer */ /* Copy the address into the buffer */
dst = (gchar *)&self->addr_buf[self->addr_buf_pos]; dst = (char *)&self->addr_buf[self->addr_buf_pos];
memcpy (dst, &addr, sizeof addr); memcpy (dst, &addr, sizeof addr);
/* /*
@ -460,13 +461,13 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
SysprofCaptureWriter * SysprofCaptureWriter *
sysprof_capture_writer_new_from_fd (int fd, sysprof_capture_writer_new_from_fd (int fd,
gsize buffer_size) size_t buffer_size)
{ {
g_autofree gchar *nowstr = NULL; g_autofree gchar *nowstr = NULL;
g_autoptr(GDateTime) now = NULL; g_autoptr(GDateTime) now = NULL;
SysprofCaptureWriter *self; SysprofCaptureWriter *self;
SysprofCaptureFileHeader *header; SysprofCaptureFileHeader *header;
gsize header_len = sizeof(*header); size_t header_len = sizeof(*header);
if (fd < 0) if (fd < 0)
return NULL; return NULL;
@ -538,8 +539,8 @@ sysprof_capture_writer_new_from_fd (int fd,
} }
SysprofCaptureWriter * SysprofCaptureWriter *
sysprof_capture_writer_new (const gchar *filename, sysprof_capture_writer_new (const char *filename,
gsize buffer_size) size_t buffer_size)
{ {
SysprofCaptureWriter *self; SysprofCaptureWriter *self;
int fd; int fd;
@ -561,17 +562,17 @@ sysprof_capture_writer_new (const gchar *filename,
gboolean gboolean
sysprof_capture_writer_add_map (SysprofCaptureWriter *self, sysprof_capture_writer_add_map (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
guint64 start, uint64_t start,
guint64 end, uint64_t end,
guint64 offset, uint64_t offset,
guint64 inode, uint64_t inode,
const gchar *filename) const char *filename)
{ {
SysprofCaptureMap *ev; SysprofCaptureMap *ev;
gsize len; size_t len;
if (filename == NULL) if (filename == NULL)
filename = ""; filename = "";
@ -606,17 +607,17 @@ sysprof_capture_writer_add_map (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_mark (SysprofCaptureWriter *self, sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
guint64 duration, uint64_t duration,
const gchar *group, const char *group,
const gchar *name, const char *name,
const gchar *message) const char *message)
{ {
SysprofCaptureMark *ev; SysprofCaptureMark *ev;
gsize message_len; size_t message_len;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (name != NULL); g_assert (name != NULL);
@ -650,15 +651,15 @@ sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self, sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *id, const char *id,
const gchar *metadata, const char *metadata,
gssize metadata_len) ssize_t metadata_len)
{ {
SysprofCaptureMetadata *ev; SysprofCaptureMetadata *ev;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (id != NULL); g_assert (id != NULL);
@ -695,7 +696,7 @@ sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self,
SysprofCaptureAddress SysprofCaptureAddress
sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self, sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self,
const gchar *name) const char *name)
{ {
SysprofCaptureAddress addr = INVALID_ADDRESS; SysprofCaptureAddress addr = INVALID_ADDRESS;
@ -713,13 +714,13 @@ sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_process (SysprofCaptureWriter *self, sysprof_capture_writer_add_process (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *cmdline) const char *cmdline)
{ {
SysprofCaptureProcess *ev; SysprofCaptureProcess *ev;
gsize len; size_t len;
if (cmdline == NULL) if (cmdline == NULL)
cmdline = ""; cmdline = "";
@ -750,15 +751,15 @@ sysprof_capture_writer_add_process (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_sample (SysprofCaptureWriter *self, sysprof_capture_writer_add_sample (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
const SysprofCaptureAddress *addrs, const SysprofCaptureAddress *addrs,
guint n_addrs) unsigned int n_addrs)
{ {
SysprofCaptureSample *ev; SysprofCaptureSample *ev;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
@ -786,13 +787,13 @@ sysprof_capture_writer_add_sample (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_fork (SysprofCaptureWriter *self, sysprof_capture_writer_add_fork (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 child_pid) int32_t child_pid)
{ {
SysprofCaptureFork *ev; SysprofCaptureFork *ev;
gsize len = sizeof *ev; size_t len = sizeof *ev;
g_assert (self != NULL); g_assert (self != NULL);
@ -815,12 +816,12 @@ sysprof_capture_writer_add_fork (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_exit (SysprofCaptureWriter *self, sysprof_capture_writer_add_exit (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid) int32_t pid)
{ {
SysprofCaptureExit *ev; SysprofCaptureExit *ev;
gsize len = sizeof *ev; size_t len = sizeof *ev;
g_assert (self != NULL); g_assert (self != NULL);
@ -842,12 +843,12 @@ sysprof_capture_writer_add_exit (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self, sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid) int32_t pid)
{ {
SysprofCaptureTimestamp *ev; SysprofCaptureTimestamp *ev;
gsize len = sizeof *ev; size_t len = sizeof *ev;
g_assert (self != NULL); g_assert (self != NULL);
@ -870,7 +871,7 @@ sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self,
static gboolean static gboolean
sysprof_capture_writer_flush_end_time (SysprofCaptureWriter *self) sysprof_capture_writer_flush_end_time (SysprofCaptureWriter *self)
{ {
gint64 end_time = SYSPROF_CAPTURE_CURRENT_TIME; int64_t end_time = SYSPROF_CAPTURE_CURRENT_TIME;
ssize_t ret; ssize_t ret;
g_assert (self != NULL); g_assert (self != NULL);
@ -914,10 +915,10 @@ sysprof_capture_writer_flush (SysprofCaptureWriter *self)
*/ */
gboolean gboolean
sysprof_capture_writer_save_as (SysprofCaptureWriter *self, sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
const gchar *filename, const char *filename,
GError **error) GError **error)
{ {
gsize to_write; size_t to_write;
off_t in_off; off_t in_off;
off_t pos; off_t pos;
int fd = -1; int fd = -1;
@ -940,7 +941,7 @@ sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
while (to_write > 0) while (to_write > 0)
{ {
gssize written; ssize_t written;
written = _sysprof_sendfile (fd, self->fd, &in_off, pos); written = _sysprof_sendfile (fd, self->fd, &in_off, pos);
@ -950,7 +951,7 @@ sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
if (written == 0 && errno != EAGAIN) if (written == 0 && errno != EAGAIN)
goto handle_errno; goto handle_errno;
g_assert (written <= (gssize)to_write); g_assert (written <= (ssize_t)to_write);
to_write -= written; to_write -= written;
} }
@ -997,7 +998,7 @@ _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
{ {
struct stat stbuf; struct stat stbuf;
off_t in_off; off_t in_off;
gsize to_write; size_t to_write;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (self->fd != -1); g_assert (self->fd != -1);
@ -1019,7 +1020,7 @@ _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
while (to_write > 0) while (to_write > 0)
{ {
gssize written; ssize_t written;
written = _sysprof_sendfile (self->fd, fd, &in_off, to_write); written = _sysprof_sendfile (self->fd, fd, &in_off, to_write);
@ -1029,7 +1030,7 @@ _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
if (written == 0 && errno != EAGAIN) if (written == 0 && errno != EAGAIN)
goto handle_errno; goto handle_errno;
g_assert (written <= (gssize)to_write); g_assert (written <= (ssize_t)to_write);
to_write -= written; to_write -= written;
} }
@ -1166,15 +1167,15 @@ sysprof_capture_writer_stat (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_define_counters (SysprofCaptureWriter *self, sysprof_capture_writer_define_counters (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const SysprofCaptureCounter *counters, const SysprofCaptureCounter *counters,
guint n_counters) unsigned int n_counters)
{ {
SysprofCaptureCounterDefine *def; SysprofCaptureCounterDefine *def;
gsize len; size_t len;
guint i; unsigned int i;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (counters != NULL); g_assert (counters != NULL);
@ -1216,19 +1217,19 @@ sysprof_capture_writer_define_counters (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_set_counters (SysprofCaptureWriter *self, sysprof_capture_writer_set_counters (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const guint *counters_ids, const unsigned int *counters_ids,
const SysprofCaptureCounterValue *values, const SysprofCaptureCounterValue *values,
guint n_counters) unsigned int n_counters)
{ {
SysprofCaptureCounterSet *set; SysprofCaptureCounterSet *set;
gsize len; size_t len;
guint n_groups; unsigned int n_groups;
guint group; unsigned int group;
guint field; unsigned int field;
guint i; unsigned int i;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (counters_ids != NULL || n_counters == 0); g_assert (counters_ids != NULL || n_counters == 0);
@ -1292,11 +1293,11 @@ sysprof_capture_writer_set_counters (SysprofCaptureWriter *self,
* *
* Returns: The next series of counter values or zero on failure. * Returns: The next series of counter values or zero on failure.
*/ */
guint unsigned int
sysprof_capture_writer_request_counter (SysprofCaptureWriter *self, sysprof_capture_writer_request_counter (SysprofCaptureWriter *self,
guint n_counters) unsigned int n_counters)
{ {
gint ret; int ret;
g_assert (self != NULL); g_assert (self != NULL);
@ -1311,8 +1312,8 @@ sysprof_capture_writer_request_counter (SysprofCaptureWriter *self,
gboolean gboolean
_sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self, _sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self,
gint64 start_time, int64_t start_time,
gint64 end_time) int64_t end_time)
{ {
ssize_t ret; ssize_t ret;
@ -1340,9 +1341,9 @@ do_end:
} }
SysprofCaptureWriter * SysprofCaptureWriter *
sysprof_capture_writer_new_from_env (gsize buffer_size) sysprof_capture_writer_new_from_env (size_t buffer_size)
{ {
const gchar *fdstr; const char *fdstr;
int fd; int fd;
if (!(fdstr = g_getenv ("SYSPROF_TRACE_FD"))) if (!(fdstr = g_getenv ("SYSPROF_TRACE_FD")))
@ -1361,7 +1362,7 @@ sysprof_capture_writer_new_from_env (gsize buffer_size)
return sysprof_capture_writer_new_from_fd (dup (fd), buffer_size); return sysprof_capture_writer_new_from_fd (dup (fd), buffer_size);
} }
gsize size_t
sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self) sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self)
{ {
g_return_val_if_fail (self != NULL, 0); g_return_val_if_fail (self != NULL, 0);
@ -1371,16 +1372,16 @@ sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self)
gboolean gboolean
sysprof_capture_writer_add_log (SysprofCaptureWriter *self, sysprof_capture_writer_add_log (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
GLogLevelFlags severity, int severity,
const gchar *domain, const char *domain,
const gchar *message) const char *message)
{ {
SysprofCaptureLog *ev; SysprofCaptureLog *ev;
gsize message_len; size_t message_len;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
@ -1416,16 +1417,16 @@ sysprof_capture_writer_add_log (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_file (SysprofCaptureWriter *self, sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *path, const char *path,
gboolean is_last, bool is_last,
const guint8 *data, const uint8_t *data,
gsize data_len) size_t data_len)
{ {
SysprofCaptureFileChunk *ev; SysprofCaptureFileChunk *ev;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
@ -1454,20 +1455,20 @@ sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self, sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *path, const char *path,
gint fd) int fd)
{ {
guint8 data[(4096*4L) - sizeof(SysprofCaptureFileChunk)]; uint8_t data[(4096*4L) - sizeof(SysprofCaptureFileChunk)];
g_assert (self != NULL); g_assert (self != NULL);
for (;;) for (;;)
{ {
gboolean is_last; gboolean is_last;
gssize n_read; ssize_t n_read;
again: again:
n_read = read (fd, data, sizeof data); n_read = read (fd, data, sizeof data);
@ -1524,18 +1525,18 @@ sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self, sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
SysprofCaptureAddress alloc_addr, SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
SysprofBacktraceFunc backtrace_func, SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data) void *backtrace_data)
{ {
SysprofCaptureAllocation *ev; SysprofCaptureAllocation *ev;
gsize len; size_t len;
guint n_addrs; unsigned int n_addrs;
g_assert (self != NULL); g_assert (self != NULL);
g_assert (backtrace_func != NULL); g_assert (backtrace_func != NULL);
@ -1565,7 +1566,7 @@ sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self,
if (ev->n_addrs < MAX_UNWIND_DEPTH) if (ev->n_addrs < MAX_UNWIND_DEPTH)
{ {
gsize diff = (sizeof (SysprofCaptureAddress) * (MAX_UNWIND_DEPTH - ev->n_addrs)); size_t diff = (sizeof (SysprofCaptureAddress) * (MAX_UNWIND_DEPTH - ev->n_addrs));
ev->frame.len -= diff; ev->frame.len -= diff;
self->pos -= diff; self->pos -= diff;
@ -1578,17 +1579,17 @@ sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self,
gboolean gboolean
sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self, sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
SysprofCaptureAddress alloc_addr, SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
const SysprofCaptureAddress *addrs, const SysprofCaptureAddress *addrs,
guint n_addrs) unsigned int n_addrs)
{ {
SysprofCaptureAllocation *ev; SysprofCaptureAllocation *ev;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
@ -1624,8 +1625,8 @@ gboolean
_sysprof_capture_writer_add_raw (SysprofCaptureWriter *self, _sysprof_capture_writer_add_raw (SysprofCaptureWriter *self,
const SysprofCaptureFrame *fr) const SysprofCaptureFrame *fr)
{ {
gpointer begin; void *begin;
gsize len; size_t len;
g_assert (self != NULL); g_assert (self != NULL);
g_assert ((fr->len & 0x7) == 0); g_assert ((fr->len & 0x7) == 0);

View File

@ -56,6 +56,9 @@
#pragma once #pragma once
#include <stdint.h>
#include <sys/types.h>
#include "sysprof-capture-types.h" #include "sysprof-capture-types.h"
#include "sysprof-version-macros.h" #include "sysprof-version-macros.h"
@ -72,20 +75,20 @@ typedef struct _SysprofCaptureWriter SysprofCaptureWriter;
* *
* Returns: the number of addresses filled in @addrs * Returns: the number of addresses filled in @addrs
*/ */
typedef gint (*SysprofBacktraceFunc) (SysprofCaptureAddress *addrs, typedef int (*SysprofBacktraceFunc) (SysprofCaptureAddress *addrs,
guint n_addrs, unsigned int n_addrs,
gpointer user_data); void *user_data);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureWriter *sysprof_capture_writer_new_from_env (gsize buffer_size); SysprofCaptureWriter *sysprof_capture_writer_new_from_env (size_t buffer_size);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureWriter *sysprof_capture_writer_new (const gchar *filename, SysprofCaptureWriter *sysprof_capture_writer_new (const char *filename,
gsize buffer_size); size_t buffer_size);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureWriter *sysprof_capture_writer_new_from_fd (int fd, SysprofCaptureWriter *sysprof_capture_writer_new_from_fd (int fd,
gsize buffer_size); size_t buffer_size);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gsize sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self); size_t sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureWriter *sysprof_capture_writer_ref (SysprofCaptureWriter *self); SysprofCaptureWriter *sysprof_capture_writer_ref (SysprofCaptureWriter *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
@ -96,135 +99,135 @@ void sysprof_capture_writer_stat (Sy
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self, void sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter *self,
GMainContext *main_context, GMainContext *main_context,
guint timeout_seconds); unsigned int timeout_seconds);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_file (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *path, const char *path,
gboolean is_last, gboolean is_last,
const guint8 *data, const uint8_t *data,
gsize data_len); size_t data_len);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *path, const char *path,
gint fd); int fd);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_map (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_map (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
guint64 start, uint64_t start,
guint64 end, uint64_t end,
guint64 offset, uint64_t offset,
guint64 inode, uint64_t inode,
const gchar *filename); const char *filename);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_mark (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
guint64 duration, uint64_t duration,
const gchar *group, const char *group,
const gchar *name, const char *name,
const gchar *message); const char *message);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *id, const char *id,
const gchar *metadata, const char *metadata,
gssize metadata_len); ssize_t metadata_len);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
guint64 sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self, uint64_t sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self,
const gchar *name); const char *name);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_process (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_process (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const gchar *cmdline); const char *cmdline);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_sample (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_sample (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
const SysprofCaptureAddress *addrs, const SysprofCaptureAddress *addrs,
guint n_addrs); unsigned int n_addrs);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_fork (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_fork (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 child_pid); int32_t child_pid);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_exit (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_exit (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid); int32_t pid);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid); int32_t pid);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_define_counters (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_define_counters (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const SysprofCaptureCounter *counters, const SysprofCaptureCounter *counters,
guint n_counters); unsigned int n_counters);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_set_counters (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_set_counters (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
const guint *counters_ids, const unsigned int *counters_ids,
const SysprofCaptureCounterValue *values, const SysprofCaptureCounterValue *values,
guint n_counters); unsigned int n_counters);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_add_log (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_log (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
GLogLevelFlags severity, int severity,
const gchar *domain, const char *domain,
const gchar *message); const char *message);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
gboolean sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
SysprofCaptureAddress alloc_addr, SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
SysprofBacktraceFunc backtrace_func, SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data); void *backtrace_data);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
gboolean sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self,
gint64 time, int64_t time,
gint cpu, int cpu,
gint32 pid, int32_t pid,
gint32 tid, int32_t tid,
SysprofCaptureAddress alloc_addr, SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
const SysprofCaptureAddress *addrs, const SysprofCaptureAddress *addrs,
guint n_addrs); unsigned int n_addrs);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_flush (SysprofCaptureWriter *self); gboolean sysprof_capture_writer_flush (SysprofCaptureWriter *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_capture_writer_save_as (SysprofCaptureWriter *self, gboolean sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
const gchar *filename, const char *filename,
GError **error); GError **error);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
guint sysprof_capture_writer_request_counter (SysprofCaptureWriter *self, unsigned int sysprof_capture_writer_request_counter (SysprofCaptureWriter *self,
guint n_counters); unsigned int n_counters);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofCaptureReader *sysprof_capture_writer_create_reader (SysprofCaptureWriter *self, SysprofCaptureReader *sysprof_capture_writer_create_reader (SysprofCaptureWriter *self,
GError **error); GError **error);
@ -245,8 +248,8 @@ gboolean _sysprof_capture_writer_splice_from_fd (Sy
GError **error) G_GNUC_INTERNAL; GError **error) G_GNUC_INTERNAL;
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean _sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self, gboolean _sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self,
gint64 start_time, int64_t start_time,
gint64 end_time) G_GNUC_INTERNAL; int64_t end_time) G_GNUC_INTERNAL;
G_END_DECLS G_END_DECLS

View File

@ -60,12 +60,12 @@
#include "sysprof-clock.h" #include "sysprof-clock.h"
gint sysprof_clock = -1; int sysprof_clock = -1;
void void
sysprof_clock_init (void) sysprof_clock_init (void)
{ {
static const gint clock_ids[] = { static const int clock_ids[] = {
CLOCK_MONOTONIC, CLOCK_MONOTONIC,
CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_RAW,
#ifdef __linux__ #ifdef __linux__
@ -78,7 +78,7 @@ sysprof_clock_init (void)
if (sysprof_clock != -1) if (sysprof_clock != -1)
return; return;
for (guint i = 0; i < G_N_ELEMENTS (clock_ids); i++) for (unsigned int i = 0; i < G_N_ELEMENTS (clock_ids); i++)
{ {
struct timespec ts; struct timespec ts;
int clock_id = clock_ids [i]; int clock_id = clock_ids [i];

View File

@ -57,15 +57,16 @@
#pragma once #pragma once
#include <glib.h> #include <glib.h>
#include <stdint.h>
#include <time.h> #include <time.h>
#include "sysprof-version-macros.h" #include "sysprof-version-macros.h"
G_BEGIN_DECLS G_BEGIN_DECLS
typedef gint SysprofClock; typedef int SysprofClock;
typedef gint64 SysprofTimeStamp; typedef int64_t SysprofTimeStamp;
typedef gint32 SysprofTimeSysprofan; typedef int32_t SysprofTimeSysprofan;
#define SYSPROF_NSEC_PER_SEC G_GINT64_CONSTANT(1000000000) #define SYSPROF_NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)

View File

@ -87,10 +87,10 @@ typedef struct
int pid; int pid;
} SysprofCollector; } SysprofCollector;
#define COLLECTOR_INVALID ((gpointer)&invalid) #define COLLECTOR_INVALID ((void *)&invalid)
static MappedRingBuffer *request_writer (void); static MappedRingBuffer *request_writer (void);
static void sysprof_collector_free (gpointer data); static void sysprof_collector_free (void *data);
static const SysprofCollector *sysprof_collector_get (void); static const SysprofCollector *sysprof_collector_get (void);
static G_LOCK_DEFINE (control_fd); static G_LOCK_DEFINE (control_fd);
@ -115,8 +115,8 @@ _do_getcpu (void)
#endif #endif
} }
static inline gsize static inline size_t
realign (gsize size) realign (size_t size)
{ {
return (size + SYSPROF_CAPTURE_ALIGN - 1) & ~(SYSPROF_CAPTURE_ALIGN - 1); return (size + SYSPROF_CAPTURE_ALIGN - 1) & ~(SYSPROF_CAPTURE_ALIGN - 1);
} }
@ -129,7 +129,7 @@ request_writer (void)
if (conn == NULL) if (conn == NULL)
{ {
const gchar *fdstr = g_getenv ("SYSPROF_CONTROL_FD"); const char *fdstr = g_getenv ("SYSPROF_CONTROL_FD");
int peer_fd = -1; int peer_fd = -1;
if (fdstr != NULL) if (fdstr != NULL)
@ -166,7 +166,7 @@ request_writer (void)
if (g_output_stream_write_all (G_OUTPUT_STREAM (out_stream), CREATRING, CREATRING_LEN, &len, NULL, NULL) && if (g_output_stream_write_all (G_OUTPUT_STREAM (out_stream), CREATRING, CREATRING_LEN, &len, NULL, NULL) &&
len == CREATRING_LEN) len == CREATRING_LEN)
{ {
gint ring_fd = g_unix_connection_receive_fd (conn, NULL, NULL); int ring_fd = g_unix_connection_receive_fd (conn, NULL, NULL);
if (ring_fd > -1) if (ring_fd > -1)
{ {
@ -198,7 +198,7 @@ write_final_frame (MappedRingBuffer *ring)
} }
static void static void
sysprof_collector_free (gpointer data) sysprof_collector_free (void *data)
{ {
SysprofCollector *collector = data; SysprofCollector *collector = data;
@ -263,7 +263,7 @@ sysprof_collector_get (void)
void void
sysprof_collector_init (void) sysprof_collector_init (void)
{ {
static gsize once_init; static size_t once_init;
if (g_once_init_enter (&once_init)) if (g_once_init_enter (&once_init))
{ {
@ -293,19 +293,19 @@ sysprof_collector_init (void)
void void
sysprof_collector_allocate (SysprofCaptureAddress alloc_addr, sysprof_collector_allocate (SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
SysprofBacktraceFunc backtrace_func, SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data) void *backtrace_data)
{ {
COLLECTOR_BEGIN { COLLECTOR_BEGIN {
SysprofCaptureAllocation *ev; SysprofCaptureAllocation *ev;
gsize len; size_t len;
len = sizeof *ev + (sizeof (SysprofCaptureAllocation) * MAX_UNWIND_DEPTH); len = sizeof *ev + (sizeof (SysprofCaptureAllocation) * MAX_UNWIND_DEPTH);
if ((ev = mapped_ring_buffer_allocate (collector->buffer, len))) if ((ev = mapped_ring_buffer_allocate (collector->buffer, len)))
{ {
gint n_addrs; int n_addrs;
/* First take a backtrace, so that backtrace_func() can overwrite /* First take a backtrace, so that backtrace_func() can overwrite
* a little bit of data *BEFORE* ev->addrs as stratch space. This * a little bit of data *BEFORE* ev->addrs as stratch space. This
@ -339,17 +339,17 @@ sysprof_collector_allocate (SysprofCaptureAddress alloc_addr,
void void
sysprof_collector_sample (SysprofBacktraceFunc backtrace_func, sysprof_collector_sample (SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data) void *backtrace_data)
{ {
COLLECTOR_BEGIN { COLLECTOR_BEGIN {
SysprofCaptureSample *ev; SysprofCaptureSample *ev;
gsize len; size_t len;
len = sizeof *ev + (sizeof (SysprofCaptureSample) * MAX_UNWIND_DEPTH); len = sizeof *ev + (sizeof (SysprofCaptureSample) * MAX_UNWIND_DEPTH);
if ((ev = mapped_ring_buffer_allocate (collector->buffer, len))) if ((ev = mapped_ring_buffer_allocate (collector->buffer, len)))
{ {
gint n_addrs; int n_addrs;
/* See comment from sysprof_collector_allocate(). */ /* See comment from sysprof_collector_allocate(). */
if (backtrace_func) if (backtrace_func)
@ -373,16 +373,16 @@ sysprof_collector_sample (SysprofBacktraceFunc backtrace_func,
} }
void void
sysprof_collector_mark (gint64 time, sysprof_collector_mark (int64_t time,
gint64 duration, int64_t duration,
const gchar *group, const char *group,
const gchar *mark, const char *mark,
const gchar *message) const char *message)
{ {
COLLECTOR_BEGIN { COLLECTOR_BEGIN {
SysprofCaptureMark *ev; SysprofCaptureMark *ev;
gsize len; size_t len;
gsize sl; size_t sl;
if (group == NULL) if (group == NULL)
group = ""; group = "";
@ -416,14 +416,14 @@ sysprof_collector_mark (gint64 time,
} }
void void
sysprof_collector_log (GLogLevelFlags severity, sysprof_collector_log (int severity,
const gchar *domain, const char *domain,
const gchar *message) const char *message)
{ {
COLLECTOR_BEGIN { COLLECTOR_BEGIN {
SysprofCaptureLog *ev; SysprofCaptureLog *ev;
gsize len; size_t len;
gsize sl; size_t sl;
if (domain == NULL) if (domain == NULL)
domain = ""; domain = "";
@ -455,17 +455,17 @@ sysprof_collector_log (GLogLevelFlags severity,
} }
void void
sysprof_collector_log_printf (GLogLevelFlags severity, sysprof_collector_log_printf (int severity,
const gchar *domain, const char *domain,
const gchar *format, const char *format,
...) ...)
{ {
COLLECTOR_BEGIN { COLLECTOR_BEGIN {
g_autofree gchar *formatted = NULL; g_autofree char *formatted = NULL;
SysprofCaptureLog *ev; SysprofCaptureLog *ev;
va_list args; va_list args;
gsize len; size_t len;
gsize sl; size_t sl;
va_start (args, format); va_start (args, format);
formatted = g_strdup_vprintf (format, args); formatted = g_strdup_vprintf (format, args);

View File

@ -64,26 +64,26 @@ SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_init (void); void sysprof_collector_init (void);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_allocate (SysprofCaptureAddress alloc_addr, void sysprof_collector_allocate (SysprofCaptureAddress alloc_addr,
gint64 alloc_size, int64_t alloc_size,
SysprofBacktraceFunc backtrace_func, SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data); void *backtrace_data);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_sample (SysprofBacktraceFunc backtrace_func, void sysprof_collector_sample (SysprofBacktraceFunc backtrace_func,
gpointer backtrace_data); void *backtrace_data);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_mark (gint64 time, void sysprof_collector_mark (int64_t time,
gint64 duration, int64_t duration,
const gchar *group, const char *group,
const gchar *mark, const char *mark,
const gchar *message); const char *message);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_log (GLogLevelFlags severity, void sysprof_collector_log (int severity,
const gchar *domain, const char *domain,
const gchar *message); const char *message);
SYSPROF_AVAILABLE_IN_3_38 SYSPROF_AVAILABLE_IN_3_38
void sysprof_collector_log_printf (GLogLevelFlags severity, void sysprof_collector_log_printf (int severity,
const gchar *domain, const char *domain,
const gchar *format, const char *format,
...) G_GNUC_PRINTF (3, 4); ...) G_GNUC_PRINTF (3, 4);
G_END_DECLS G_END_DECLS

View File

@ -77,7 +77,7 @@
* Returns: An fd if successful; otherwise -1 and errno is set. * Returns: An fd if successful; otherwise -1 and errno is set.
*/ */
int int
sysprof_memfd_create (const gchar *name) sysprof_memfd_create (const char *name)
{ {
#ifdef __NR_memfd_create #ifdef __NR_memfd_create
if (name == NULL) if (name == NULL)
@ -116,7 +116,7 @@ sysprof_memfd_create (const gchar *name)
* *
* Since: 3.36 * Since: 3.36
*/ */
gsize size_t
sysprof_getpagesize (void) sysprof_getpagesize (void)
{ {
return _sysprof_getpagesize (); return _sysprof_getpagesize ();

View File

@ -56,13 +56,16 @@
#pragma once #pragma once
#include <stdint.h>
#include <string.h>
#include "sysprof-version-macros.h" #include "sysprof-version-macros.h"
G_BEGIN_DECLS G_BEGIN_DECLS
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
int sysprof_memfd_create (const gchar *desc); int sysprof_memfd_create (const char *desc);
SYSPROF_AVAILABLE_IN_3_36 SYSPROF_AVAILABLE_IN_3_36
gsize sysprof_getpagesize (void); size_t sysprof_getpagesize (void);
G_END_DECLS G_END_DECLS