Commit Graph

32 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
2c2cbf6343 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
2020-07-02 21:07:11 +01:00
16bf945d34 libsysprof-capture: Drop unnecessary #include
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
2020-07-02 21:07:11 +01:00
01d196abe4 libsysprof-collector: avoid formatting unless recording
We can avoid the process of creating the log message altogether if we are
not actively recording messages.
2020-03-16 12:28:04 -07:00
3d546eb6d1 libsysprof-capture: add sysprof_collector_log_printf()
This is a convenience function to call sysprof_collector_log() while also
formatting the message.

Ideally we'd be able to avoid the string format if we are not currently
collecting data, but that can be left for a future commit. We don't have
recursive locks so we need to duplicate the structure setup.
2020-03-16 12:28:04 -07:00
b022906b9e collector: fix mark name in collection 2020-03-13 15:31:51 -07:00
745eb981d1 libsysprof-capture: add mark and log variants 2020-03-05 15:43:33 -08:00
2725565eb9 libsysprof-capture: remove fallback code
We don't support the fallback writer interface currently, so this can go
until we decide what to do going forward.
2020-03-05 15:30:02 -08:00
de492d11e5 libsysprof-capture: set padding to 0 2020-03-05 15:26:41 -08:00
43f31fb8b7 libsysprof-capture: add collector interface for samples 2020-03-05 15:26:31 -08:00
351a2089ff libsysprof-capture: remove unused API
We want this alter, but for now, we can skip it until there is a chance
to fully implement it.
2020-02-28 09:27:32 -08:00
0d6a3d0183 libsysprof-capture: fix use of n_addrs 2020-02-18 14:05:26 -08:00
7490a774ab libsysprof-capture: use signed int for backtrace return
This allows us to more safely subtract 1 from the unw_backtrace() to get
the proper number of frames (and detect it in the collector).
2020-02-18 14:03:19 -08:00
fdf912b716 libsysprof-capture: do less work to calculate frame length
These values are already all aligned, so there is no need to realign them.
2020-02-18 13:35:45 -08:00
70bea64f88 libsysprof-capture: allow for backtrace skip optimization
We want to be backtracing directly into the capture buffer, but also need
to skip a small number of frames.

If we call the backtrace before filling in information, we can capture to
the position *before* ev->addrs and then overwrite that data right after.
2020-02-18 13:35:18 -08:00
20f7c271ca libsysprof-capture: clear SYSPROF_CONTROL_FD 2020-02-18 13:17:33 -08:00
4cfb51421b libsysprof-capture: set tid to pid on non-Linux 2020-02-18 13:17:22 -08:00
ee5c43f107 libsysprof-capture: avoid recursion in TLS cleanup 2020-02-16 20:58:39 -08:00
135b5d2fbf libsysprof-capture: remove unused code 2020-02-16 20:56:12 -08:00
c36420d716 libsysprof-capture: write final frame
This frame type can be used to communicate with the peer over the mapped
ring buffer to denote that writing is finished and it can free any
resources for the mapping.
2020-02-15 20:49:27 -07:00
c546d31ad9 libsysprof-capture: add simplified collector API
This is a simplified API for the inferior to use (such as from a
LD_PRELOAD) that will use mmap()'d ring buffer created by Sysprof. Doing
so can reduce the amount of overhead in the inferior enough to make some
workloads useful. For example, collecting memory statistics and backtraces
is now fast enough to be useful.
2020-02-13 18:56:54 -08:00