libsysprof-capture: Use assert() instead of g_assert()

Also use it instead of `g_return_if_fail()`.

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

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-01 16:26:15 +01:00
parent 5636bbf4f0
commit 8e28ac6e81
12 changed files with 349 additions and 271 deletions

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <assert.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
@ -54,7 +55,7 @@ typedef struct _MappedRingHeader
uint32_t size;
} MappedRingHeader;
G_STATIC_ASSERT (sizeof (MappedRingHeader) == 16);
static_assert (sizeof (MappedRingHeader) == 16, "MappedRingHeader changed size");
/*
* MappedRingBuffer is used to wrap both the reader and writer
@ -80,7 +81,7 @@ static inline void *
get_body_at_pos (MappedRingBuffer *self,
size_t pos)
{
g_assert (pos < (self->body_size + self->body_size));
assert (pos < (self->body_size + self->body_size));
return (uint8_t *)self->map + self->page_size + pos;
}
@ -132,7 +133,7 @@ map_head_and_body_twice (int fd,
return NULL;
}
g_assert (second == (void *)((uint8_t *)map + head_size + body_size));
assert (second == (void *)((uint8_t *)map + head_size + body_size));
return map;
}
@ -166,8 +167,8 @@ mapped_ring_buffer_new_reader (size_t buffer_size)
void *map;
int fd;
g_return_val_if_fail ((buffer_size % _sysprof_getpagesize ()) == 0, NULL);
g_return_val_if_fail (buffer_size < BUFFER_MAX_SIZE, NULL);
assert ((buffer_size % _sysprof_getpagesize ()) == 0);
assert (buffer_size < BUFFER_MAX_SIZE);
page_size = _sysprof_getpagesize ();
@ -243,7 +244,7 @@ mapped_ring_buffer_new_writer (int fd)
size_t page_size;
void *map;
g_return_val_if_fail (fd > -1, NULL);
assert (fd > -1);
page_size = _sysprof_getpagesize ();
@ -329,8 +330,8 @@ mapped_ring_buffer_finalize (MappedRingBuffer *self)
void
mapped_ring_buffer_unref (MappedRingBuffer *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
mapped_ring_buffer_finalize (self);
@ -339,8 +340,8 @@ mapped_ring_buffer_unref (MappedRingBuffer *self)
MappedRingBuffer *
mapped_ring_buffer_ref (MappedRingBuffer *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
@ -350,7 +351,7 @@ mapped_ring_buffer_ref (MappedRingBuffer *self)
int
mapped_ring_buffer_get_fd (MappedRingBuffer *self)
{
g_return_val_if_fail (self != NULL, -1);
assert (self != NULL);
return self->fd;
}
@ -386,11 +387,11 @@ mapped_ring_buffer_allocate (MappedRingBuffer *self,
uint32_t headpos;
uint32_t tailpos;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->mode & MODE_WRITER, NULL);
g_return_val_if_fail (length > 0, NULL);
g_return_val_if_fail (length < self->body_size, NULL);
g_return_val_if_fail ((length & 0x7) == 0, NULL);
assert (self != NULL);
assert (self->mode & MODE_WRITER);
assert (length > 0);
assert (length < self->body_size);
assert ((length & 0x7) == 0);
header = get_header (self);
headpos = g_atomic_int_get (&header->head);
@ -442,11 +443,11 @@ mapped_ring_buffer_advance (MappedRingBuffer *self,
MappedRingHeader *header;
uint32_t tail;
g_return_if_fail (self != NULL);
g_return_if_fail (self->mode & MODE_WRITER);
g_return_if_fail (length > 0);
g_return_if_fail (length < self->body_size);
g_return_if_fail ((length & 0x7) == 0);
assert (self != NULL);
assert (self->mode & MODE_WRITER);
assert (length > 0);
assert (length < self->body_size);
assert ((length & 0x7) == 0);
header = get_header (self);
tail = header->tail;
@ -487,16 +488,16 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
uint32_t headpos;
uint32_t tailpos;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (self->mode & MODE_READER, FALSE);
g_return_val_if_fail (callback != NULL, FALSE);
assert (self != NULL);
assert (self->mode & MODE_READER);
assert (callback != NULL);
header = get_header (self);
headpos = g_atomic_int_get (&header->head);
tailpos = g_atomic_int_get (&header->tail);
g_assert (headpos < self->body_size);
g_assert (tailpos < self->body_size);
assert (headpos < self->body_size);
assert (tailpos < self->body_size);
if (headpos == tailpos)
return true;
@ -507,7 +508,7 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
if (tailpos < headpos)
tailpos += self->body_size;
g_assert (headpos < tailpos);
assert (headpos < tailpos);
while (headpos < tailpos)
{
@ -571,7 +572,7 @@ mapped_ring_buffer_clear (MappedRingBuffer *self)
{
MappedRingHeader *header;
g_return_if_fail (self != NULL);
assert (self != NULL);
header = get_header (self);
header->head = 0;

View File

@ -56,6 +56,7 @@
#pragma once
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
@ -65,7 +66,8 @@ G_BEGIN_DECLS
typedef uint64_t SysprofAddress;
G_STATIC_ASSERT (sizeof (SysprofAddress) >= sizeof (void *));
static_assert (sizeof (SysprofAddress) >= sizeof (void *),
"Address space is too big");
typedef enum
{

View File

@ -58,10 +58,12 @@
#include "config.h"
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "sysprof-capture-condition.h"
#include "sysprof-macros-internal.h"
/**
* SECTION:sysprof-capture-condition
@ -109,8 +111,8 @@ bool
sysprof_capture_condition_match (const SysprofCaptureCondition *self,
const SysprofCaptureFrame *frame)
{
g_assert (self != NULL);
g_assert (frame != NULL);
assert (self != NULL);
assert (frame != NULL);
switch (self->type)
{
@ -192,7 +194,7 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
break;
}
g_assert_not_reached ();
sysprof_assert_not_reached ();
return false;
}
@ -250,7 +252,7 @@ sysprof_capture_condition_copy (const SysprofCaptureCondition *self)
break;
}
g_return_val_if_reached (NULL);
sysprof_assert_not_reached ();
}
static void
@ -288,7 +290,7 @@ sysprof_capture_condition_finalize (SysprofCaptureCondition *self)
break;
default:
g_assert_not_reached ();
sysprof_assert_not_reached ();
break;
}
@ -298,8 +300,8 @@ sysprof_capture_condition_finalize (SysprofCaptureCondition *self)
SysprofCaptureCondition *
sysprof_capture_condition_ref (SysprofCaptureCondition *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
return self;
@ -308,8 +310,8 @@ sysprof_capture_condition_ref (SysprofCaptureCondition *self)
void
sysprof_capture_condition_unref (SysprofCaptureCondition *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sysprof_capture_condition_finalize (self);
@ -321,7 +323,7 @@ sysprof_capture_condition_new_where_type_in (unsigned int n_ty
{
SysprofCaptureCondition *self;
g_return_val_if_fail (types != NULL, NULL);
assert (types != NULL);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN;
@ -359,7 +361,7 @@ sysprof_capture_condition_new_where_pid_in (unsigned int n_pids,
{
SysprofCaptureCondition *self;
g_return_val_if_fail (pids != NULL, NULL);
assert (pids != NULL);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN;
@ -376,7 +378,7 @@ sysprof_capture_condition_new_where_counter_in (unsigned int n_counters,
{
SysprofCaptureCondition *self;
g_return_val_if_fail (counters != NULL || n_counters == 0, NULL);
assert (counters != NULL || n_counters == 0);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_COUNTER_IN;
@ -407,8 +409,8 @@ sysprof_capture_condition_new_and (SysprofCaptureCondition *left,
{
SysprofCaptureCondition *self;
g_return_val_if_fail (left != NULL, NULL);
g_return_val_if_fail (right != NULL, NULL);
assert (left != NULL);
assert (right != NULL);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_AND;
@ -434,8 +436,8 @@ sysprof_capture_condition_new_or (SysprofCaptureCondition *left,
{
SysprofCaptureCondition *self;
g_return_val_if_fail (left != NULL, NULL);
g_return_val_if_fail (right != NULL, NULL);
assert (left != NULL);
assert (right != NULL);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_OR;
@ -459,7 +461,7 @@ sysprof_capture_condition_new_where_file (const char *path)
{
SysprofCaptureCondition *self;
g_return_val_if_fail (path != NULL, NULL);
assert (path != NULL);
self = sysprof_capture_condition_init ();
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_FILE;

View File

@ -58,6 +58,8 @@
#include "config.h"
#include <assert.h>
#include "sysprof-capture-condition.h"
#include "sysprof-capture-cursor.h"
#include "sysprof-capture-reader.h"
@ -105,8 +107,8 @@ sysprof_capture_cursor_init (void)
SysprofCaptureCursor *
sysprof_capture_cursor_ref (SysprofCaptureCursor *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
return self;
@ -121,8 +123,8 @@ sysprof_capture_cursor_ref (SysprofCaptureCursor *self)
void
sysprof_capture_cursor_unref (SysprofCaptureCursor *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sysprof_capture_cursor_finalize (self);
@ -140,9 +142,9 @@ sysprof_capture_cursor_foreach (SysprofCaptureCursor *self,
SysprofCaptureCursorCallback callback,
void *user_data)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->reader != NULL);
g_return_if_fail (callback != NULL);
assert (self != NULL);
assert (self->reader != NULL);
assert (callback != NULL);
for (;;)
{
@ -249,8 +251,8 @@ sysprof_capture_cursor_foreach (SysprofCaptureCursor *self,
void
sysprof_capture_cursor_reset (SysprofCaptureCursor *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->reader != NULL);
assert (self != NULL);
assert (self->reader != NULL);
sysprof_capture_reader_reset (self->reader);
}
@ -258,7 +260,7 @@ sysprof_capture_cursor_reset (SysprofCaptureCursor *self)
void
sysprof_capture_cursor_reverse (SysprofCaptureCursor *self)
{
g_return_if_fail (self != NULL);
assert (self != NULL);
self->reversed = !self->reversed;
}
@ -275,8 +277,8 @@ void
sysprof_capture_cursor_add_condition (SysprofCaptureCursor *self,
SysprofCaptureCondition *condition)
{
g_return_if_fail (self != NULL);
g_return_if_fail (condition != NULL);
assert (self != NULL);
assert (condition != NULL);
g_ptr_array_add (self->conditions, condition);
}
@ -292,7 +294,7 @@ sysprof_capture_cursor_new (SysprofCaptureReader *reader)
{
SysprofCaptureCursor *self;
g_return_val_if_fail (reader != NULL, NULL);
assert (reader != NULL);
self = sysprof_capture_cursor_init ();
self->reader = sysprof_capture_reader_copy (reader);
@ -311,7 +313,7 @@ sysprof_capture_cursor_new (SysprofCaptureReader *reader)
SysprofCaptureReader *
sysprof_capture_cursor_get_reader (SysprofCaptureCursor *self)
{
g_return_val_if_fail (self != NULL, NULL);
assert (self != NULL);
return self->reader;
}

View File

@ -58,6 +58,7 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@ -69,6 +70,7 @@
#include "sysprof-capture-reader.h"
#include "sysprof-capture-util-private.h"
#include "sysprof-capture-writer.h"
#include "sysprof-macros-internal.h"
struct _SysprofCaptureReader
{
@ -92,8 +94,8 @@ sysprof_capture_reader_read_file_header (SysprofCaptureReader *self,
SysprofCaptureFileHeader *header,
GError **error)
{
g_assert (self != NULL);
g_assert (header != NULL);
assert (self != NULL);
assert (header != NULL);
if (sizeof *header != _sysprof_pread (self->fd, header, sizeof *header, 0L))
{
@ -133,7 +135,7 @@ sysprof_capture_reader_finalize (SysprofCaptureReader *self)
const char *
sysprof_capture_reader_get_time (SysprofCaptureReader *self)
{
g_return_val_if_fail (self != NULL, NULL);
assert (self != NULL);
return self->header.capture_time;
}
@ -141,7 +143,7 @@ sysprof_capture_reader_get_time (SysprofCaptureReader *self)
const char *
sysprof_capture_reader_get_filename (SysprofCaptureReader *self)
{
g_return_val_if_fail (self != NULL, NULL);
assert (self != NULL);
return self->filename;
}
@ -151,7 +153,7 @@ sysprof_capture_reader_discover_end_time (SysprofCaptureReader *self)
{
SysprofCaptureFrame frame;
g_assert (self != NULL);
assert (self != NULL);
while (sysprof_capture_reader_peek_frame (self, &frame))
{
@ -212,7 +214,7 @@ sysprof_capture_reader_new_from_fd (int fd,
{
SysprofCaptureReader *self;
g_assert (fd > -1);
assert (fd > -1);
self = g_new0 (SysprofCaptureReader, 1);
self->ref_count = 1;
@ -251,7 +253,7 @@ sysprof_capture_reader_new (const char *filename,
SysprofCaptureReader *self;
int fd;
g_assert (filename != NULL);
assert (filename != NULL);
if (-1 == (fd = open (filename, O_RDONLY, 0)))
{
@ -277,8 +279,8 @@ static inline void
sysprof_capture_reader_bswap_frame (SysprofCaptureReader *self,
SysprofCaptureFrame *frame)
{
g_assert (self != NULL);
g_assert (frame!= NULL);
assert (self != NULL);
assert (frame!= NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
@ -293,8 +295,8 @@ static inline void
sysprof_capture_reader_bswap_file_chunk (SysprofCaptureReader *self,
SysprofCaptureFileChunk *file_chunk)
{
g_assert (self != NULL);
g_assert (file_chunk != NULL);
assert (self != NULL);
assert (file_chunk != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
file_chunk->len = GUINT16_SWAP_LE_BE (file_chunk->len);
@ -304,8 +306,8 @@ static inline void
sysprof_capture_reader_bswap_log (SysprofCaptureReader *self,
SysprofCaptureLog *log)
{
g_assert (self != NULL);
g_assert (log != NULL);
assert (self != NULL);
assert (log != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
log->severity = GUINT16_SWAP_LE_BE (log->severity);
@ -315,8 +317,8 @@ static inline void
sysprof_capture_reader_bswap_map (SysprofCaptureReader *self,
SysprofCaptureMap *map)
{
g_assert (self != NULL);
g_assert (map != NULL);
assert (self != NULL);
assert (map != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
{
@ -331,8 +333,8 @@ static inline void
sysprof_capture_reader_bswap_mark (SysprofCaptureReader *self,
SysprofCaptureMark *mark)
{
g_assert (self != NULL);
g_assert (mark != NULL);
assert (self != NULL);
assert (mark != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
mark->duration = GUINT64_SWAP_LE_BE (mark->duration);
@ -342,8 +344,8 @@ static inline void
sysprof_capture_reader_bswap_jitmap (SysprofCaptureReader *self,
SysprofCaptureJitmap *jitmap)
{
g_assert (self != NULL);
g_assert (jitmap != NULL);
assert (self != NULL);
assert (jitmap != NULL);
if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
jitmap->n_jitmaps = GUINT64_SWAP_LE_BE (jitmap->n_jitmaps);
@ -353,9 +355,9 @@ static bool
sysprof_capture_reader_ensure_space_for (SysprofCaptureReader *self,
size_t len)
{
g_assert (self != NULL);
g_assert (self->pos <= self->len);
g_assert (len > 0);
assert (self != NULL);
assert (self->pos <= self->len);
assert (len > 0);
/* Ensure alignment of length to read */
len = (len + SYSPROF_CAPTURE_ALIGN - 1) & ~(SYSPROF_CAPTURE_ALIGN - 1);
@ -371,8 +373,8 @@ sysprof_capture_reader_ensure_space_for (SysprofCaptureReader *self,
while (self->len < len)
{
g_assert ((self->pos + self->len) < self->bufsz);
g_assert (self->len < self->bufsz);
assert ((self->pos + self->len) < self->bufsz);
assert (self->len < self->bufsz);
/* Read into our buffer after our current read position */
r = _sysprof_pread (self->fd,
@ -396,8 +398,8 @@ sysprof_capture_reader_skip (SysprofCaptureReader *self)
{
SysprofCaptureFrame *frame;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof (SysprofCaptureFrame)))
return false;
@ -427,15 +429,15 @@ sysprof_capture_reader_peek_frame (SysprofCaptureReader *self,
{
SysprofCaptureFrame *real_frame;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->len);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->len);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *real_frame))
return false;
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
real_frame = (SysprofCaptureFrame *)(void *)&self->buf[self->pos];
@ -459,8 +461,8 @@ sysprof_capture_reader_peek_type (SysprofCaptureReader *self,
{
SysprofCaptureFrame frame;
g_assert (self != NULL);
g_assert (type != NULL);
assert (self != NULL);
assert (type != NULL);
if (!sysprof_capture_reader_peek_frame (self, &frame))
return false;
@ -478,9 +480,9 @@ sysprof_capture_reader_read_basic (SysprofCaptureReader *self,
SysprofCaptureFrame *frame;
size_t len = sizeof *frame + extra;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, len))
return NULL;
@ -522,7 +524,7 @@ sysprof_capture_reader_read_fork (SysprofCaptureReader *self)
{
SysprofCaptureFork *fk;
g_assert (self != NULL);
assert (self != NULL);
fk = (SysprofCaptureFork *)
sysprof_capture_reader_read_basic (self, SYSPROF_CAPTURE_FRAME_FORK, sizeof (uint32_t));
@ -541,9 +543,9 @@ sysprof_capture_reader_read_map (SysprofCaptureReader *self)
{
SysprofCaptureMap *map;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *map))
return NULL;
@ -581,9 +583,9 @@ sysprof_capture_reader_read_log (SysprofCaptureReader *self)
{
SysprofCaptureLog *log;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *log))
return NULL;
@ -623,9 +625,9 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
{
SysprofCaptureMark *mark;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *mark))
return NULL;
@ -669,9 +671,9 @@ sysprof_capture_reader_read_metadata (SysprofCaptureReader *self)
{
SysprofCaptureMetadata *metadata;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *metadata))
return NULL;
@ -709,9 +711,9 @@ sysprof_capture_reader_read_process (SysprofCaptureReader *self)
{
SysprofCaptureProcess *process;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *process))
return NULL;
@ -751,9 +753,9 @@ sysprof_capture_reader_read_jitmap (SysprofCaptureReader *self)
uint8_t *endptr;
unsigned int i;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *jitmap))
return NULL;
@ -813,9 +815,9 @@ sysprof_capture_reader_read_sample (SysprofCaptureReader *self)
{
SysprofCaptureSample *sample;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *sample))
return NULL;
@ -859,9 +861,9 @@ sysprof_capture_reader_read_counter_define (SysprofCaptureReader *self)
{
SysprofCaptureCounterDefine *def;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *def))
return NULL;
@ -906,9 +908,9 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
{
SysprofCaptureCounterSet *set;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *set))
return NULL;
@ -956,7 +958,7 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
bool
sysprof_capture_reader_reset (SysprofCaptureReader *self)
{
g_assert (self != NULL);
assert (self != NULL);
self->fd_off = sizeof (SysprofCaptureFileHeader);
self->pos = 0;
@ -968,8 +970,8 @@ sysprof_capture_reader_reset (SysprofCaptureReader *self)
SysprofCaptureReader *
sysprof_capture_reader_ref (SysprofCaptureReader *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
@ -979,8 +981,8 @@ sysprof_capture_reader_ref (SysprofCaptureReader *self)
void
sysprof_capture_reader_unref (SysprofCaptureReader *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sysprof_capture_reader_finalize (self);
@ -991,9 +993,9 @@ sysprof_capture_reader_splice (SysprofCaptureReader *self,
SysprofCaptureWriter *dest,
GError **error)
{
g_assert (self != NULL);
g_assert (self->fd != -1);
g_assert (dest != NULL);
assert (self != NULL);
assert (self->fd != -1);
assert (dest != NULL);
/* Flush before writing anything to ensure consistency */
if (!sysprof_capture_writer_flush (dest))
@ -1035,8 +1037,8 @@ sysprof_capture_reader_save_as (SysprofCaptureReader *self,
size_t to_write;
int fd = -1;
g_assert (self != NULL);
g_assert (filename != NULL);
assert (self != NULL);
assert (filename != NULL);
if (-1 == (fd = open (filename, O_CREAT | O_WRONLY, 0640)))
goto handle_errno;
@ -1065,7 +1067,7 @@ sysprof_capture_reader_save_as (SysprofCaptureReader *self,
if (written == 0 && errno != EAGAIN)
goto handle_errno;
g_assert (written <= (ssize_t)to_write);
assert (written <= (ssize_t)to_write);
to_write -= written;
}
@ -1092,7 +1094,7 @@ handle_errno:
int64_t
sysprof_capture_reader_get_start_time (SysprofCaptureReader *self)
{
g_return_val_if_fail (self != NULL, 0);
assert (self != NULL);
if (self->endian != G_BYTE_ORDER)
return GUINT64_SWAP_LE_BE (self->header.time);
@ -1120,7 +1122,7 @@ sysprof_capture_reader_get_end_time (SysprofCaptureReader *self)
{
int64_t end_time = 0;
g_return_val_if_fail (self != NULL, 0);
assert (self != NULL);
if (self->header.end_time != 0)
{
@ -1149,7 +1151,7 @@ sysprof_capture_reader_copy (SysprofCaptureReader *self)
SysprofCaptureReader *copy;
int fd;
g_return_val_if_fail (self != NULL, NULL);
assert (self != NULL);
if (-1 == (fd = dup (self->fd)))
return NULL;
@ -1175,7 +1177,7 @@ void
sysprof_capture_reader_set_stat (SysprofCaptureReader *self,
const SysprofCaptureStat *st_buf)
{
g_return_if_fail (self != NULL);
assert (self != NULL);
if (st_buf != NULL)
{
@ -1193,7 +1195,7 @@ bool
sysprof_capture_reader_get_stat (SysprofCaptureReader *self,
SysprofCaptureStat *st_buf)
{
g_return_val_if_fail (self != NULL, FALSE);
assert (self != NULL);
if (st_buf != NULL)
*st_buf = self->st_buf;
@ -1206,9 +1208,9 @@ sysprof_capture_reader_read_file (SysprofCaptureReader *self)
{
SysprofCaptureFileChunk *file_chunk;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *file_chunk))
return NULL;
@ -1254,7 +1256,7 @@ sysprof_capture_reader_list_files (SysprofCaptureReader *self)
GHashTableIter iter;
const gchar *key;
g_assert (self != NULL);
assert (self != NULL);
ar = g_ptr_array_new_with_free_func (g_free);
files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@ -1289,9 +1291,9 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
const char *path,
int fd)
{
g_assert (self != NULL);
g_assert (path != NULL);
g_assert (fd > -1);
assert (self != NULL);
assert (path != NULL);
assert (fd > -1);
for (;;)
{
@ -1326,7 +1328,7 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
if (written == 0 && errno != EAGAIN)
return false;
g_assert (written <= (ssize_t)to_write);
assert (written <= (ssize_t)to_write);
buf += written;
to_write -= written;
@ -1342,13 +1344,13 @@ sysprof_capture_reader_read_file_fd (SysprofCaptureReader *self,
return false;
}
g_return_val_if_reached (FALSE);
sysprof_assert_not_reached ();
}
int
sysprof_capture_reader_get_byte_order (SysprofCaptureReader *self)
{
g_return_val_if_fail (self != NULL, 0);
assert (self != NULL);
return self->endian;
}
@ -1359,8 +1361,8 @@ sysprof_capture_reader_find_file (SysprofCaptureReader *self,
{
SysprofCaptureFrameType type;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
assert (self != NULL);
assert (path != NULL);
while (sysprof_capture_reader_peek_type (self, &type))
{
@ -1389,9 +1391,9 @@ sysprof_capture_reader_read_allocation (SysprofCaptureReader *self)
{
SysprofCaptureAllocation *ma;
g_assert (self != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
g_assert (self->pos <= self->bufsz);
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *ma))
return NULL;

View File

@ -56,6 +56,7 @@
#pragma once
#include <assert.h>
#include <glib.h>
#include <inttypes.h>
#include <stddef.h>
@ -331,27 +332,27 @@ typedef struct
} SysprofCaptureAllocation
SYSPROF_ALIGNED_END(1);
G_STATIC_ASSERT (sizeof (SysprofCaptureFileHeader) == 256);
G_STATIC_ASSERT (sizeof (SysprofCaptureFrame) == 24);
G_STATIC_ASSERT (sizeof (SysprofCaptureMap) == 56);
G_STATIC_ASSERT (sizeof (SysprofCaptureJitmap) == 28);
G_STATIC_ASSERT (sizeof (SysprofCaptureProcess) == 24);
G_STATIC_ASSERT (sizeof (SysprofCaptureSample) == 32);
G_STATIC_ASSERT (sizeof (SysprofCaptureFork) == 28);
G_STATIC_ASSERT (sizeof (SysprofCaptureExit) == 24);
G_STATIC_ASSERT (sizeof (SysprofCaptureTimestamp) == 24);
G_STATIC_ASSERT (sizeof (SysprofCaptureCounter) == 128);
G_STATIC_ASSERT (sizeof (SysprofCaptureCounterValues) == 96);
G_STATIC_ASSERT (sizeof (SysprofCaptureCounterDefine) == 32);
G_STATIC_ASSERT (sizeof (SysprofCaptureCounterSet) == 32);
G_STATIC_ASSERT (sizeof (SysprofCaptureMark) == 96);
G_STATIC_ASSERT (sizeof (SysprofCaptureMetadata) == 64);
G_STATIC_ASSERT (sizeof (SysprofCaptureLog) == 64);
G_STATIC_ASSERT (sizeof (SysprofCaptureFileChunk) == 284);
G_STATIC_ASSERT (sizeof (SysprofCaptureAllocation) == 48);
static_assert (sizeof (SysprofCaptureFileHeader) == 256, "SysprofCaptureFileHeader changed size");
static_assert (sizeof (SysprofCaptureFrame) == 24, "SysprofCaptureFrame changed size");
static_assert (sizeof (SysprofCaptureMap) == 56, "SysprofCaptureMap changed size");
static_assert (sizeof (SysprofCaptureJitmap) == 28, "SysprofCaptureJitmap changed size");
static_assert (sizeof (SysprofCaptureProcess) == 24, "SysprofCaptureProcess changed size");
static_assert (sizeof (SysprofCaptureSample) == 32, "SysprofCaptureSample changed size");
static_assert (sizeof (SysprofCaptureFork) == 28, "SysprofCaptureFork changed size");
static_assert (sizeof (SysprofCaptureExit) == 24, "SysprofCaptureExit changed size");
static_assert (sizeof (SysprofCaptureTimestamp) == 24, "SysprofCaptureTimestamp changed size");
static_assert (sizeof (SysprofCaptureCounter) == 128, "SysprofCaptureCounter changed size");
static_assert (sizeof (SysprofCaptureCounterValues) == 96, "SysprofCaptureCounterValues changed size");
static_assert (sizeof (SysprofCaptureCounterDefine) == 32, "SysprofCaptureCounterDefine changed size");
static_assert (sizeof (SysprofCaptureCounterSet) == 32, "SysprofCaptureCounterSet changed size");
static_assert (sizeof (SysprofCaptureMark) == 96, "SysprofCaptureMark changed size");
static_assert (sizeof (SysprofCaptureMetadata) == 64, "SysprofCaptureMetadata changed size");
static_assert (sizeof (SysprofCaptureLog) == 64, "SysprofCaptureLog changed size");
static_assert (sizeof (SysprofCaptureFileChunk) == 284, "SysprofCaptureFileChunk changed size");
static_assert (sizeof (SysprofCaptureAllocation) == 48, "SysprofCaptureAllocation changed size");
G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0);
G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0);
static_assert ((offsetof (SysprofCaptureAllocation, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureAllocation.addrs is not aligned");
static_assert ((offsetof (SysprofCaptureSample, addrs) % SYSPROF_CAPTURE_ALIGN) == 0, "SysprofCaptureSample.addrs is not aligned");
static inline int
sysprof_capture_address_compare (SysprofCaptureAddress a,

View File

@ -58,6 +58,7 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <glib.h>
#include <unistd.h>
@ -205,14 +206,14 @@ ssize_t
if (n_read <= 0)
return -1;
g_assert (count >= n_read);
assert (count >= n_read);
count -= n_read;
rpos += n_read;
while (wpos < rpos)
{
g_assert (off < sizeof buf);
assert (off < sizeof buf);
errno = 0;
n_written = write (out_fd, &buf[off], rpos - wpos);
@ -226,7 +227,7 @@ ssize_t
}
}
g_assert (count == 0);
assert (count == 0);
if (offset != NULL)
*offset = rpos;

View File

@ -158,8 +158,8 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
int64_t first_start_time = INT64_MAX;
int64_t end_time = -1;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (reader != NULL, FALSE);
assert (self != NULL);
assert (reader != NULL);
sysprof_capture_reader_reset (reader);
@ -459,7 +459,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter *self,
}
}
g_assert (ids->len == values->len);
assert (ids->len == values->len);
sysprof_capture_writer_set_counters (self,
frame->frame.time,

View File

@ -62,6 +62,7 @@
# define _GNU_SOURCE
#endif
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <glib/gstdio.h>
@ -75,6 +76,7 @@
#include "sysprof-capture-reader.h"
#include "sysprof-capture-util-private.h"
#include "sysprof-capture-writer.h"
#include "sysprof-macros-internal.h"
#define DEFAULT_BUFFER_SIZE (_sysprof_getpagesize() * 64L)
#define INVALID_ADDRESS (G_GUINT64_CONSTANT(0))
@ -153,7 +155,7 @@ sysprof_capture_writer_frame_init (SysprofCaptureFrame *frame_,
int64_t time_,
SysprofCaptureFrameType type)
{
g_assert (frame_ != NULL);
assert (frame_ != NULL);
frame_->len = len;
frame_->cpu = cpu;
@ -187,8 +189,8 @@ sysprof_capture_writer_finalize (SysprofCaptureWriter *self)
SysprofCaptureWriter *
sysprof_capture_writer_ref (SysprofCaptureWriter *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
@ -198,8 +200,8 @@ sysprof_capture_writer_ref (SysprofCaptureWriter *self)
void
sysprof_capture_writer_unref (SysprofCaptureWriter *self)
{
g_assert (self != NULL);
g_assert (self->ref_count > 0);
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
sysprof_capture_writer_finalize (self);
@ -212,9 +214,9 @@ sysprof_capture_writer_flush_data (SysprofCaptureWriter *self)
ssize_t written;
size_t to_write;
g_assert (self != NULL);
g_assert (self->pos <= self->len);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self != NULL);
assert (self->pos <= self->len);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
if (self->pos == 0)
return true;
@ -231,7 +233,7 @@ sysprof_capture_writer_flush_data (SysprofCaptureWriter *self)
if (written == 0 && errno != EAGAIN)
return false;
g_assert (written <= (ssize_t)to_write);
assert (written <= (ssize_t)to_write);
buf += written;
to_write -= written;
@ -271,9 +273,9 @@ sysprof_capture_writer_allocate (SysprofCaptureWriter *self,
{
void *p;
g_assert (self != NULL);
g_assert (len != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self != NULL);
assert (len != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
sysprof_capture_writer_realign (len);
@ -284,7 +286,7 @@ sysprof_capture_writer_allocate (SysprofCaptureWriter *self,
self->pos += *len;
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
return p;
}
@ -296,12 +298,12 @@ sysprof_capture_writer_flush_jitmap (SysprofCaptureWriter *self)
ssize_t r;
size_t len;
g_assert (self != NULL);
assert (self != NULL);
if (self->addr_hash_size == 0)
return true;
g_assert (self->addr_buf_pos > 0);
assert (self->addr_buf_pos > 0);
len = sizeof jitmap + self->addr_buf_pos;
@ -339,9 +341,9 @@ sysprof_capture_writer_lookup_jitmap (SysprofCaptureWriter *self,
unsigned int hash;
unsigned int i;
g_assert (self != NULL);
g_assert (name != NULL);
g_assert (addr != NULL);
assert (self != NULL);
assert (name != NULL);
assert (addr != NULL);
hash = g_str_hash (name) % G_N_ELEMENTS (self->addr_hash);
@ -386,9 +388,9 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
unsigned int hash;
unsigned int i;
g_assert (self != NULL);
g_assert (str != NULL);
g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self != NULL);
assert (str != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
len = sizeof addr + strlen (str) + 1;
@ -398,12 +400,12 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
if (!sysprof_capture_writer_flush_jitmap (self))
return INVALID_ADDRESS;
g_assert (self->addr_hash_size == 0);
g_assert (self->addr_buf_pos == 0);
assert (self->addr_hash_size == 0);
assert (self->addr_buf_pos == 0);
}
g_assert (self->addr_hash_size < G_N_ELEMENTS (self->addr_hash));
g_assert (len > sizeof addr);
assert (self->addr_hash_size < G_N_ELEMENTS (self->addr_hash));
assert (len > sizeof addr);
/* Allocate the next unique address */
addr = SYSPROF_CAPTURE_JITMAP_MARK | ++self->addr_seq;
@ -421,7 +423,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
/* Advance our string cache position */
self->addr_buf_pos += len;
g_assert (self->addr_buf_pos <= sizeof self->addr_buf);
assert (self->addr_buf_pos <= sizeof self->addr_buf);
/* Now place the address into the hashtable */
hash = g_str_hash (str) % G_N_ELEMENTS (self->addr_hash);
@ -454,7 +456,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
}
}
g_assert_not_reached ();
sysprof_assert_not_reached ();
return INVALID_ADDRESS;
}
@ -475,8 +477,8 @@ sysprof_capture_writer_new_from_fd (int fd,
if (buffer_size == 0)
buffer_size = DEFAULT_BUFFER_SIZE;
g_assert (fd != -1);
g_assert (buffer_size % _sysprof_getpagesize() == 0);
assert (fd != -1);
assert (buffer_size % _sysprof_getpagesize() == 0);
/* This is only useful on files, memfd, etc */
if (ftruncate (fd, 0) != 0) { /* Do Nothing */ }
@ -528,12 +530,12 @@ sysprof_capture_writer_new_from_fd (int fd,
return NULL;
}
g_assert (self->pos == 0);
g_assert (self->len > 0);
g_assert (self->len % _sysprof_getpagesize() == 0);
g_assert (self->buf != NULL);
g_assert (self->addr_hash_size == 0);
g_assert (self->fd != -1);
assert (self->pos == 0);
assert (self->len > 0);
assert (self->len % _sysprof_getpagesize() == 0);
assert (self->buf != NULL);
assert (self->addr_hash_size == 0);
assert (self->fd != -1);
return self;
}
@ -545,8 +547,8 @@ sysprof_capture_writer_new (const char *filename,
SysprofCaptureWriter *self;
int fd;
g_assert (filename != NULL);
g_assert (buffer_size % _sysprof_getpagesize() == 0);
assert (filename != NULL);
assert (buffer_size % _sysprof_getpagesize() == 0);
if ((-1 == (fd = open (filename, O_CREAT | O_RDWR, 0640))) ||
(-1 == ftruncate (fd, 0L)))
@ -577,8 +579,8 @@ sysprof_capture_writer_add_map (SysprofCaptureWriter *self,
if (filename == NULL)
filename = "";
g_assert (self != NULL);
g_assert (filename != NULL);
assert (self != NULL);
assert (filename != NULL);
len = sizeof *ev + strlen (filename) + 1;
@ -619,9 +621,9 @@ sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
size_t message_len;
size_t len;
g_assert (self != NULL);
g_assert (name != NULL);
g_assert (group != NULL);
assert (self != NULL);
assert (name != NULL);
assert (group != NULL);
if (message == NULL)
message = "";
@ -661,8 +663,8 @@ sysprof_capture_writer_add_metadata (SysprofCaptureWriter *self,
SysprofCaptureMetadata *ev;
size_t len;
g_assert (self != NULL);
g_assert (id != NULL);
assert (self != NULL);
assert (id != NULL);
if (metadata == NULL)
{
@ -703,8 +705,8 @@ sysprof_capture_writer_add_jitmap (SysprofCaptureWriter *self,
if (name == NULL)
name = "";
g_assert (self != NULL);
g_assert (name != NULL);
assert (self != NULL);
assert (name != NULL);
if (!sysprof_capture_writer_lookup_jitmap (self, name, &addr))
addr = sysprof_capture_writer_insert_jitmap (self, name);
@ -725,8 +727,8 @@ sysprof_capture_writer_add_process (SysprofCaptureWriter *self,
if (cmdline == NULL)
cmdline = "";
g_assert (self != NULL);
g_assert (cmdline != NULL);
assert (self != NULL);
assert (cmdline != NULL);
len = sizeof *ev + strlen (cmdline) + 1;
@ -761,7 +763,7 @@ sysprof_capture_writer_add_sample (SysprofCaptureWriter *self,
SysprofCaptureSample *ev;
size_t len;
g_assert (self != NULL);
assert (self != NULL);
len = sizeof *ev + (n_addrs * sizeof (SysprofCaptureAddress));
@ -795,7 +797,7 @@ sysprof_capture_writer_add_fork (SysprofCaptureWriter *self,
SysprofCaptureFork *ev;
size_t len = sizeof *ev;
g_assert (self != NULL);
assert (self != NULL);
ev = (SysprofCaptureFork *)sysprof_capture_writer_allocate (self, &len);
if (!ev)
@ -823,7 +825,7 @@ sysprof_capture_writer_add_exit (SysprofCaptureWriter *self,
SysprofCaptureExit *ev;
size_t len = sizeof *ev;
g_assert (self != NULL);
assert (self != NULL);
ev = (SysprofCaptureExit *)sysprof_capture_writer_allocate (self, &len);
if (!ev)
@ -850,7 +852,7 @@ sysprof_capture_writer_add_timestamp (SysprofCaptureWriter *self,
SysprofCaptureTimestamp *ev;
size_t len = sizeof *ev;
g_assert (self != NULL);
assert (self != NULL);
ev = (SysprofCaptureTimestamp *)sysprof_capture_writer_allocate (self, &len);
if (!ev)
@ -874,7 +876,7 @@ sysprof_capture_writer_flush_end_time (SysprofCaptureWriter *self)
int64_t end_time = SYSPROF_CAPTURE_CURRENT_TIME;
ssize_t ret;
g_assert (self != NULL);
assert (self != NULL);
/* This field is opportunistic, so a failure is okay. */
@ -893,7 +895,7 @@ again:
bool
sysprof_capture_writer_flush (SysprofCaptureWriter *self)
{
g_assert (self != NULL);
assert (self != NULL);
return sysprof_capture_writer_flush_jitmap (self) &&
sysprof_capture_writer_flush_data (self) &&
@ -923,9 +925,9 @@ sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
off_t pos;
int fd = -1;
g_assert (self != NULL);
g_assert (self->fd != -1);
g_assert (filename != NULL);
assert (self != NULL);
assert (self->fd != -1);
assert (filename != NULL);
if (-1 == (fd = open (filename, O_CREAT | O_RDWR, 0640)))
goto handle_errno;
@ -951,7 +953,7 @@ sysprof_capture_writer_save_as (SysprofCaptureWriter *self,
if (written == 0 && errno != EAGAIN)
goto handle_errno;
g_assert (written <= (ssize_t)to_write);
assert (written <= (ssize_t)to_write);
to_write -= written;
}
@ -1000,8 +1002,8 @@ _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
off_t in_off;
size_t to_write;
g_assert (self != NULL);
g_assert (self->fd != -1);
assert (self != NULL);
assert (self->fd != -1);
if (-1 == fstat (fd, &stbuf))
goto handle_errno;
@ -1030,7 +1032,7 @@ _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter *self,
if (written == 0 && errno != EAGAIN)
goto handle_errno;
g_assert (written <= (ssize_t)to_write);
assert (written <= (ssize_t)to_write);
to_write -= written;
}
@ -1067,10 +1069,10 @@ sysprof_capture_writer_splice (SysprofCaptureWriter *self,
bool ret;
off_t pos;
g_assert (self != NULL);
g_assert (self->fd != -1);
g_assert (dest != NULL);
g_assert (dest->fd != -1);
assert (self != NULL);
assert (self->fd != -1);
assert (dest != NULL);
assert (dest->fd != -1);
/* Flush before writing anything to ensure consistency */
if (!sysprof_capture_writer_flush (self) || !sysprof_capture_writer_flush (dest))
@ -1122,8 +1124,8 @@ sysprof_capture_writer_create_reader (SysprofCaptureWriter *self,
SysprofCaptureReader *ret;
int copy;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->fd != -1, NULL);
assert (self != NULL);
assert (self->fd != -1);
if (!sysprof_capture_writer_flush (self))
{
@ -1159,8 +1161,8 @@ void
sysprof_capture_writer_stat (SysprofCaptureWriter *self,
SysprofCaptureStat *stat)
{
g_return_if_fail (self != NULL);
g_return_if_fail (stat != NULL);
assert (self != NULL);
assert (stat != NULL);
*stat = self->stat;
}
@ -1177,8 +1179,8 @@ sysprof_capture_writer_define_counters (SysprofCaptureWriter *self,
size_t len;
unsigned int i;
g_assert (self != NULL);
g_assert (counters != NULL);
assert (self != NULL);
assert (counters != NULL);
if (n_counters == 0)
return true;
@ -1231,9 +1233,9 @@ sysprof_capture_writer_set_counters (SysprofCaptureWriter *self,
unsigned int field;
unsigned int i;
g_assert (self != NULL);
g_assert (counters_ids != NULL || n_counters == 0);
g_assert (values != NULL || !n_counters);
assert (self != NULL);
assert (counters_ids != NULL || n_counters == 0);
assert (values != NULL || !n_counters);
if (n_counters == 0)
return true;
@ -1299,7 +1301,7 @@ sysprof_capture_writer_request_counter (SysprofCaptureWriter *self,
{
int ret;
g_assert (self != NULL);
assert (self != NULL);
if (MAX_COUNTERS - n_counters < self->next_counter_id)
return 0;
@ -1317,7 +1319,7 @@ _sysprof_capture_writer_set_time_range (SysprofCaptureWriter *self,
{
ssize_t ret;
g_assert (self != NULL);
assert (self != NULL);
do_start:
ret = _sysprof_pwrite (self->fd,
@ -1365,7 +1367,7 @@ sysprof_capture_writer_new_from_env (size_t buffer_size)
size_t
sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter *self)
{
g_return_val_if_fail (self != NULL, 0);
assert (self != NULL);
return self->len;
}
@ -1383,7 +1385,7 @@ sysprof_capture_writer_add_log (SysprofCaptureWriter *self,
size_t message_len;
size_t len;
g_assert (self != NULL);
assert (self != NULL);
if (domain == NULL)
domain = "";
@ -1428,7 +1430,7 @@ sysprof_capture_writer_add_file (SysprofCaptureWriter *self,
SysprofCaptureFileChunk *ev;
size_t len;
g_assert (self != NULL);
assert (self != NULL);
len = sizeof *ev + data_len;
ev = (SysprofCaptureFileChunk *)sysprof_capture_writer_allocate (self, &len);
@ -1463,7 +1465,7 @@ sysprof_capture_writer_add_file_fd (SysprofCaptureWriter *self,
{
uint8_t data[(4096*4L) - sizeof(SysprofCaptureFileChunk)];
g_assert (self != NULL);
assert (self != NULL);
for (;;)
{
@ -1538,8 +1540,8 @@ sysprof_capture_writer_add_allocation (SysprofCaptureWriter *self,
size_t len;
unsigned int n_addrs;
g_assert (self != NULL);
g_assert (backtrace_func != NULL);
assert (self != NULL);
assert (backtrace_func != NULL);
len = sizeof *ev + (MAX_UNWIND_DEPTH * sizeof (SysprofCaptureAddress));
ev = (SysprofCaptureAllocation *)sysprof_capture_writer_allocate (self, &len);
@ -1591,7 +1593,7 @@ sysprof_capture_writer_add_allocation_copy (SysprofCaptureWriter *self,
SysprofCaptureAllocation *ev;
size_t len;
g_assert (self != NULL);
assert (self != NULL);
if (n_addrs > 0xFFF)
n_addrs = 0xFFF;
@ -1628,17 +1630,17 @@ _sysprof_capture_writer_add_raw (SysprofCaptureWriter *self,
void *begin;
size_t len;
g_assert (self != NULL);
g_assert ((fr->len & 0x7) == 0);
g_assert (fr->type < SYSPROF_CAPTURE_FRAME_LAST);
assert (self != NULL);
assert ((fr->len & 0x7) == 0);
assert (fr->type < SYSPROF_CAPTURE_FRAME_LAST);
len = fr->len;
if (!(begin = sysprof_capture_writer_allocate (self, &len)))
return false;
g_assert (fr->len == len);
g_assert (fr->type < 16);
assert (fr->len == len);
assert (fr->type < 16);
memcpy (begin, fr, fr->len);

View File

@ -58,9 +58,11 @@
#include "config.h"
#include <assert.h>
#include <stdbool.h>
#include "sysprof-clock.h"
#include "sysprof-macros-internal.h"
int sysprof_clock = -1;
@ -92,5 +94,5 @@ sysprof_clock_init (void)
}
}
g_assert_not_reached ();
sysprof_assert_not_reached ();
}

View File

@ -60,6 +60,7 @@
# define _GNU_SOURCE
#endif
#include <assert.h>
#include <glib-unix.h>
#include <gio/gio.h>
#include <gio/gunixconnection.h>
@ -185,7 +186,7 @@ write_final_frame (MappedRingBuffer *ring)
{
SysprofCaptureFrame *fr;
g_assert (ring != NULL);
assert (ring != NULL);
if ((fr = mapped_ring_buffer_allocate (ring, sizeof *fr)))
{

View File

@ -0,0 +1,62 @@
/* sysprof-macros.h
*
* Copyright 2020 Endless OS Foundation
*
* Author:
* - Philip Withnall <withnall@endlessm.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Subject to the terms and conditions of this license, each copyright holder
* and contributor hereby grants to those receiving rights under this license
* a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
* irrevocable (except for failure to satisfy the conditions of this license)
* patent license to make, have made, use, offer to sell, sell, import, and
* otherwise transfer this software, where such license applies only to those
* patent claims, already acquired or hereafter acquired, licensable by such
* copyright holder or contributor that are necessarily infringed by:
*
* (a) their Contribution(s) (the licensed copyrights of copyright holders
* and non-copyrightable additions of contributors, in source or binary
* form) alone; or
*
* (b) combination of their Contribution(s) with the work of authorship to
* which such Contribution(s) was added by such copyright holder or
* contributor, if, at the time the Contribution is added, such addition
* causes such combination to be necessarily infringed. The patent license
* shall not apply to any other combinations which include the
* Contribution.
*
* Except as expressly stated above, no rights or licenses from any copyright
* holder or contributor is granted under this license, whether expressly, by
* implication, estoppel or otherwise.
*
* DISCLAIMER
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
#pragma once
#define sysprof_assert_not_reached() assert (false)