e04e8a2111a55dbed421352f7674ea7c5abc56d6
[platform/core/dotnet/launcher.git] / Managed / Tizen.Runtime / Profiler.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.IO;
19 using System.Runtime;
20 using System.Threading.Tasks;
21
22 namespace Tizen.Runtime
23 {
24     public class Profiler
25     {
26         const string profilePath = "/home/owner/data/.__tizen_candidate_profile_data";
27
28         private static void stop()
29         {
30             Console.WriteLine("Stop profile and write collected data");
31             ProfileOptimization.StartProfile(null);
32         }
33
34         public static void StopProfileAfterDelay(int sec)
35         {
36             Console.WriteLine($"Stop profile after {sec} sec");
37             Task.Delay(sec * 1000).ContinueWith(_ => stop());
38         }
39
40         public static void SetCandidateProcessProfile()
41         {
42             try
43             {
44                 if (File.Exists(profilePath))
45                 {
46                     Environment.SetEnvironmentVariable("COMPlus_MultiCoreJitNoProfileGather", "1");
47                     Environment.SetEnvironmentVariable("COMPlus_MultiCoreJitMinNumCpus", "1");
48                     ProfileOptimization.SetProfileRoot("");
49                     ProfileOptimization.StartProfile(profilePath);
50                     Console.WriteLine("Completed loading of profile data to the candidate process");
51                 }
52             }
53             catch (Exception e)
54             {
55                 Console.WriteLine(e.ToString());
56             }
57         }
58     }
59 }