Closed jimblandy closed 4 years ago
The cgroup and group are parameters to perf_event_open
, not fields of perf_event_attr
, so there's not much simplification possible there. Those have to be separate fields of Builder
anyway, and it's simpler and more well-typed to do it the way it's done now.
The kernel API copes with perf_event_attr
structs both smaller (older) and larger (newer) than the kernel expects, so it's not necessary to play games with the size.
At present,
Builder
has its own representation of the configuration selected by the methods called on it, and it uses that representation to initialize aperf_event_attr
struct to pass toperf_event_open
whenbuild
is finally called.It would be better to simply have
Builder
contain aperf_event_attr
struct, and let its methods initialize its fields. It could continue to take thegroup
andcgroup
file descriptors by reference, but its lifetime parameter could be used by aPhantomData<&File>
, while the raw file descriptor gets copied into theperf_event_attr
struct. This would hold theFile
s frozen until we had a chance to construct the perf fd.The structure size could be initialized to some older version, and updated with
max
as newer parts of the structure were initialized, to maximize compatibility with older kernels.