[gjs/wip/chergert/sysprof-3: 1/3] profiler: port to sysprof-capture-3



commit e36edda9b8dd39fc8724ecbb9c618bf985ba2090
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 3 14:08:47 2019 -0700

    profiler: port to sysprof-capture-3
    
    Rather than embedding the old sysprof sources into the tree this change
    uses the static sysprof-capture-3 library when available. If --enable-
    profiler=auto, then the profiler will only be enabled if the sources are
    found. If the build is --enable-profiler=yes, the sysprof-capture-3
    library must be available.
    
    Now that sysprof is maintaining an ABI, the function prefix was also
    changed to sysprof_. This patch also reflects that.
    
    Related to GNOME/Initiatives#10.

 Makefile.am                  |   4 +-
 configure.ac                 |  20 +-
 gjs-srcs.mk                  |   6 -
 gjs/profiler.cpp             |  35 +--
 test/org.gnome.GjsDevel.json |  18 ++
 util/sp-capture-types.h      | 127 ---------
 util/sp-capture-writer.c     | 628 -------------------------------------------
 util/sp-capture-writer.h     |  81 ------
 8 files changed, 58 insertions(+), 861 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 7882af0a..0949f63f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -87,8 +87,8 @@ endif
 libgjs_la_SOURCES = $(gjs_srcs)
 
 if ENABLE_PROFILER
-libgjs_la_SOURCES += $(gjs_sysprof_srcs)
-libgjs_la_LIBADD += $(LIB_TIMER_TIME)
+libgjs_la_CPPFLAGS += $(SYSPROF_CAPTURE_CFLAGS)
+libgjs_la_LIBADD += $(LIB_TIMER_TIME) $(SYSPROF_CAPTURE_LIBS)
 endif
 
 # Also, these files used to be a separate library
diff --git a/configure.ac b/configure.ac
index 00269d74..aa04e841 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,9 +147,24 @@ AS_IF([test x$have_gtk = xyes], [
 ], [AS_IF([test "x$with_gtk" = "xyes"],
   [AC_MSG_ERROR([GTK requested but not found])])])
 
