perf: optionally enable clockid and use_clockid

Some kernels to not have this feature yet, so check for support in
linux/perf_event.h and optionally enable the struct field.
This commit is contained in:
Christian Hergert
2016-04-16 16:07:11 -07:00
parent de572f4ed6
commit 06aaff90e5
4 changed files with 41 additions and 9 deletions

View File

@ -16,6 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <errno.h>
@ -228,10 +232,6 @@ sysprofd_perf_event_open (sd_bus_message *msg,
else if (r == 0)
return -EACCES;
if (!use_clockid || clockid < 0)
clockid = CLOCK_MONOTONIC_RAW;
attr.clockid = clockid;
attr.comm = !!comm;
attr.config = config;
attr.disabled = disabled;
@ -242,9 +242,16 @@ sysprofd_perf_event_open (sd_bus_message *msg,
attr.sample_type = sample_type;
attr.task = !!task;
attr.type = type;
attr.use_clockid = use_clockid;
attr.wakeup_events = wakeup_events;
#if HAVE_PERF_CLOCKID
if (!use_clockid || clockid < 0)
attr.clockid = CLOCK_MONOTONIC_RAW;
else
attr.clockid = clockid;
attr.use_clockid = use_clockid;
#endif
attr.size = sizeof attr;
fd = _perf_event_open (&attr, pid, cpu, -1, 0);