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 XPERF_PLUGIN_H
16 #define XPERF_PLUGIN_H
17 
18 #include <map>
19 #include "plugin.h"
20 #include "IMonitor.h"
21 #include "sys_event.h"
22 #include "IXperfContext.h"
23 #include "app_event_publisher.h"
24 #include "IEventObserver.h"
25 
26 namespace OHOS {
27     namespace HiviewDFX {
28         class XperfPlugin : public AppEventPublisher, public IEventObserver {
29         public:
30             void OnLoad() override;
31             void OnUnload() override;
32             void OnEventListeningCallback(const Event& event) override;
33             void AddAppEventHandler(std::shared_ptr<AppEventHandler> handler) override;
34             void PostAppStartEvent(const AppStartInfo& ase) override;
35             void PostScrollJankEvent(const ScrollJankInfo& scrollJankInfo) override;
36 
37         private:
38             std::shared_ptr<IXperfContext> perfContext{nullptr};
39             static constexpr const char* const PLUGIN_NAME = "Xperf";
40             static constexpr const char* const PLUGIN_VERSION = "Xperf 1.0";
41             std::shared_ptr<AppEventHandler> appEventHandler{nullptr};
42 
43             void XperfDispatch(const SysEvent &sysEvent);
44             void DispatchToMonitor(unsigned int logId, std::shared_ptr<XperfEvt> xperfEvt);
45             void NormalInit();
46         };
47     } // HiviewDFX
48 } // OHOS
49 #endif