2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #define HT_PATH "/home/owner/share/tmp/sdk_tools/heaptrack/"
25 #define HT_LIB_PATH HT_PATH "libprofiler.so"
26 #define HT_INJECTION_LIB_PATH HT_PATH "libheaptrack_inject.so"
28 static int injectLibrary(const char path[])
30 typedef int inject_func();
34 inject_func *inject = nullptr;
35 const char *inject_sym = "dotnet_launcher_inject";
37 _INFO("Inject %s library", path);
39 // Current implementation of heaptrack CLR profiler requires RTLD_GLOBAL
40 lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
42 _ERR("%s", dlerror());
46 inject = reinterpret_cast<inject_func*>(dlsym(lib, inject_sym));
47 if (inject == nullptr) {
48 _ERR("%s is not found in the %s", inject_sym, path);
60 env = getenv("CORECLR_PROFILER_PATH");
65 // At the moment, this mechanism is used only when the Memory Profiler is started.
66 if (strcmp(env, HT_LIB_PATH) != 0) {
70 _INFO("##### Perform injection #########");
72 if (injectLibrary(HT_INJECTION_LIB_PATH) != 0) {
73 _INFO("##### Injection failed #########");
77 _INFO("##### Injection finished #########");