Hiview 架构
1. 模块概述
源码:https://gitee.com/openharmony/hiviewdfx_hiview
1.1 功能与目标
主要功能
Hiview(HiviewDFX)是OpenHarmony系统中的跨平台终端设备维测服务集,主要提供以下核心功能:
- 系统事件管理:收集、处理和分发系统事件(HiSysEvent)
- 故障日志管理:记录和管理系统故障日志(Faultlogger)
- 事件日志收集:收集应用和系统的事件日志(EventLogger)
- 冻屏检测:检测和分析系统冻屏问题(FreezeDetector)
- 性能监控:系统性能数据采集和分析
- 统一采集:提供统一的数据采集框架(UnifiedCollector)
设计目标
- 提供插件化的维测服务架构,支持功能模块的动态加载和卸载
- 实现事件驱动的处理机制,高效处理系统事件
- 支持流水线式的事件处理流程
- 提供可扩展的插件开发框架
使用场景
- 系统故障诊断与分析
- 应用崩溃日志收集
- 系统性能监控与优化
- 设备维护与问题排查
1.2 系统位置
在DFX子系统中的位置
OpenHarmony 系统
DFX 子系统
★ Hiview 组件 ★
插件管理平台
(Plugin Platform)
Faultlogger
EventLogger
FreezeDetector
Performance
HiLog
HiSysEvent
HiAppEvent
FaultLoggerd
模块角色
- 核心模块:Hiview是DFX子系统的核心组件,负责统一管理和协调各维测功能
- 与其他模块关系 :
- 接收来自HiSysEvent的系统事件
- 接收来自HiAppEvent的应用事件
- 与FaultLoggerd协作处理崩溃日志
- 通过HiLog输出日志信息
1.3 设计思路与模式
设计理念
- 插件化架构:所有功能模块以插件形式存在,支持动态加载/卸载
- 事件驱动:基于事件的处理机制,通过HiSysEvent桩点收集事件
- 流水线处理:事件按流水线顺序经过多个插件处理
- 松耦合设计:插件间通过事件订阅机制通信,降低耦合度
采用的设计模式
| 设计模式 | 应用场景 | 说明 |
|---|---|---|
| 工厂模式 | PluginFactory | 用于创建和管理插件实例 |
| 单例模式 | HiviewPlatform | 平台管理器全局唯一实例 |
| 观察者模式 | EventListener | 事件订阅和通知机制 |
| 代理模式 | PluginProxy | 插件代理,支持延迟加载 |
| 责任链模式 | Pipeline | 流水线式事件处理 |
| 策略模式 | EventHandler | 不同事件的处理策略 |
1.4 系统框图
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hiview 系统架构 │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Hiview Service (服务层) │ │
│ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │
│ │ │ HiviewService │ │ ServiceAdapter │ │ Dump Service │ │ │
│ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Hiview Core (核心层) │ │
│ │ ┌──────────────────────────────────────────────────────────────────┐ │ │
│ │ │ HiviewPlatform (插件管理平台) │ │ │
│ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │ │ │
│ │ │ │PluginConfig │ │PluginBundle│ │ Pipeline │ │ EventLoop │ │ │ │
│ │ │ └─────────────┘ └─────────────┘ └─────────────┘ └────────────┘ │ │ │
│ │ └──────────────────────────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Hiview Base (基础层) │ │
│ │ ┌─────────┐ ┌─────────┐ ┌───────────┐ ┌─────────┐ ┌───────────────┐ │ │
│ │ │ Plugin │ │ Event │ │EventSource│ │Pipeline │ │ EventListener │ │ │
│ │ └─────────┘ └─────────┘ └───────────┘ └─────────┘ └───────────────┘ │ │
│ │ ┌─────────────────────────────────────────────────────────────────┐ │ │
│ │ │ Utility (工具类) │ │ │
│ │ │ FileUtil | StringUtil | TimeUtil | CommonUtils | DbUtil │ │ │
│ │ └─────────────────────────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Plugins (插件层) │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │SysEventSource│ │ Faultlogger │ │ EventLogger │ │FreezeDetector│ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ Performance │ │UnifiedCollect│ │UsageEventRpt│ │EventValidator│ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Adapter (适配层) │ │
│ │ ┌─────────────────────┐ ┌─────────────────────┐ │ │
│ │ │ EventService Adapter│ │ Service Adapter │ │ │
│ │ └─────────────────────┘ └─────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
2. 模块结构
2.1 源文件与头文件
目录结构
hiviewdfx_hiview/
├── adapter/ # 平台适配层
│ ├── plugins/
│ │ ├── eventlogger/ # EventLogger适配
│ │ └── eventservice/ # EventService适配
│ └── service/ # 服务适配
│ ├── client/ # 客户端实现
│ ├── common/ # 公共组件
│ └── server/ # 服务端实现
│
├── base/ # 基础模块定义
│ ├── include/ # 头文件
│ │ ├── plugin.h # 插件基类定义
│ │ ├── event.h # 事件基类定义
│ │ ├── event_source.h # 事件源定义
│ │ ├── pipeline.h # 流水线定义
│ │ ├── event_loop.h # 事件循环定义
│ │ └── plugin_factory.h # 插件工厂定义
│ ├── utility/ # 工具类
│ ├── event_publish/ # 事件发布
│ ├── event_raw/ # 原始事件处理
│ ├── event_report/ # 事件上报
│ ├── event_store/ # 事件存储
│ └── logstore/ # 日志存储
│
├── core/ # 核心模块
│ ├── include/
│ │ └── hiview_platform.h # 平台管理器
│ ├── bundle_config/ # 插件包配置
│ ├── param_update/ # 参数更新
│ └── platform_config/ # 平台配置
│
├── plugins/ # 插件模块
│ ├── sysevent_source/ # 系统事件源
│ ├── faultlogger/ # 故障日志插件
│ ├── eventlogger/ # 事件日志插件
│ ├── freeze_detector/ # 冻屏检测插件
│ ├── performance/ # 性能监控插件
│ ├── unified_collector/ # 统一采集插件
│ ├── usage_event_report/ # 使用事件上报
│ ├── event_validator/ # 事件验证器
│ └── reliability/ # 可靠性插件
│
├── service/ # Hiview服务
│ ├── hiview_service.h # 服务头文件
│ └── hiview_service.cpp # 服务实现
│
├── interfaces/ # 接口层
│ ├── inner_api/ # 内部API
│ ├── js/ # JavaScript接口
│ └── ets/ # ArkTS接口
│
├── framework/ # 框架层
│ └── native/ # Native实现
│
└── main.cpp # 程序入口
主要文件功能说明
| 文件/目录 | 功能描述 |
|---|---|
base/include/plugin.h |
定义Plugin基类,所有插件的父类 |
base/include/event.h |
定义Event基类和EventListener |
base/include/event_source.h |
定义EventSource事件源基类 |
base/include/pipeline.h |
定义Pipeline流水线和PipelineEvent |
base/include/event_loop.h |
定义EventLoop事件循环机制 |
core/include/hiview_platform.h |
定义HiviewPlatform平台管理器 |
base/include/sys_event.h |
定义SysEvent系统事件 |
2.2 类、结构体、函数与方法
2.2.1 核心类定义
Plugin 类(插件基类)
cpp
class Plugin : public EventHandler, public std::enable_shared_from_this<Plugin> {
public:
enum class PluginType {
STATIC, // 静态插件
DYNAMIC, // 动态插件
PROXY, // 代理插件
};
// 生命周期方法
virtual void OnLoad(); // 插件加载时调用
virtual void OnUnload(); // 插件卸载时调用
virtual bool ReadyToLoad(); // 判断是否可加载
// 事件处理方法
virtual bool OnEvent(std::shared_ptr<Event>& event); // 处理事件
virtual bool CanProcessEvent(std::shared_ptr<Event> event); // 判断能否处理事件
virtual bool IsInterestedPipelineEvent(std::shared_ptr<Event> event);
virtual bool CanProcessMoreEvents();
// 监听回调
virtual void OnEventListeningCallback(const Event &msg);
// 工具方法
void DelayProcessEvent(std::shared_ptr<Event> event, uint64_t delay);
HiviewContext* GetHiviewContext();
const std::string& GetName();
const std::string& GetVersion();
void BindWorkLoop(std::shared_ptr<EventLoop> loop);
protected:
std::string name_; // 插件名称
std::string version_; // 插件版本
std::shared_ptr<EventLoop> workLoop_; // 工作线程
PluginType type_ = PluginType::STATIC; // 插件类型
};
Event 类(事件基类)
cpp
class Event : public std::enable_shared_from_this<Event> {
public:
// 事件类型枚举
enum MessageType {
NONE = 0,
PLUGIN_MAINTENANCE, // 插件维护
FAULT_EVENT, // 故障事件
STATISTICS_EVENT, // 统计事件
RAW_EVENT, // 原始事件
SYS_EVENT, // 系统事件
UE_EVENT, // 用户体验事件
EXTERNAL_EVENT, // 外部事件
};
enum ManageType {
ORDERED, // 有序处理
UNORDERED, // 无序处理
};
// 成员变量
MessageType messageType_;
ManageType processType_;
uint32_t eventId_;
uint64_t happenTime_;
std::string sender_;
std::string domain_;
std::string eventName_;
bool isPipeline_;
// 方法
virtual bool OnContinue();
virtual bool OnFinish();
void SetValue(const std::string &name, const std::string &value);
const std::string GetValue(const std::string &name) const;
};
EventSource 类(事件源基类)
cpp
class EventSource : public PipelineEventProducer, public Plugin {
public:
virtual void StartEventSource(); // 启动事件源
virtual void Recycle(PipelineEvent* event); // 回收事件
virtual void PauseDispatch(std::weak_ptr<Plugin> plugin); // 暂停分发
bool PublishPipelineEvent(std::shared_ptr<PipelineEvent> event); // 发布事件
void AddPipeline(std::shared_ptr<Pipeline> pipeline); // 添加流水线
private:
std::list<std::shared_ptr<Pipeline>> listeners_; // 流水线列表
};
Pipeline 类(流水线)
cpp
class Pipeline : public std::enable_shared_from_this<Pipeline> {
public:
Pipeline(const std::string& name, std::list<std::weak_ptr<Plugin>>& processors);
bool CanProcessEvent(std::shared_ptr<PipelineEvent> event); // 判断能否处理
void ProcessEvent(std::shared_ptr<PipelineEvent> event); // 处理事件
const std::string& GetName() const; // 获取名称
std::list<std::weak_ptr<Plugin>> GetProcessSequence(); // 获取处理序列
void AppendProcessor(std::weak_ptr<Plugin> plugin); // 添加处理器
void RemoveProcessor(std::weak_ptr<Plugin> plugin); // 移除处理器
private:
std::string name_; // 流水线名称
std::list<std::weak_ptr<Plugin>> processors_; // 处理器列表
};
HiviewPlatform 类(平台管理器)
cpp
class HiviewPlatform : public HiviewContext, public Singleton<HiviewPlatform> {
public:
bool InitEnvironment(const std::string& platformConfigDir = "");
void StartLoop();
// 事件处理
void PostUnorderedEvent(std::shared_ptr<Plugin> plugin, std::shared_ptr<Event> event);
void RegisterUnorderedEventListener(std::weak_ptr<EventListener> listener);
bool PostSyncEventToTarget(std::shared_ptr<Plugin> caller, const std::string& calleeName,
std::shared_ptr<Event> event);
void PostAsyncEventToTarget(std::shared_ptr<Plugin> caller, const std::string& calleeName,
std::shared_ptr<Event> event);
// 插件管理
void RequestUnloadPlugin(std::shared_ptr<Plugin> caller);
std::shared_ptr<Plugin> GetPluginByName(const std::string& name);
std::shared_ptr<Plugin> InstancePluginByProxy(std::shared_ptr<Plugin> proxy);
// 流水线管理
std::list<std::weak_ptr<Plugin>> GetPipelineSequenceByName(const std::string& name);
void AppendPluginToPipeline(const std::string& pluginName, const std::string& pipelineName);
// 工作循环
std::shared_ptr<EventLoop> GetSharedWorkLoop();
std::shared_ptr<EventLoop> GetMainWorkLoop();
// 目录管理
std::string GetHiViewDirectory(DirectoryType type);
// 属性管理
std::string GetHiviewProperty(const std::string& key, const std::string& defaultValue);
bool SetHiviewProperty(const std::string& key, const std::string& value, bool forceUpdate);
bool IsReady();
private:
std::map<std::string, std::shared_ptr<Plugin>> pluginMap_;
std::map<std::string, std::shared_ptr<Pipeline>> pipelines_;
std::map<std::string, std::shared_ptr<EventLoop>> privateWorkLoopMap_;
std::shared_ptr<EventDispatchQueue> unorderQueue_;
std::shared_ptr<EventLoop> sharedWorkLoop_;
std::shared_ptr<EventLoop> mainWorkLoop_;
};
EventLoop 类(事件循环)
cpp
class EventLoop {
public:
explicit EventLoop(const std::string &name);
virtual ~EventLoop();
void StartLoop(bool createNewThread = true);
void StopLoop();
// 文件描述符事件
bool AddFileDescriptorEventCallback(const std::string &name,
std::shared_ptr<FileDescriptorEventCallback> source);
bool RemoveFileDescriptorEventCallback(const std::string &name);
// 事件处理
uint64_t AddEvent(std::shared_ptr<EventHandler> handler, std::shared_ptr<Event> event,
const Task task = nullptr);
std::future<bool> AddEventForResult(std::shared_ptr<EventHandler> handler,
std::shared_ptr<Event> event);
// 定时事件
virtual uint64_t AddTimerEvent(std::shared_ptr<EventHandler> handler,
std::shared_ptr<Event> event, const Task &task, uint64_t interval, bool repeat);
bool RemoveEvent(uint64_t seq);
const std::string &GetName() const;
bool IsRunning() const;
private:
std::string name_;
EventPriorityQueue<LoopEvent> pendingEvents_;
std::unique_ptr<std::thread> thread_;
};
2.2.2 继承关系与多态
enable_shared_from_this<Plugin>
enable_shared_from_this<Event>
<<interface>>
EventHandler
+OnEvent()
+CanProcessEvent()
Plugin
#name_: string
#version_: string
#workLoop_: shared_ptr
#type_: PluginType
+OnLoad()
+OnUnload()
+OnEvent()
+GetHiviewContext()
EventSource
-listeners_: list
+StartEventSource()
+PublishPipelineEvent()
+Recycle()
SysEventSource
-eventServer_
-platformMonitor_
+OnLoad()
+StartEventSource()
Faultlogger
-faultLogManager_
+OnEvent()
+OnLoad()
+Dump()
EventLogger
-eventLoggerConfig_
+OnEvent()
+OnLoad()
+GetListenerName()
Event
+messageType_
+eventId_
+sender_
+domain_
+eventName_
+OnContinue()
+OnFinish()
PipelineEvent
-handler_
-pipelineName_
-processors_
+SetPipelineInfo()
+OnContinue()
SysEvent
+eventType_
+seq_
+pid_, tid_, uid_
+GetEventValue()
+SetEventValue()
<<interface>>
EventListener
+OnUnorderedEvent()
+GetListenerName()
2.3 类图
1 1 1 1 1 * * * * * <<interface>>
EventHandler
+OnEvent(event) : bool
+CanProcessEvent(event) : bool
Plugin
-name_: string
-version_: string
-workLoop_: shared_ptr<EventLoop>
-type_: PluginType
+OnLoad()
+OnUnload()
+OnEvent(event) : bool
+GetHiviewContext() : HiviewContext
+GetName() : string
EventSource
-listeners_: list<Pipeline>
+StartEventSource()
+PublishPipelineEvent(event) : bool
+AddPipeline(pipeline)
+Recycle(event)
SysEventSource
-eventServer_: EventServer
-platformMonitor_: PlatformMonitor
+OnLoad()
+StartEventSource()
+PublishPipelineEvent(event) : bool
Faultlogger
-faultLogManager_: shared_ptr
-faultLogBootScan_: shared_ptr
+OnEvent(event) : bool
+OnLoad()
+Dump(fd, cmds)
EventLogger
-eventLoggerConfig_: unordered_map
-threadLoop_: shared_ptr<EventLoop>
+OnEvent(event) : bool
+OnLoad()
+GetListenerName() : string
Event
+messageType_: MessageType
+processType_: ManageType
+eventId_: uint32_t
+happenTime_: uint64_t
+sender_: string
+domain_: string
+eventName_: string
+OnContinue() : bool
+OnFinish() : bool
+SetValue(name, value)
+GetValue(name) : string
PipelineEvent
-handler_: PipelineEventProducer
-pipelineName_: string
-processors_: list<Plugin>
+SetPipelineInfo(name, processors)
+OnContinue() : bool
+OnFinish() : bool
SysEvent
+eventType_: int32_t
+seq_: int64_t
+pid_: int32_t
+tid_: int32_t
+uid_: int32_t
+GetEventValue(key) : string
+SetEventValue(key, value)
+AsJsonStr() : string
Pipeline
-name_: string
-processors_: list<Plugin>
+CanProcessEvent(event) : bool
+ProcessEvent(event)
+GetName() : string
+AppendProcessor(plugin)
EventLoop
-name_: string
-pendingEvents_: EventPriorityQueue
-thread_: unique_ptr<thread>
+StartLoop(createNewThread)
+StopLoop()
+AddEvent(handler, event) : uint64_t
+AddTimerEvent(handler, event, task, interval, repeat) : uint64_t
HiviewPlatform
-pluginMap_: map<string, Plugin>
-pipelines_: map<string, Pipeline>
-privateWorkLoopMap_: map<string, EventLoop>
-sharedWorkLoop_: shared_ptr<EventLoop>
+InitEnvironment(configDir) : bool
+StartLoop()
+PostUnorderedEvent(plugin, event)
+GetPluginByName(name) : Plugin
+GetPipelineSequenceByName(name) : list
2.4 模块内部依赖框图
┌─────────────────────────────────────────────────────────────────────────────┐
│ 模块内部依赖关系 │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Service Layer │ │
│ │ ┌───────────────┐ │ │
│ │ │ HiviewService │ │ │
│ │ └───────┬───────┘ │ │
│ └──────────│────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Core Layer │ │
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
│ │ │ HiviewPlatform │ │ │
│ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │
│ │ │ │PluginManager │ │PipelineManager│ │ EventDispatch │ │ │ │
│ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │
│ │ └─────────│─────────────────│─────────────────│────────────────┘ │ │
│ └────────────│─────────────────│─────────────────│─────────────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Base Layer │ │
│ │ │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Plugin │◄───│EventSource │ │ Pipeline │ │ │
│ │ └─────┬──────┘ └─────┬──────┘ └─────┬──────┘ │ │
│ │ │ │ │ │ │
│ │ │ ┌────────────┴────────────┐ │ │ │
│ │ │ │ │ │ │ │
│ │ ▼ ▼ ▼ ▼ │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
│ │ │ Event │◄───│PipelineEvent│───►│ EventLoop │ │ │
│ │ └────────────┘ └────────────┘ └────────────┘ │ │
│ │ ▲ │ │
│ │ │ │ │
│ │ ┌─────┴──────┐ │ │
│ │ │ SysEvent │ │ │
│ │ └────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
│ │ │ Utility │ │ │
│ │ │ FileUtil │ StringUtil │ TimeUtil │ DbUtil │ CommonUtils │ │ │
│ │ └─────────────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Plugin Layer │ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │SysEventSource│ │ Faultlogger │ │ EventLogger │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ │ │ │ │ │ │
│ │ │ │ │ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │EventValidator│ │FreezeDetector│ │ Performance │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
3. 模块间交互
3.1 交互描述
3.1.1 与外部系统的交互
| 外部系统 | 交互方式 | 说明 |
|---|---|---|
| HiSysEvent | Socket通信 | 接收系统事件上报 |
| HiAppEvent | API调用 | 接收应用事件上报 |
| FaultLoggerd | IPC通信 | 获取崩溃堆栈信息 |
| HiLog | API调用 | 输出日志信息 |
| HiDumper | IPC通信 | 提供dump信息导出 |
| 数据库 | SQLite | 持久化存储事件数据 |
3.1.2 异步处理机制
Hiview采用事件驱动的异步处理机制:
-
EventLoop事件循环
- 每个插件可以绑定独立的EventLoop线程
- 支持定时事件和延迟事件
- 基于优先级队列的事件调度
-
事件分发队列
- EventDispatchQueue负责无序事件的分发
- 支持事件广播到多个订阅者
-
流水线处理
- 事件按流水线顺序依次处理
- 支持事件的暂停和恢复
3.1.3 多线程处理
线程配置模式
singledthread: 插件独享线程
sharedthread: 多个插件共享线程
Main Thread
主线程:平台初始化、插件加载
Shared WorkLoop
共享工作线程:处理公共任务
Plugin Loop 1
Plugin Loop 2
Plugin Loop 3
Plugin Loop N
3.2 外部依赖框图
┌─────────────────────────────────────────────────────────────────────────────┐
│ 外部依赖关系图 │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ │
│ │ Application │ │
│ │ Layer │ │
│ └────────┬────────┘ │
│ │ │
│ ┌───────────────────────┼───────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ HiAppEvent │ │ HiSysEvent │ │ FaultLoggerd│ │
│ │ (应用事件) │ │ (系统事件) │ │ (崩溃收集) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ └──────────────────────┼──────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ HIVIEW │ │
│ │ ┌───────────────────────────────────────────────────────────────┐ │ │
│ │ │ 插件管理平台 │ │ │
│ │ └───────────────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┼──────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ HiLog │ │ SQLite DB │ │ c_utils │ │
│ │ (日志) │ │ (数据存储) │ │ (基础工具) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 其他依赖组件 │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │
│ │ │ SAMGR │ │ IPC │ │ HiCollie │ │ HiTrace │ │ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────┘ │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │
│ │ │ FFRT │ │ OpenSSL │ │ zlib │ │ jsoncpp │ │ │
│ │ └───────────┘ └───────────┘ └───────────┘ └───────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
附录
A. 插件注册宏定义
cpp
// 静态注册(永不卸载)
REGISTER(PluginClassName);
// 代理注册(运行时动态加载卸载)
REGISTER_PROXY(PluginClassName);
// 代理注册且开机加载
REGISTER_PROXY_WITH_LOADED(PluginClassName);
B. 配置文件格式
plugin_config 示例
plugins:4
SysEventSource[thread:sysevent_source]:0 static
Faultlogger[thread:faultlogger]:0 static
EventLogger[thread:eventlogger]:0 static
FreezeDetector[]:0 static
pipelines:1
SysEventPipeline:Faultlogger EventLogger FreezeDetector
pipelinegroups:1
SysEventSource:SysEventPipeline