[gjs: 3/11] profiler: Allow enabling with GJS_ENABLE_PROFILER=1



commit e7ede4a233fd7de7cba3b74edac76970f7d1d778
Author: Philip Chimento <philip endlessm com>
Date:   Thu Jan 18 13:55:32 2018 -0800

    profiler: Allow enabling with GJS_ENABLE_PROFILER=1
    
    As discussed in #31, we also want to be able to turn on the profiler with
    an environment variable.

 gjs/console.cpp                            | 7 ++++++-
 installed-tests/scripts/testCommandLine.sh | 6 ++++++
 test/gjs-tests.cpp                         | 3 +++
 3 files changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 672ef9d..7ba11f2 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -113,7 +113,8 @@ check_stray_profile_arg(const char *option_name,
 {
     g_warning("You used the --profile option after the script on the GJS "
               "command line. Support for this will be removed in a future "
-              "version. Place the option before the script.");
+              "version. Place the option before the script or use the "
+              "GJS_ENABLE_PROFILER environment variable.");
     g_free(profile_output_path);
     return parse_profile_arg(option_name, value, data, error_out);
 }
@@ -308,6 +309,10 @@ main(int argc, char **argv)
         g_object_unref(output);
     }
 
+    const char *env_profiler = g_getenv("GJS_ENABLE_PROFILER");
+    if (env_profiler)
+        enable_profiler = true;
+
     profiler = gjs_profiler_new(js_context);
 
     /* Allow SIGUSR2 (with sigaction param) to enable/disable */
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh
index e0a42f5..4d847a9 100755
--- a/installed-tests/scripts/testCommandLine.sh
+++ b/installed-tests/scripts/testCommandLine.sh
@@ -6,6 +6,9 @@ else
     gjs="$LOG_COMPILER $LOG_FLAGS gjs-console"
 fi
 
+# Avoid interference in the profiler tests from stray environment variable
+unset GJS_ENABLE_PROFILER
+
 # This JS script should exit immediately with code 42. If that is not working,
 # then it will exit after 3 seconds as a fallback, with code 0.
 cat <<EOF >exit.js
@@ -161,6 +164,9 @@ report "--profile should dump profiling data to the default file name"
 $gjs --profile=foo.syscap -c 'imports.system.exit(0)' && test -f foo.syscap
 report "--profile with argument should dump profiling data to the named file"
 rm -f gjs-*.syscap foo.syscap
+GJS_ENABLE_PROFILER=1 $gjs -c 'imports.system.exit(0)' && test -f gjs-*.syscap
+report "GJS_ENABLE_PROFILER=1 should enable the profiler"
+rm -f gjs-*.syscap
 
 # interpreter handles queued promise jobs correctly
 output=$($gjs promise.js)
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 2c9477e..24f395c 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -409,6 +409,9 @@ main(int    argc,
     if (!g_getenv("GJS_TEST_SKIP_TIMEOUT"))
         gjs_crash_after_timeout(60 * 7);
 
+    /* Avoid interference in the tests from stray environment variable */
+    g_unsetenv("GJS_ENABLE_PROFILER");
+
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/gjs/context/construct/destroy", gjstest_test_func_gjs_context_construct_destroy);


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