Modify the injection function for the new memory profiler (#545)
author최종헌/MDE Lab(SR)/삼성전자 <j-h.choi@samsung.com>
Wed, 29 May 2024 07:43:44 +0000 (16:43 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 29 May 2024 07:43:44 +0000 (16:43 +0900)
Change-Id: I139b4564e176f16d98d69cb43fc5bdda67d37c76

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

index 1f8f89a..6b6e49c 100644 (file)
@@ -102,3 +102,30 @@ DEFAULT_OPT 6003
 DEFAULT_OPT --
 DEFAULT_OPT /home/owner/share/tmp/sdk_tools/netcoredbg/netcoredbg
 EXTRA_KEY __DLP_DEBUG_ARG__
+
+[DEBUGGER]
+NAME MEMORYPROFILER
+EXE /home/owner/share/tmp/sdk_tools/profctl/profctl
+APP_TYPE dotnet|dotnet-nui
+DEFAULT_OPT -v
+DEFAULT_OPT -p
+DEFAULT_OPT /home/owner/share/tmp/sdk_tools/mixed-heaptrack/heaptrack_fifo
+DEFAULT_OPT -w
+DEFAULT_OPT -e
+DEFAULT_OPT /home/owner/share/tmp/sdk_tools/mixed-heaptrack/heaptrack_interpret
+DEFAULT_OPT -o
+DEFAULT_OPT /home/owner/share/tmp/sdk_tools/profctl/profctl_heaptrack.log
+DEFAULT_OPT -E
+DEFAULT_OPT    DUMP_HEAPTRACK_OUTPUT=/home/owner/share/tmp/sdk_tools/mixed-heaptrack/heaptrack_fifo
+DEFAULT_OPT    CORECLR_PROFILER={C7BAD323-25F0-4C0B-B354-566390B215CA}
+DEFAULT_OPT    CORECLR_PROFILER_PATH=/home/owner/share/tmp/sdk_tools/mixed-heaptrack/libprofiler.so
+DEFAULT_OPT    PROF_CONFIG_FILENAME=/home/owner/share/tmp/sdk_tools/mixed-heaptrack/profiler.config
+DEFAULT_OPT    CORECLR_ENABLE_PROFILING=1
+DEFAULT_OPT    COMPlus_LogEnable=1
+DEFAULT_OPT UNW_ARM_UNWIND_METHOD=4
+DEFAULT_OPT HEAPTRACK_NATIVE_ENABLE=1
+DEFAULT_OPT -c
+DEFAULT_OPT 6005
+DEFAULT_OPT -d
+DEFAULT_OPT 6006
+DEFAULT_OPT --
\ No newline at end of file
index 8431610..e7c0e54 100644 (file)
@@ -323,9 +323,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..ab203a2 100644 (file)
 
 #include <cstdlib>
 #include <cstring>
-
+#include <string>
 #include <dlfcn.h>
 
-#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"
+#define SDK_TOOLS_PATH   "/home/owner/share/tmp/sdk_tools/"
+#define LIB_INJECTION   "libheaptrack_inject.so"
 
-static int injectLibrary(const char path[])
+static int injectHeaptrackLibrary(const char path[])
 {
        typedef int inject_func();
-
-       int res = -1;
        void *lib = nullptr;
        inject_func *inject = nullptr;
        const char *inject_sym = "dotnet_launcher_inject";
@@ -40,40 +37,46 @@ static int injectLibrary(const char path[])
        lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
        if (lib == nullptr) {
                _ERR("%s", dlerror());
-               return res;
+               return -1;
        }
 
        inject = reinterpret_cast<inject_func*>(dlsym(lib, inject_sym));
        if (inject == nullptr) {
                _ERR("%s is not found in the %s", inject_sym, path);
-               return res;
+               return -1;
        }
 
-       res = inject();
-       return res;
+       return inject();
 }
 
-int checkInjection()
+int checkProfilerInjection()
 {
        char *env = nullptr;
-
        env = getenv("CORECLR_PROFILER_PATH");
        if (env == nullptr) {
                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;
+       if (!exist(env)) {
+               return -1;
        }
 
-       _INFO("##### Perform injection #########");
+       if (env.find(SDK_TOOLS_PATH) == std::string::npos) {
+               return -1;
+       }
+
+       _INFO("##### Perform profiler injection #########");
+
+       std::string path = concatPath(getBaseName(env), LIB_INJECTION);
+       if (!exist(path)) {
+               return -1;
+       }
 
-       if (injectLibrary(HT_INJECTION_LIB_PATH) != 0) {
-               _INFO("##### Injection failed #########");
+       if (injectHeaptrackLibrary(path.c_str()) != 0) {
+               _ERR("##### Heaptrack injection failed #########");
                return -1;
        }
 
-       _INFO("##### Injection finished #########");
+       _INFO("##### Profiler injection 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__