Commit Graph

98 Commits

Author SHA1 Message Date
988ad116a4 libsysprof-capture: check alignment in read length
We require aligned frames, so we might as well enforce it in the reader.
2020-02-23 14:30:06 -08:00
fd215a39a3 libsysprof-capture: check frame length overruns
If we got a corrupted frame, just stop reading forward immediately.
2020-02-23 14:26:13 -08:00
be6b979714 libsysprof-capture: remove use of GAtomicRCBox
If we backport to an older GLib release, we won't have the newer atomic
helpers available. It's really not too much burden to do that manually if
it means we can run on older systems.
2020-02-20 10:39:33 -08:00
cd8a99402f build: fallback to __sync_synchronize()
If we're running on a GCC older than 4.9, then we won't have the
stdatomic.h available. We can just use a full barrier instead using
__sync_synchronize() to get the same effect, albeit slower.
2020-02-20 10:38:35 -08:00
2cd05c1bd8 libsysprof-capture: fallback to g_time_val_to_iso8601()
To allow us to backport to older systems, we can have a fallback here for
the time being.
2020-02-20 10:36:18 -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
2a457f25ec libsysprof-capture: reduce max stack depth
128 is a bit much and can slow us down considerably with user-space stack
traces. This can mess up the tree a bit, but we can alter how we view
things later on if we need to so that it is easier to read.
2020-02-16 20:49:35 -08:00
53a351b66e libsysprof-capture: add clear/reset API for mapped ring buffer 2020-02-16 17:57:06 -07:00
69e4fb2588 libsysprof-capture: allow using ring in readwrite mode
This is a first step to be able to use the ring buffer as the backing
buffer for the SysprofCaptureWriter.
2020-02-15 22:50:22 -07:00
36860b449e libsysprof-capture: unref GSource after attaching 2020-02-15 22:27:34 -07:00
ca5c66245c libsysprof-capture: ignore some types when extending end_time 2020-02-15 22:17:23 -07:00
c74c02a2d9 libsysprof-capture: update ring position while walking
This ensures that the producer can produce as soon as the reader has moved
past that data. Now that the callback has a mutable consumption value, they
can read the whole data in one shot anyway.
2020-02-15 21:55:08 -07:00
c0697c91cc libsysprof-capture: increase rate of buffer read
This ideally should be dynamic in the future to copy out data at a rate
that keeps us around 33% usage rate so that we can still burst if we need
to but keep things empty enough to not loose data.
2020-02-15 21:53:34 -07:00
47768859ad libsysprof-capture: whitespace cleanup 2020-02-15 20:50:05 -07:00
cb1b7d03fb libsysprof-capture: check frame types when peeking 2020-02-15 20:49:47 -07: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
e3ed30eb48 libsysprof-capture: remove framing data from MappedRingBuffer
This removes the 8 bytes of framing data from the MappedRingBuffer which
means we can write more data without racing. But also this means that we
can eventually use the mapped ring buffer as our normal buffer for
capture writing (to be done later).
2020-02-15 20:46:05 -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
ec67106a4d libsysprof-capture: add missing platform header 2020-02-13 18:54:42 -08:00
77400c57c1 libsysprof-capture: add mmap()'d ring buffer
This is the start of a ring buffer to coordinate between processes without
the overhead of writing directly to files within the inferior process.
Instead, the parent process can monitor the ring buffer for framing
information and pass that along to the capture writer.
2020-02-13 18:50:20 -08:00
a8c6038679 libsysprof-capture: fix version value for 3.36 2020-02-13 14:32:34 -08:00
86dcedfba0 libsysprof-capture: add sysprof_getpagesize()
This is a helper to get the page size on various platforms so that calling
code does not need to duplicate that effort.
2020-02-13 14:32:34 -08:00
19e077736b libsysprof-capture: use sysconf() instead of getpagesize() 2020-02-13 14:32:34 -08:00
6cb55f4d71 libsysprof-capture: add raw frame helper
This helps when shuffling data between sources so that you can simply
memcpy() into the destination buffer.
2020-02-13 14:32:34 -08:00
1d44282edb libsysprof-capture: add define for last frame type 2020-02-13 14:32:34 -08:00
b351e1a50a capture: add comment about frame tracking 2020-02-11 18:07:31 -08:00
33c81a3a9c memprof: add memory profiling using LD_PRELOAD
This brings over some of the techniques from the old memprof design.
Sysprof and memprof shared a lot of code, so it is pretty natural to
bring back the same callgraph view based on memory allocations.

