Skip to content

Sys_README

SweerItTer edited this page Feb 21, 2026 · 4 revisions

Sys 系统监控模块 API 文档

概述

Sys 模块提供系统监控功能,包括 CPU 使用率、内存使用率等系统资源监控。

模块组成

核心类

文档 说明
CpuMonitor Sys_CpuMonitor.md CPU 监控
MemoryMonitor Sys_MemoryMonitor.md 内存监控
ResourceMonitor Sys_Base.md 资源监控基类

功能特性

CPU 监控

  • CPU 使用率查询
  • CPU 核心级别监控
  • 负载平均值查询
  • 实时监控

内存监控

  • 内存使用率查询
  • 可用内存查询
  • 缓存和缓冲区查询

基础工具

  • 文件操作
  • 字符串处理
  • 时间处理

使用示例

CPU 监控

// 创建 CPU 监控器实例
CpuMonitor cpu_monitor(1000);  // 轮询间隔 1000ms

// 获取 CPU 使用率
float cpu_usage = cpu_monitor.getUsage();
printf("CPU Usage: %.2f%%\n", cpu_usage);

// 持续监控示例
for (int i = 0; i < 10; ++i) {
    float usage = cpu_monitor.getUsage();
    printf("CPU Usage [%d]: %.2f%%\n", i, usage);
    sleep(1);
}

内存监控

// 创建内存监控器实例
MemoryMonitor mem_monitor(2000);  // 轮询间隔 2000ms

// 获取内存使用率
float mem_usage = mem_monitor.getUsage();
printf("Memory Usage: %.2f%%\n", mem_usage);

// 持续监控示例
for (int i = 0; i < 5; ++i) {
    float usage = mem_monitor.getUsage();
    printf("Memory Usage [%d]: %.2f%%\n", i, usage);
    sleep(2);
}

线程安全

  • CpuMonitor: 线程安全,所有操作都是线程安全的
  • MemoryMonitor: 线程安全,所有操作都是线程安全的

性能优化

  • 使用状态缓存减少文件读取
  • 批量查询减少开销
  • 合理设置监控间隔

错误处理

  • 检查文件访问权限
  • 处理文件格式错误
  • 记录错误日志

相关模块

参考资料

注意事项

  1. 文件访问: 依赖 /proc 文件系统
  2. 权限: 需要读取 /proc 文件的权限
  3. 性能: 频繁查询可能影响性能
  4. 线程安全: 所有操作都是线程安全的
  5. 单位: 注意单位转换(字节→KB→MB→GB)

版本历史

  • v1.0 - 初始版本,支持基本系统监控

主页

API 文档

DMA 模块

DRM 模块

NET 模块

V4L2 模块

V4L2Param 模块

RGA 模块

MPP 模块

Sys 模块

Mouse 模块

Utils 模块

Clone this wiki locally