Commit Graph

163 Commits

Author SHA1 Message Date
6fde9c5ce6 libsysprof-capture: Add sysprof_collector_mark_{v,}printf() methods
These are just like `sysprof_collector_mark()`, but do the printf
formatting of the message internally, and only once the collector has
been fetched — so there is no overhead from the printf if sysprof is not
enabled at runtime.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-03 22:01:33 +01:00
d6e8d39292 build: Add subproject support for libsysprof-capture
This will be used to build libsysprof-capture as a subproject within
libglib, with the symbols from libglib being left unresolved until the
static libsysprof-capture is linked into libglib.

When built as a subproject, libsysprof-capture won’t install anything.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-03 22:01:33 +01:00
484bc328ee collector: set unlikely for pthread_once() 2020-07-03 22:00:34 +01:00
5d20c3f6cf collector: disable re-entrancy during initialization
When creating a new collector, we need to prevent the following
call to sysprof_malloc0() from re-entering us into the same
position.
2020-07-03 22:00:34 +01:00
608582d3c4 libsysprof-capture: Drop GLib dependency
None of the code uses it any more. This means that `libsysprof-capture.a`
can now be used within `libglib-2.0.so` for collecting main loop
statistics.

Brought to you by Opeth’s Deliverance on repeat.

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

Fixes: #40
2020-07-03 22:00:34 +01:00
45c8c95706 libsysprof-capture: Drop GError usage from SysprofCaptureWriter
Use `errno` instead, which is icky, but given that all of the failure
modes are from POSIX I/O functions, it’s at least in keeping with them.

This is a major API break.

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

Helps: #40
2020-07-03 22:00:34 +01:00
e19d70bca0 libsysprof-capture: Drop GError usage from SysprofCaptureReader
Use `errno` instead, which is icky, but given that all of the failure
modes are from POSIX I/O functions, it’s at least in keeping with them.

This is a major API break.

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

Helps: #40
2020-07-03 22:00:34 +01:00
fde278fb7f libsysprof-capture: Drop sysprof_capture_writer_set_flush_delay()
It was unused anywhere within sysprof.git, and couldn’t be modified to
drop its GLib dependency while still retaining its functionality.

If it’s still needed, it’ll have to be reimplemented in libsysprof.

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

Helps: #40
2020-07-03 22:00:34 +01:00
cef698e658 libsysprof-capture: wrap strdup to be NULL-safe 2020-07-03 22:00:34 +01:00
6a45f020f7 libsysprof-capture: Add SysprofCaptureJitmapIter to replace GHashTable
Change `sysprof_capture_reader_read_jitmap()` to return a `const
SysprofCaptureJitmap *` (like the other `read` functions), and add a new
`SysprofCaptureJitmapIter` type to allow easy iteration over the jitmap.

This allows a use of `GHashTable` to be removed from the API. It breaks
the libsysprof-capture API and ABI.

All the callers iterate over the jitmap rather than looking up elements
by key. If that functionality is needed in future, additional API can be
added to allow it on `SysprofCaptureJitmap`.

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

Helps: #40
2020-07-03 22:00:34 +01:00
75b69d0a89 libsysprof-capture: Rewrite list_files() to avoid GHashTable/GPtrArray
This changes its API and ABI: it now returns an allocated array of const
strings, rather than an allocated array of allocated strings.

The call sites in the source tree have been adjusted accordingly.

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

Helps: #40
2020-07-03 22:00:34 +01:00
13b1e79901 libsysprof-capture: Use POSIX socket functions rather than GSocket
This should be equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
5a2144e254 libsysprof-capture: Port from GLib to pthreads for locking and once-init
Another step towards dropping the GLib dependency.

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

Helps: #40
2020-07-03 22:00:34 +01:00
c89a47939e libsysprof-capture: Move SysprofBacktraceFunc to a different header
So it’s next to the definition of `SysprofCaptureAddress`, which it
uses.

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

Helps: #40
2020-07-03 22:00:34 +01:00
0d68b1afb5 libsysprof-capture: Use _WIN32 rather than G_OS_WIN32
They should be equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
214ec21ce8 libsysprof-capture: Use an internal header in writer-cat.c
This makes no functional difference, but does tidy up the code style a
bit. All other internal headers are included using quotes in other
files.

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

