[sysprof] perf: optionally enable clockid and use_clockid



commit 06aaff90e5e9f289f3f597030d54ec2bb350d090
Author: Christian Hergert <christian hergert me>
Date:   Sat Apr 16 16:07:11 2016 -0700

    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.

 configure.ac          |   10 ++++++++++
 daemon/sysprofd.c     |   17 ++++++++++++-----
 lib/sp-perf-counter.c |   14 +++++++++++---
 lib/sp-perf-source.c  |    9 ++++++++-
 4 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 70fe059..ac34f2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,16 @@ GOBJECT_INTROSPECTION_CHECK([1.42.0])
 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 Check for required packages
 dnl ***********************************************************************
diff --git a/daemon/sysprofd.c b/daemon/sysprofd.c
index 0933a48..51cc456 100644
--- a/daemon/sysprofd.c
+++ b/daemon/sysprofd.c
@@ -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);
diff --git a/lib/sp-perf-counter.c b/lib/sp-perf-counter.c
index 8445c47..1ceb513 100644
--- a/lib/sp-perf-counter.c
+++ b/lib/sp-perf-counter.c
@@ -35,6 +35,10 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <errno.h>
 #include <gio/gio.h>
 #include <gio/gunixfdlist.h>
@@ -650,7 +654,10 @@ sp_perf_counter_open (SpPerfCounter          *self,
                        "("
                                "["
                                        "{'comm', <%b>},"
+#if HAVE_PERF_CLOCKID
                                        "{'clockid', <%i>},"
+                                       "{'use_clockid', <%b>},"
+#endif
                                        "{'config', <%t>},"
                                        "{'disabled', <%b>},"
                                        "{'exclude_idle', <%b>},"
@@ -660,15 +667,17 @@ sp_perf_counter_open (SpPerfCounter          *self,
                                        "{'sample_period', <%t>},"
                                        "{'sample_type', <%t>},"
                                        "{'task', <%b>},"
-                                       "{'type', <%u>},"
-                                       "{'use_clockid', <%b>}"
+                                       "{'type', <%u>}"
                                "],"
                                "%i,"
                                "%i,"
                                "%t"
                        ")",
       (gboolean)!!attr->comm,
+#if HAVE_PERF_CLOCKID
       (gint32)attr->clockid,
+      (gboolean)!!attr->use_clockid,
+#endif
       (guint64)attr->config,
       (gboolean)!!attr->disabled,
       (gboolean)!!attr->exclude_idle,
@@ -679,7 +688,6 @@ sp_perf_counter_open (SpPerfCounter          *self,
       (guint64)attr->sample_type,
       (gboolean)!!attr->task,
       (guint32)attr->type,
-      (gboolean)!!attr->use_clockid,
       (gint32)pid,
       (gint32)cpu,
       (guint64)flags);
diff --git a/lib/sp-perf-source.c b/lib/sp-perf-source.c
index 3b60381..5eaa723 100644
--- a/lib/sp-perf-source.c
+++ b/lib/sp-perf-source.c
@@ -35,6 +35,10 @@
  * 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 <glib/gi18n.h>
 #include <errno.h>
@@ -292,9 +296,12 @@ sp_perf_source_start_pid (SpPerfSource  *self,
   attr.comm = 1;
   attr.task = 1;
   attr.exclude_idle = 1;
+  attr.sample_id_all = 1;
+
+#if HAVE_PERF_CLOCKID
   attr.clockid = sp_clock;
   attr.use_clockid = 1;
-  attr.sample_id_all = 1;
+#endif
 
   attr.size = sizeof attr;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]