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 #ifndef APP_LAUNCH_MONITOR_H
16 #define APP_LAUNCH_MONITOR_H
17 
18 #include "DefaultMonitor.h"
19 #include "IAppThrExecutor.h"
20 #include "IAppLaunchSceneDataProcessor.h"
21 #include "MonitorConfig.h"
22 #include "IAppStartReporter.h"
23 #include "IMonitorRegistry.h"
24 
25 using AppStartMetrics = IAppLaunchSceneDataProcessor::AppStartMetrics;
26 
27 class AppLaunchMonitor :
28     public DefaultMonitor,
29     public IAppLaunchSceneDataProcessor::MetricReporter,
30     public IAppThrExecutor::IProcessAppEvtTask {
31 public:
32     AppLaunchMonitor(IMonitorRegistry* registry, IAppThrExecutor* exec, IAppStartReporter* reporter,
33                      IAppLaunchSceneDataProcessor* scene);
34     void HandleEvt(std::shared_ptr<XperfEvt> evt) override;
35     void ReportMetrics(const AppStartMetrics& metrics) override;
36     void ExecuteProcessAppEvtTaskInMainThr(const IAppThrExecutor::AppEvtData& data) override;
37 
38 private:
39     IAppThrExecutor* exec{nullptr};
40     IAppLaunchSceneDataProcessor* scene{nullptr};
41     IAppStartReporter* reporter{nullptr};
42     IMonitorRegistry* registry{nullptr};
43     int actionId{0};
44     AppStartReportEvent ConstructReportEvent(const AppStartMetrics& metrics);
45     void ReportNormal(const AppStartMetrics& metrics);
46 };
47 #endif