Helps: #40
2020-07-03 22:00:34 +01:00
b558e7b128 libsysprof-capture: Open-code MAX and CLAMP macros
The macros don’t seem to make things sufficiently much clearer that it
makes sense to provide them.

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

Helps: #40
2020-07-03 22:00:34 +01:00
d83adffd2d libsysprof-capture: Avoid using G_STMT_{START,END} from GLib
Open-code them instead, as they’re relatively simple.

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

Helps: #40
2020-07-03 22:00:34 +01:00
8748db4091 libsysprof-capture: Use calloc() to replace GArray in writer-cat.c
This is a straightforward replacement using a single allocation, as the
number of array elements is always known ahead of time.

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

Helps: #40
2020-07-03 22:00:34 +01:00
8641789d87 libsysprof-capture: Use unlink() rather than g_unlink()
They’re equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
621e7ea314 libsysprof-capture: Use mkostemp() rather than g_file_open_tmp()
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
2020-07-03 22:00:34 +01:00
43530e3613 libsysprof-capture: Use vsnprintf() instead of g_strdup_printf()
This imposes an arbitrary limit of 2048B on the length of printf-ed log
messages, but is otherwise equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
f5cf12ae40 libsysprof-capture: Use POSIX environment functions instead of GLib ones
They are equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
e8a6474236 libsysprof-capture: Use strftime() to format dates rather than GLib
This means we lose support for local timezones other than UTC, but is
otherwise equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
6d3ede2e9f libsysprof-capture: Avoid using GLIB_SIZEOF_VOID_P
Use `UINTPTR_MAX` to calculate the size of a pointer instead. This
assumes that all pointers are the same width.

It also means that the sysprof-capture code uses the pointer size of the
platform that libsysprof-capture was compiled on, rather than the
pointer size of the platform that GLib was compiled on. They seem
unlikely to differ.

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

Helps: #40
2020-07-03 22:00:34 +01:00
113d9d166a libsysprof-capture: Use C-standard printf modifiers
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
2020-07-03 22:00:34 +01:00
14078e6c4d libsysprof-capture: Use SYSPROF_INT64_CONSTANT instead of GLib version
Same for the unsigned version. They do the same thing as the GLib
versions.

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

Helps: #40
2020-07-03 22:00:34 +01:00
f1cb640091 libsysprof-capture: Use reallocarray() instead of GArray in writer-cat.c
This is more of a direct port than previous replacements of `GArray`
(which have had linear growth): this one implements exponential growth
of the allocated array, as `GArray` does.

It uses `qsort()` to sort the array so that it can be binary searched as
before.

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

Helps: #40
2020-07-03 22:00:34 +01:00
3446628cec libsysprof-capture: Use offsetof() rather than G_STRUCT_OFFSET()
It does the same for modern compilers.

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

Helps: #40
2020-07-03 22:00:34 +01:00
284b5fd7cf libsysprof-capture: Rework version macros to drop GLib dependency
They’re equivalent, using deprecation markers suitable for modern
compilers.

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

Helps: #40
2020-07-03 22:00:34 +01:00
175c53aed8 libsysprof-capture: Use SYSPROF_PRINTF rather than G_GNUC_PRINTF
It does the same thing for modern compilers.

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

Helps: #40
2020-07-03 22:00:34 +01:00
9493fa2e03 libsysprof-capture: Use endianness macros from libc rather than GLib
They should be equivalent.

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

Helps: #40
2020-07-03 22:00:34 +01:00
c64dfe9cac libsysprof-capture: Add missing header to define NULL
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
2020-07-03 22:00:34 +01:00
0785f32ce5 libsysprof-capture: Use SYSPROF_N_ELEMENTS macro instead of G_N_ELEMENTS
It does the same thing.

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

Helps: #40
2020-07-03 22:00:34 +01:00
b509daaa42 libsysprof-capture: Use reallocarray() instead of GPtrArray in cursor
There are typically 0 or 1 conditions applied to a cursor, and they’re
only applied at construction time, so it makes sense to only grow the
conditions array linearly when it’s used. This means the array may stay
as `NULL` throughout the lifetime of the cursor.

There’s currently no way to return an error from
`sysprof_capture_cursor_add_condition()`, so an allocation failure
results in an abort.

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