This reuses the StackStash just like it did in memprof. While it
would be nice to reuse some existing tools out there, the fit of
memprof with sysprof is so naturally aligned, it's not really a
big deal to bring back the LD_PRELOAD. The value really comes
from seeing all this stuff together instead of multiple apps.

There are plenty of things we can implement on top of this that
we are not doing yet such as temporary allocations, cross-thread
frees, graphing the heap, and graphing differences between the
heap at to points in time. I'd like all of these things, given
enough time to make them useful.

This is still a bit slow though due to the global lock we take
to access the writer. To improve the speed here we need to get
rid of that lock and head towards a design that allows a thread
to request a new writer from Sysprof and save it in TLS (to be
destroyed when the thread exits).
2020-02-07 19:00:33 -08:00
2e72e6af84 capture: fix format type for address on macOS 2020-02-07 11:00:09 -08:00
47c09cb241 build: add version macros for 3.36 2020-01-31 09:13:50 -08:00
994b0535ef Fix endianness detection when writing a frame
Properly detect endianness at compilation time

This fixes the tests on big-endian machines

Fix: https://gitlab.gnome.org/GNOME/sysprof/issues/7
2020-01-02 12:44:15 +01:00
653ff6ba9e build: add datadir to pkgconfig files
Mutter wants sysprof's exact dbus interface directory during build time
* https://gitlab.gnome.org/GNOME/mutter/blob/master/src/meson.build#L714

On certain platforms mutter's datadir != sysprof's datadir.
This is initial work for a forthcoming PR to do
```
sysprof_dep.get_pkgconfig_variable('datadir')
```
in mutter for compatibility with these platforms.

This patch is on behalf of nixpkgs where we actually have to carry a 
downstream patch [0] for this exact reason. We install everything into 
their own immutable prefix under `/nix/store`.

[0]: a821167046/pkgs/desktops/gnome-3/core/mutter/0001-build-use-get_pkgconfig_variable-for-sysprof-dbusdir.patch
2019-12-04 17:17:58 -05:00
0716e23fb4 libsysprof-capture: use GDateTime instead of GTimeVal 2019-08-08 16:08:00 -07:00
fc013fe99f libsysprof-capture: reset reader before catting into dest 2019-07-31 13:07:41 -07:00
c2728b8ada cleanup: remove duplicated NSEC_PER_SEC macros
This switches everything to using a single 64-bit constant for NSEC_PER_SEC
that ensure we're doing 64-bit math everywhere.
2019-07-18 10:22:46 -07:00
1b36f92f73 libsysprof-capture: only short-circuit for address translation 2019-06-06 17:49:44 -07:00
db33d910bb libsysprof-capture: allow NULL only when n_counters == 0 2019-06-06 17:15:10 -07:00
8f18572499 libsysprof-capture: translate jitmaps before samples
So we have valid addresses to translate, we need to translate the jitmap
before we translate samples. Otherwise we likely won't have anything to
translate.
2019-06-05 19:32:42 -07:00
44772d243e libsysprof-capture: fix comparison of translation item 2019-06-05 19:30:15 -07:00
97ec24ab42 libsysprof-capture: add flush_delay for auto flushing
This can be useful in scenarios where you need to kill the application
using a signal so that data is not lost in the buffer.
2019-06-05 15:12:17 -07:00
0f85e10368 style cleanup 2019-06-05 15:11:24 -07:00
400e5b81bc libsysprof-capture: be more defensive 2019-06-05 15:11:04 -07:00
26c029b7a2 libsysprof-capture: short-circuit empty write 2019-06-05 15:10:48 -07:00
ec7fa297e7 whitespace cleanup 2019-06-05 13:25:29 -07:00