--- /dev/null
+/*\r
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+using System;\r
+using System.Runtime;\r
+using System.Threading.Tasks;\r
+\r
+namespace Tizen.Runtime\r
+{\r
+ public class Profiler\r
+ {\r
+ private static void stop()\r
+ {\r
+ Console.WriteLine("Stop profile and write collected data");\r
+ ProfileOptimization.StartProfile(null);\r
+ }\r
+\r
+ public static void StopProfileAfterDelay(int sec)\r
+ {\r
+ Console.WriteLine($"Stop profile after {sec} sec");\r
+ Task.Delay(sec * 1000).ContinueWith(_ => stop());\r
+ }\r
+ }\r
+}\r
static coreclr_shutdown_ptr shutdown = nullptr;
static coreclr_create_delegate_ptr createDelegate = nullptr;
static set_environment_variable_ptr setEnvironmentVariable = nullptr;
+static stop_profile_after_delay_ptr stopProfileAfterDelay = nullptr;
static void* __coreclrLib = nullptr;
static void* __hostHandle = nullptr;
static unsigned int __domainId = -1;
static bool __isProfileMode = false;
PathManager* CoreRuntime::__pm = nullptr;
+#define MAX_DELAY_SEC 100
+
static std::vector<std::string> __envList;
static void setEnvFromFile()
return -1;
}
+ st = createDelegate(__hostHandle, __domainId, "Tizen.Runtime", "Tizen.Runtime.Profiler", "StopProfileAfterDelay", (void**)&stopProfileAfterDelay);
+ if (st < 0 || stopProfileAfterDelay == nullptr) {
+ _ERR("Create delegate for Tizen.Runtime.dll -> Tizen.Runtime.Profiler -> StopProfileAfterDelay failed (0x%08x)", st);
+ return -1;
+ }
+
if (launchMode == LaunchMode::loader) {
// terminate candidate process if language is changed.
// CurrentCulture created for preloaded dlls should be updated.
setEnvironmentVariable("COMPlus_MultiCoreJitProfile", multiCoreJitProfile);
setEnvironmentVariable("COMPlus_MultiCoreJitMinNumCpus", "1");
+
+ // stop profiling and write collected data after delay if env value is set.
+ char *env = getenv("CLR_MCJ_PROFILE_WRITE_DELAY");
+ if (env != nullptr) {
+ int delay = std::atoi(env);
+ // To avoid undefined behavior by out-of-range input(atoi), set max delay value to 100.
+ if (delay > 0) {
+ if (delay > MAX_DELAY_SEC) delay = MAX_DELAY_SEC;
+ stopProfileAfterDelay(delay);
+ }
+ }
+
if (exist(multiCoreJitProfile)) {
setEnvironmentVariable("COMPlus_MultiCoreJitNoProfileGather", "1");
}