Helps: #40
2020-07-03 22:00:34 +01:00
607af73676 libsysprof-capture: Stop defining G_LOG_DOMAIN
libsysprof-capture no longer calls any of the GLib logging functions
which make use of it.

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

Helps: #40
2020-07-03 22:00:34 +01:00
e4813cd729 libsysprof-capture: Assert rather than calling g_warning()
Calling this function without having registered the counter beforehand
seems reasonable to call a programmer error.

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

Helps: #40
2020-07-03 22:00:34 +01:00
e26eae5bcf libsysprof-capture: Use libc string functions rather than GLib ones
Use `strcmp()` and `strdup()` rather than `g_strcmp0()` and
`g_strdup()`. In the latter case, this makes no difference. In the
former case it means we potentially need to do some additional `NULL`
checks before calling it; although most of the call sites use
fixed-length arrays, so no `NULL` check is needed.

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

Helps: #40
2020-07-03 22:00:34 +01:00
1d865c5c8e libsysprof-capture: Use sysprof_{steal,clear}_pointer() instead of GLib
They work exactly the same way as the GLib functions.

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

Helps: #40
2020-07-03 22:00:34 +01:00
e96e35b6f1 libsysprof-capture: Stop using GArray in SysprofCaptureCondition
The code is well-suited to directly using `calloc()` instead, since the
arrays never grow dynamically.

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

Helps: #40
2020-07-03 22:00:34 +01:00
0e4b3f52b1 libsysprof-capture: Handle OOM conditions in SysprofCaptureCondition
This doesn’t change any of the sites which call
`sysprof_capture_condition_*()` in other files, but does change
`SysprofCaptureCondition` internally to handle OOM and return an error
code.

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

Helps: #40
2020-07-03 22:00:34 +01:00
b0a5c4f700 libsysprof-capture: Use malloc() rather than g_new0() and friends
Another step away from GLib. This changes the OOM behaviour of the
library — previously it would immediately `abort()` on OOM. However, it
seems likely that given the small number of allocations
libsysprof-capture does, it should be able to recover from an OOM
situation more gracefully than larger libraries can — so the new
implementation tries to do that.

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

Helps: #40
2020-07-03 22:00:34 +01:00
6e281dca1f libsysprof-capture: Use strlcpy() instead of g_strlcpy()
If the system doesn’t provide `strlcpy()` (FreeBSD does, Linux doesn’t),
use an inbuilt copy instead.

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

Helps: #40
2020-07-03 22:00:34 +01:00
951b46fddf libsysprof-capture: Use intrinsic atomics rather than g_atomic_*()
Use the intrinsic atomics provided by the compiler, instead of GLib’s
wrapper around them. This should work for all modern compilers.

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

Helps: #40
2020-07-03 22:00:34 +01:00
b6fb272865 libsysprof-capture: Use fprintf() instead of g_printerr()
This removes one more dependency on GLib.

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

Helps: #40
2020-07-03 22:00:34 +01:00
f925fab564 libsysprof-capture: Replace G_{UN,}LIKELY with SYSPROF_{UN,}LIKELY
This does the same thing for modern compilers, but without the GLib
dependency.

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

Helps: #40
2020-07-03 22:00:34 +01:00
c9f54fcc68 libsysprof-capture: Replace G_GNUC_INTERNAL with SYSPROF_INTERNAL
It does the same thing for modern compilers.

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

Helps: #40
2020-07-03 22:00:34 +01:00
41ec04ea99 libsysprof-capture: Replace G_BEGIN_DECLS with SYSPROF_BEGIN_DECLS
It does the same job, but doesn’t require GLib.

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

Helps: #40
2020-07-03 22:00:34 +01:00
8e28ac6e81 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
2020-07-03 22:00:34 +01:00
5636bbf4f0 libsysprof-capture: Use stdbool instead of gboolean
Another step towards dropping GLib as a dependency of
libsysprof-capture.

Unlike the previous commit which replaced GLib integer types with the
bitwise equivalent C standard types, `stdbool` is potentially a different
width from `gboolean`, so this is an ABI break.

It therefore involves some changes to callback functions in the tests
and tools, and in libsysprof.

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

Helps: #40
2020-07-02 21:07:11 +01:00