• 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_wrapper.h"
20 
21 #include <ctime>
22 #include <chrono>
23 #include <string>
24 
25 namespace panda::ecmascript {
26 using Clock = std::chrono::high_resolution_clock;
27 using Duration = std::chrono::duration<uint64_t, std::nano>;
28 
29 class AotCompilerStats {
30 public:
AotCompilerStats()31     AotCompilerStats() {};
32     ~AotCompilerStats() = default;
33 
SetBundleName(std::string bundleName)34     void SetBundleName(std::string bundleName)
35     {
36         bundleName_ = bundleName;
37     }
38 
GetBundleName()39     std::string GetBundleName() const
40     {
41         return bundleName_;
42     }
43 
SetPgoPath(std::string pgoFilePath)44     void SetPgoPath(std::string pgoFilePath)
45     {
46         pgoFilePath_ = pgoFilePath;
47     }
48 
GetPgoPath()49     std::string GetPgoPath() const
50     {
51         return pgoFilePath_;
52     }
53 
SetAotFilePath(std::string aotFilePath)54     void SetAotFilePath(std::string aotFilePath)
55     {
56         aotFilePath_ = aotFilePath;
57     }
58 
GetAotFilePath()59     std::string GetAotFilePath() const
60     {
61         return aotFilePath_;
62     }
63 
StartCompiler()64     void StartCompiler()
65     {
66         start_ = Clock::now();
67     }
68 
EndCompiler()69     void EndCompiler()
70     {
71         end_ = Clock::now();
72     }
73 
GetTotalTime()74     float GetTotalTime() const
75     {
76         auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_ - start_);
77         return (float) duration.count() / SECOND_TIME;
78     }
79 
SetIsLiteCg(bool litecg)80     void SetIsLiteCg(bool litecg)
81     {
82         isLiteCg_ = litecg;
83     }
84 
IsLiteCg()85     bool IsLiteCg() const
86     {
87         return isLiteCg_;
88     }
89 
SetCompilerMethodCount(uint32_t count)90     void SetCompilerMethodCount(uint32_t count)
91     {
92         compilerMethodCount_ += count;
93     }
94 
GetCompilerMethodCount()95     uint32_t GetCompilerMethodCount() const
96     {
97         return compilerMethodCount_;
98     }
99 
SetPgoFileLegal(bool legal)100     void SetPgoFileLegal(bool legal)
101     {
102         pgoFileLegal_ = legal;
103     }
104 
GetPgoFileLegal()105     bool GetPgoFileLegal() const
106     {
107         return pgoFileLegal_;
108     }
109 
110     void PUBLIC_API PrintCompilerStatsLog();
111     int32_t PUBLIC_API SendDataPartitionSysEvent(const std::string &path) const;
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