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

@ -80,6 +80,16 @@ GOBJECT_INTROSPECTION_CHECK([1.42.0])
VAPIGEN_CHECK VAPIGEN_CHECK
dnl ***********************************************************************
dnl Check for recent perf improvements
dnl ***********************************************************************
AC_CHECK_MEMBERS([struct perf_event_attr.use_clockid, struct perf_event_attr.clockid],
[AC_DEFINE([HAVE_PERF_CLOCKID],[1],[Define if perf supports clockid])],
[],
[[#include <linux/perf_event.h>]])
dnl *********************************************************************** dnl ***********************************************************************
dnl Check for required packages dnl Check for required packages
dnl *********************************************************************** dnl ***********************************************************************

View File

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

View File

@ -35,6 +35,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h> #include <errno.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <gio/gunixfdlist.h> #include <gio/gunixfdlist.h>
@ -650,7 +654,10 @@ sp_perf_counter_open (SpPerfCounter *self,
"(" "("
"[" "["
"{'comm', <%b>}," "{'comm', <%b>},"
#if HAVE_PERF_CLOCKID
"{'clockid', <%i>}," "{'clockid', <%i>},"
"{'use_clockid', <%b>},"
#endif
"{'config', <%t>}," "{'config', <%t>},"
"{'disabled', <%b>}," "{'disabled', <%b>},"
"{'exclude_idle', <%b>}," "{'exclude_idle', <%b>},"
@ -660,15 +667,17 @@ sp_perf_counter_open (SpPerfCounter *self,
"{'sample_period', <%t>}," "{'sample_period', <%t>},"
"{'sample_type', <%t>}," "{'sample_type', <%t>},"
"{'task', <%b>}," "{'task', <%b>},"
"{'type', <%u>}," "{'type', <%u>}"
"{'use_clockid', <%b>}"
"]," "],"
"%i," "%i,"
"%i," "%i,"
"%t" "%t"
")", ")",
(gboolean)!!attr->comm, (gboolean)!!attr->comm,
#if HAVE_PERF_CLOCKID
(gint32)attr->clockid, (gint32)attr->clockid,
(gboolean)!!attr->use_clockid,
#endif
(guint64)attr->config, (guint64)attr->config,
(gboolean)!!attr->disabled, (gboolean)!!attr->disabled,
(gboolean)!!attr->exclude_idle, (gboolean)!!attr->exclude_idle,
@ -679,7 +688,6 @@ sp_perf_counter_open (SpPerfCounter *self,
(guint64)attr->sample_type, (guint64)attr->sample_type,
(gboolean)!!attr->task, (gboolean)!!attr->task,
(guint32)attr->type, (guint32)attr->type,
(gboolean)!!attr->use_clockid,
(gint32)pid, (gint32)pid,
(gint32)cpu, (gint32)cpu,
(guint64)flags); (guint64)flags);

View File

@ -35,6 +35,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gio/gio.h> #include <gio/gio.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <errno.h> #include <errno.h>
@ -292,9 +296,12 @@ sp_perf_source_start_pid (SpPerfSource *self,
attr.comm = 1; attr.comm = 1;
attr.task = 1; attr.task = 1;
attr.exclude_idle = 1; attr.exclude_idle = 1;
attr.sample_id_all = 1;
#if HAVE_PERF_CLOCKID
attr.clockid = sp_clock; attr.clockid = sp_clock;
attr.use_clockid = 1; attr.use_clockid = 1;
attr.sample_id_all = 1; #endif
attr.size = sizeof attr; attr.size = sizeof attr;