-# Some Linux APIs required for profiler
 AC_ARG_ENABLE([profiler],
   [AS_HELP_STRING([--disable-profiler], [Don't build profiler])])
+
+# Use sysprof-capture-3 for profiler
+PKG_CHECK_MODULES([SYSPROF_CAPTURE],
+                  [sysprof-capture-3],
+                  [have_sysprof_capture=yes],
+                  [have_sysprof_capture=no])
+AS_IF([test x$enable_profiler = xauto],[
+  AS_IF([test $have_sysprof_capture = no],[enable_profiler=no])
+])
+AS_IF([test x$enable_profiler = yes],[
+  AS_IF([test $have_sysprof_capture = no],[
+    AC_MSG_ERROR([--enable-profiler requires sysprof-capture-3.pc])
+  ])
+])
+
+# Some Linux APIs required for profiler
 AS_IF([test x$enable_profiler != xno], [
   # Requires timer_settime() - only on Linux
   gl_TIMER_TIME
@@ -166,8 +181,11 @@ AS_IF([test x$enable_profiler != xno], [
     [AC_MSG_ERROR([The profiler is currently only supported on Linux.
 The standard library must support timer_settime() and SIGEV_THREAD_ID.
 Configure with --disable-profiler to skip it on other platforms.])])
+  AC_SUBST([SYSPROF_CAPTURE_CFLAGS])
+  AC_SUBST([SYSPROF_CAPTURE_LIBS])
   AC_DEFINE([ENABLE_PROFILER], [1], [Define if the profiler should be built.])
 ])
+
 AM_CONDITIONAL([ENABLE_PROFILER], [test x$enable_profiler != xno])
 
 # Optional redline dep (enabled by default)
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index dcdc4387..2fcdfb8f 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -115,9 +115,3 @@ gjs_gtk_private_srcs =                      \
 gjs_console_srcs =     \
        gjs/console.cpp \
        $(NULL)
-
-gjs_sysprof_srcs =                     \
-       util/sp-capture-types.h         \
-       util/sp-capture-writer.c        \
-       util/sp-capture-writer.h        \
-       $(NULL)
diff --git a/gjs/profiler.cpp b/gjs/profiler.cpp
index 6f37eaca..b332b859 100644
--- a/gjs/profiler.cpp
+++ b/gjs/profiler.cpp
@@ -47,7 +47,7 @@
 #    ifdef G_OS_UNIX
 #        include <glib-unix.h>
 #    endif
-#    include "util/sp-capture-writer.h"
+#    include <sysprof-capture.h>
 #endif
 
 /*
@@ -95,7 +95,7 @@ struct _GjsProfiler {
     JSContext *cx;
 
     /* Buffers and writes our sampled stacks */
-    SpCaptureWriter *capture;
+    SysprofCaptureWriter* capture;
 #endif  /* ENABLE_PROFILER */
 
     /* The filename to write to */
@@ -166,8 +166,8 @@ gjs_profiler_extract_maps(GjsProfiler *self)
             inode = 0;
         }
 
-        if (!sp_capture_writer_add_map(self->capture, now, -1, self->pid, start,
-                                       end, offset, inode, file))
+        if (!sysprof_capture_writer_add_map(self->capture, now, -1, self->pid,
+                                            start, end, offset, inode, file))
             return false;
     }
 
@@ -247,7 +247,7 @@ _gjs_profiler_free(GjsProfiler *self)
 
     g_clear_pointer(&self->filename, g_free);
 #ifdef ENABLE_PROFILER
-    g_clear_pointer(&self->capture, sp_capture_writer_unref);
+    g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
 #endif
     g_free(self);
 }
@@ -304,7 +304,8 @@ gjs_profiler_sigprof(int        signum,
      * here since we are in a signal handler.
      */
     // cppcheck-suppress allocaCalled
-    SpCaptureAddress *addrs = static_cast<SpCaptureAddress *>(alloca(sizeof *addrs * depth));
+    SysprofCaptureAddress* addrs =
+        static_cast<SysprofCaptureAddress*>(alloca(sizeof *addrs * depth));
 
     for (uint32_t ix = 0; ix < depth; ix++) {
         js::ProfileEntry& entry = self->stack.entries[ix];
@@ -357,12 +358,14 @@ gjs_profiler_sigprof(int        signum,
          * everything will show up as [stack] when building callgraphs.
          */
         if (final_string[0] != '\0')
-            addrs[flipped] = sp_capture_writer_add_jitmap(self->capture, final_string);
+            addrs[flipped] =
+                sysprof_capture_writer_add_jitmap(self->capture, final_string);
         else
-            addrs[flipped] = SpCaptureAddress(entry.stackAddress());
+            addrs[flipped] = SysprofCaptureAddress(entry.stackAddress());
     }
 
-    if (!sp_capture_writer_add_sample(self->capture, now, -1, self->pid, addrs, depth))
+    if (!sysprof_capture_writer_add_sample(self->capture, now, -1, self->pid,
+                                           -1, addrs, depth))
         gjs_profiler_stop(self);
 }
 
@@ -403,7 +406,7 @@ gjs_profiler_start(GjsProfiler *self)
     if (!path)
         path = g_strdup_printf("gjs-%jd.syscap", intmax_t(self->pid));
 
-    self->capture = sp_capture_writer_new(path, 0);
+    self->capture = sysprof_capture_writer_new(path, 0);
 
     if (!self->capture) {
         g_warning("Failed to open profile capture");
@@ -412,7 +415,7 @@ gjs_profiler_start(GjsProfiler *self)
 
     if (!gjs_profiler_extract_maps(self)) {
         g_warning("Failed to extract proc maps");
-        g_clear_pointer(&self->capture, sp_capture_writer_unref);
+        g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
         return;
     }
 
@@ -423,7 +426,7 @@ gjs_profiler_start(GjsProfiler *self)
 
     if (sigaction(SIGPROF, &sa, nullptr) == -1) {
         g_warning("Failed to register sigaction handler: %s", g_strerror(errno));
-        g_clear_pointer(&self->capture, sp_capture_writer_unref);
+        g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
         return;
     }
 
@@ -443,7 +446,7 @@ gjs_profiler_start(GjsProfiler *self)
 
     if (timer_create(CLOCK_MONOTONIC, &sev, &self->timer) == -1) {
         g_warning("Failed to create profiler timer: %s", g_strerror(errno));
-        g_clear_pointer(&self->capture, sp_capture_writer_unref);
+        g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
         return;
     }
 
@@ -457,7 +460,7 @@ gjs_profiler_start(GjsProfiler *self)
     if (timer_settime(self->timer, 0, &its, &old_its) != 0) {
         g_warning("Failed to enable profiler timer: %s", g_strerror(errno));
         timer_delete(self->timer);
-        g_clear_pointer(&self->capture, sp_capture_writer_unref);
+        g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
         return;
     }
 
@@ -512,9 +515,9 @@ gjs_profiler_stop(GjsProfiler *self)
     js::EnableContextProfilingStack(self->cx, false);
     js::SetContextProfilingStack(self->cx, nullptr);
 
-    sp_capture_writer_flush(self->capture);
+    sysprof_capture_writer_flush(self->capture);
 
-    g_clear_pointer(&self->capture, sp_capture_writer_unref);
+    g_clear_pointer(&self->capture, sysprof_capture_writer_unref);
 
     g_message("Profiler stopped");
 
diff --git a/test/org.gnome.GjsDevel.json b/test/org.gnome.GjsDevel.json
index 292ddfd8..c7e0bcdf 100644
--- a/test/org.gnome.GjsDevel.json
+++ b/test/org.gnome.GjsDevel.json
@@ -16,6 +16,24 @@
         "--socket=pulseaudio"
     ],
     "modules": [
+        {
+            "name": "sysprof",
+            "builddir": true,
+            "buildsystem": "meson",
+            "config-opts": [
+                "-Denable_gtk=false",
+                "-Dhelp=false",
+                "-Dlibsysprof=false",
+                "-Dwith_sysprofd=none"
+            ],
+            "sources": [
+                {
+                    "type": "git",
+                    "branch": "master",
+                    "url": "https://gitlab.gnome.org/GNOME/sysprof.git";
+                }
+            ]
+        },
         {
             "name": "gjs",
             "builddir": true,


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