This switches over to using the portability helpers that may
be needed on some platforms other than Linux. On Linux, however,
they are just macros to the standard implementation provided
by (g)libc.
If we're on non-Linux, we can use some portability fallbacks to
get similar behavior to Linux. I'm sure we can optimize this a
bit more for FreeBSD if someone with that installed wants to
come look at things and improve them.
There were some GCC'isms here that don't port well to mingw
(and likely other win32 compilers). Of note are the removal
of #pragma pack to instead use the GCC attributes or MSVC
declarations. Also we cannot be so liberal in our use of
bitflags, we need to use common types from neighbors.
We still generally only build on Linux from the Sysprof
project, but we can start to support other systems in the
capture format (with the possibility of being more general
for the UI later on too).
We want the capture format to be usable on systems other than
Linux so that it can be used in places like GTK. To do this,
we need a sendfile() fallback that can be portable/useful on
those systems.
FreeBSD has sendfile(), but the semantics differ slightly. This
implementation will walk up to the nearest page size and then
do page aligned pread()/write() which is likely good enough of
an implementation anyway.
Simple discovery of memory counters to display in the capture set. We will
want to refactor this type of stuff in the future into recording "gadgets"
that combine a data-collector with a visualization layer.
If we have not received a y-lower/upper value, then we can discover that
from the data set at the cost of an extra capture linear scan.
This is useful for the meomry source which can change the upper value
during the lifetime of a process.
This fixes the compilation when we have sysprofd fully disabled.
That is not an ideal configuration, but keeping it working
ensures that some of the code is easy copy/paste'able in the
future for some situations.
Re-opening the FD on every poll is pretty expensive. So we should avoid
doing that as well re-use the read buffer (page-aligned, <=1 page) for
the sample data.
The point of this file was to be easily usable by applications that want
to generate capture files (or proxy them). The intention here is that we
only have SpCaptureReader/SpCaptureWriter (and associated bits necessary
to support that).
This makes sure that we do not use GObject from the libsysprof-capture-2.a
while still having GType's in the libsysprof-2.so dynamic library.
We also invert the GObject macro check so that the default is to not
register a GType which increases the chances that copy/paste code does
not run into double-registering a GType if used with an application that
links against libsysprof-2. (One such example could be if Gtk uses this
code for timers, as it would break Sysprof itself).
This reveals that we've got really bogus times from these events. I
think there are two things here: the begin is the submit time, not the
submit-to-hardware time. And the end time is retire, which is too
delayed to be really useful. We need to move i915 over to the
low-level tracepoints.
However, this code proved to be useful for vc4, where I have good
timings.
Max uint was more than we allow, since we steal the top 8 bits for some
other data. This instead checks for 24-bit and warns if the user tries to
store a counter value that was not registered.
We have an annoying issue where we look at all fiends of a counter values
chunk in the counter set frame. So we need those values set to zero. If
we are passed fewer counter values than can fit in the frame, we leave
some of that data uninitialized. This ensures that it is cleared.