Sets the ZapDisable env according to the Alternative Sampling value of the coreprofiler
authorj-h.choi <j-h.choi@samsung.com>
Wed, 24 Jan 2024 06:25:09 +0000 (15:25 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Mon, 5 Feb 2024 04:05:58 +0000 (13:05 +0900)
Change-Id: Iba9dfd40023c15b0d59a9cc8032c0e9390d7278d

NativeLauncher/dotnet.debugger
NativeLauncher/launcher/lib/core_runtime.cc
NativeLauncher/launcher/lib/injection.cc
NativeLauncher/launcher/lib/injection.h

index 12ccfc9..1f8f89a 100644 (file)
@@ -67,7 +67,6 @@ DEFAULT_OPT   PROF_TRACE_FILENAME=/home/owner/share/tmp/sdk_tools/coreprofiler/tra
 DEFAULT_OPT    PROF_CONFIG_FILENAME=/home/owner/share/tmp/sdk_tools/coreprofiler/profiler.config
 DEFAULT_OPT    CORECLR_ENABLE_PROFILING=1
 DEFAULT_OPT    COMPlus_EnableEventLog=1
-DEFAULT_OPT    COMPlus_ZapDisable=1
 DEFAULT_OPT -c
 DEFAULT_OPT 6001
 DEFAULT_OPT -d
@@ -94,7 +93,6 @@ DEFAULT_OPT   PROF_TRACE_FILENAME=/home/owner/share/tmp/sdk_tools/coreprofiler/tra
 DEFAULT_OPT    PROF_CONFIG_FILENAME=/home/owner/share/tmp/sdk_tools/coreprofiler/profiler.config
 DEFAULT_OPT    CORECLR_ENABLE_PROFILING=1
 DEFAULT_OPT    COMPlus_EnableEventLog=1
-DEFAULT_OPT    COMPlus_ZapDisable=1
 DEFAULT_OPT -c
 DEFAULT_OPT 6001
 DEFAULT_OPT -d
index ba874aa..33e3298 100644 (file)
@@ -318,9 +318,9 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                return -1;
        }
 
-       // checkInjection checks dotnet-launcher run mode
+       // checkProfilerInjection checks dotnet-launcher run mode
        // At the moment, this mechanism is used only when the Memory Profiler is started.
-       int res = checkInjection();
+       int res = checkProfilerInjection();
        if (res != 0) {
                _ERR("Failed to initnialize Memory Profiler");
                return -1;
index 819af59..2c722a4 100644 (file)
  */
 
 #include "log.h"
+#include "utils.h"
 
 #include <cstdlib>
 #include <cstring>
 
 #include <dlfcn.h>
+#include <fstream>
+#include <string>
 
 #define HT_PATH "/home/owner/share/tmp/sdk_tools/heaptrack/"
 #define HT_LIB_PATH HT_PATH "libprofiler.so"
 #define HT_INJECTION_LIB_PATH HT_PATH "libheaptrack_inject.so"
 
-static int injectLibrary(const char path[])
+#define CP_PATH "/home/owner/share/tmp/sdk_tools/coreprofiler/"
+#define CP_LIB_PATH CP_PATH "libcoreprof.so"
+#define CP_INHECTION_CONFIG CP_PATH "profiler.config"
+
+static int injectHeaptrackLibrary()
 {
        typedef int inject_func();
 
@@ -34,10 +41,10 @@ static int injectLibrary(const char path[])
        inject_func *inject = nullptr;
        const char *inject_sym = "dotnet_launcher_inject";
 
-       _INFO("Inject %s library", path);
+       _INFO("Inject %s library", HT_INJECTION_LIB_PATH);
 
        // Current implementation of heaptrack CLR profiler requires RTLD_GLOBAL
-       lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+       lib = dlopen(HT_INJECTION_LIB_PATH, RTLD_NOW | RTLD_GLOBAL);
        if (lib == nullptr) {
                _ERR("%s", dlerror());
                return res;
@@ -45,7 +52,7 @@ static int injectLibrary(const char path[])
 
        inject = reinterpret_cast<inject_func*>(dlsym(lib, inject_sym));
        if (inject == nullptr) {
-               _ERR("%s is not found in the %s", inject_sym, path);
+               _ERR("%s is not found in the %s", inject_sym, HT_INJECTION_LIB_PATH);
                return res;
        }
 
@@ -53,7 +60,32 @@ static int injectLibrary(const char path[])
        return res;
 }
 
-int checkInjection()
+static int injectCoreprofilerConfig()
+{
+       if (!exist(CP_INHECTION_CONFIG)) {
+               return -1;
+       }
+
+       _INFO("Inject %s", CP_INHECTION_CONFIG);
+
+       std::ifstream ifs(CP_INHECTION_CONFIG);
+       std::string get_conf;
+       if (ifs.is_open()) {
+               while (getline(ifs, get_conf)) {
+                       if (!strcmp(get_conf.c_str(), "PROF_USE_ALTERNATIVE_SAMPLING_EXECUTION_TRACING=1")) {
+                               setenv("COMPlus_ZapDisable", "0", 1);
+                               break;
+                       } else if (!strcmp(get_conf.c_str(), "PROF_USE_ALTERNATIVE_SAMPLING_EXECUTION_TRACING=0")) {
+                               setenv("COMPlus_ZapDisable", "1", 1);
+                               break;
+                       }
+               }
+               ifs.close();
+       }
+       return 0;
+}
+
+int checkProfilerInjection()
 {
        char *env = nullptr;
 
@@ -62,18 +94,21 @@ int checkInjection()
                return 0;
        }
 
-       // At the moment, this mechanism is used only when the Memory Profiler is started.
-       if (strcmp(env, HT_LIB_PATH) != 0) {
-               return 0;
-       }
-
-       _INFO("##### Perform injection #########");
+       _INFO("##### Perform profiler injection #########");
 
-       if (injectLibrary(HT_INJECTION_LIB_PATH) != 0) {
-               _INFO("##### Injection failed #########");
-               return -1;
+       // At the moment, this mechanism is used only when the Memory Profiler is started.
+       if (!strcmp(env, HT_LIB_PATH)) {
+               if (injectHeaptrackLibrary() != 0) {
+                       _INFO("##### Heaptrack injection failed #########");
+                       return -1;
+               }
+       } else if (!strcmp(env, CP_LIB_PATH)) {
+               if (injectCoreprofilerConfig() != 0) {
+                       _INFO("##### Coreprofiler injection failed #########");
+                       return -1;
+               }
        }
-
-       _INFO("##### Injection finished #########");
+       _INFO("##### Injection profiler finished #########");
        return 0;
 }
+
index 6bcf111..042fe42 100644 (file)
@@ -17,6 +17,6 @@
 #ifndef __INJETION_INTERFACE_H__
 #define __INJETION_INTERFACE_H__
 
-int checkInjection();
+int checkProfilerInjection();
 
 #endif // __INJETION_INTERFACE_H__