1 /*
2  * Copyright (c) 2020 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 #ifndef OHOS_ACELITE_PROFILER_MODULE_H
16 #define OHOS_ACELITE_PROFILER_MODULE_H
17 
18 #include "js_profiler.h"
19 #include "non_copyable.h"
20 #if IS_ENABLED(JS_PROFILER)
21 #include "presets/preset_module.h"
22 namespace OHOS {
23 namespace ACELite {
24 static constexpr char profiler[] = "profiler";
25 class ProfilerModule final : public PresetModule {
26 public:
27     ACE_DISALLOW_COPY_AND_MOVE(ProfilerModule);
28     /**
29      * @fn ProfilerModule::ProfilerModule()
30      *
31      * @brief Constructor.
32      */
ProfilerModule()33     ProfilerModule() : PresetModule(profiler) {}
34 
35     /**
36      * @fn ProfilerModule::~ProfilerModule()
37      *
38      * @brief Constructor.
39      */
40     ~ProfilerModule() = default;
41 
42     void Init() override;
43 
44 private:
45     /**
46      * @fn ProfilerModule::StartTracing()
47      *
48      * @brief request to start the tracing.
49      * @param func function object
50      * @param context the context of function execution
51      * @param args the list of arguments
52      * @param argsNum the num of arguments list
53      */
54     static jerry_value_t StartTracing(const jerry_value_t func,
55                                       const jerry_value_t context,
56                                       const jerry_value_t *args,
57                                       const jerry_length_t argsNum);
58 
59     /**
60      * @fn ProfilerModule::StopTracing()
61      *
62      * @brief request to start the tracing.
63      * @param func function object
64      * @param context the context of function execution
65      * @param args the list of arguments
66      * @param argsNum the num of arguments list
67      */
68     static jerry_value_t StopTracing(const jerry_value_t func,
69                                      const jerry_value_t context,
70                                      const jerry_value_t *args,
71                                      const jerry_length_t argsNum);
72 };
73 } // namespace ACELite
74 } // namespace OHOS
75 #endif
76 namespace OHOS {
77 namespace ACELite {
78 class PerformaceProfilerModule final {
79 public:
80     ACE_DISALLOW_COPY_AND_MOVE(PerformaceProfilerModule);
81     PerformaceProfilerModule() = default;
82     ~PerformaceProfilerModule() = default;
Load()83     static void Load()
84     {
85 #if IS_ENABLED(JS_PROFILER)
86         ProfilerModule profilerModule;
87         profilerModule.Init();
88 #endif
89     }
90 };
91 } // namespace ACELite
92 } // namespace OHOS
93 #endif // OHOS_ACELITE_PROFILER_MODULE_H
94