• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_AOT_COMPILER_STATS_H
17 #define ECMASCRIPT_AOT_COMPILER_STATS_H
18 
19 #include "ecmascript/log.h"
20 #include "ecmascript/log_wrapper.h"
21 
22 #include <ctime>
23 #include <chrono>
24 #include <string>
25 
26 namespace panda::ecmascript {
27 using Clock = std::chrono::high_resolution_clock;
28 using Duration = std::chrono::duration<uint64_t, std::nano>;
29 
30 class AotCompilerStats {
31 public:
AotCompilerStats()32     AotCompilerStats() {};
33     ~AotCompilerStats() = default;
34 
SetBundleName(std::string bundleName)35     void SetBundleName(std::string bundleName)
36     {
37         bundleName_ = bundleName;
38     }
39 
GetBundleName()40     std::string GetBundleName() const
41     {
42         return bundleName_;
43     }
44 
SetPgoPath(std::string pgoFilePath)45     void SetPgoPath(std::string pgoFilePath)
46     {
47         pgoFilePath_ = pgoFilePath;
48     }
49 
GetPgoPath()50     std::string GetPgoPath() const
51     {
52         return pgoFilePath_;
53     }
54 
SetAotFilePath(std::string aotFilePath)55     void SetAotFilePath(std::string aotFilePath)
56     {
57         aotFilePath_ = aotFilePath;
58     }
59 
GetAotFilePath()60     std::string GetAotFilePath() const
61     {
62         return aotFilePath_;
63     }
64 
StartCompiler()65     void StartCompiler()
66     {
67         start_ = Clock::now();
68     }
69 
EndCompiler()70     void EndCompiler()
71     {
72         end_ = Clock::now();
73     }
74 
GetTotalTime()75     float GetTotalTime() const
76     {
77         auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_);
78         return (float) duration.count() / SECOND_TIME;
79     }
80 
SetIsLiteCg(bool litecg)81     void SetIsLiteCg(bool litecg)
82     {
83         isLiteCg_ = litecg;
84     }
85 
IsLiteCg()86     bool IsLiteCg() const
87     {
88         return isLiteCg_;
89     }
90 
SetCompilerMethodCount(uint32_t count)91     void SetCompilerMethodCount(uint32_t count)
92     {
93         compilerMethodCount_ += count;
94     }
95 
GetCompilerMethodCount()96     uint32_t GetCompilerMethodCount() const
97     {
98         return compilerMethodCount_;
99     }
100 
SetPgoFileLegal(bool legal)101     void SetPgoFileLegal(bool legal)
102     {
103         pgoFileLegal_ = legal;
104     }
105 
GetPgoFileLegal()106     bool GetPgoFileLegal() const
107     {
108         return pgoFileLegal_;
109     }
110 
111     void PUBLIC_API PrintCompilerStatsLog();
112 
113 private:
114     void SendSysEvent() const;
IsLongTimeCompiler()115     bool IsLongTimeCompiler() const
116     {
117         return GetTotalTime() > longTime_;
118     }
119 
120     std::string bundleName_ = "";
121     std::string pgoFilePath_ = "";
122     std::string aotFilePath_ = "";
123     Clock::time_point start_;
124     Clock::time_point end_;
125     bool isLiteCg_ = false;
126     uint32_t compilerMethodCount_ = 0;
127     bool pgoFileLegal_ = true;
128     float longTime_ = 120;
129     static constexpr uint32_t SECOND_TIME = 1000000;
130 };
131 }
132 
133 #endif // ECMASCRIPT_AOT_COMPILER_STATS_H