9c40707b820b941abbb873a79c49e6b04bb4bcd1
[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
27         const string profilePath = "/home/owner/data/.__tizen_candidate_profile_data";
28
29         private static void stop()
30         {
31             Console.WriteLine("Stop profile and write collected data");
32             ProfileOptimization.StartProfile(null);
33         }
34
35         public static void StopProfileAfterDelay(int sec)
36         {
37             Console.WriteLine($"Stop profile after {sec} sec");
38             Task.Delay(sec * 1000).ContinueWith(_ => stop());
39         }
40
41         public static void SetCandidateProcessProfile()
42         {
43             try
44             {
45                 if (File.Exists(profilePath))
46                 {
47                     Environment.SetEnvironmentVariable("COMPlus_MultiCoreJitNoProfileGather", "1");
48                     Environment.SetEnvironmentVariable("COMPlus_MultiCoreJitMinNumCpus", "1");
49                     ProfileOptimization.SetProfileRoot("");
50                     ProfileOptimization.StartProfile(profilePath);
51                 }
52             }
53             catch (Exception e)
54             {
55                 Console.WriteLine(e.ToString());
56             }
57         }
58     }
59 }