# 系统信息

本示例演示如何从板卡获取系统信息（内存使用率、CPU使用率和温度）。

## 示例

示例脚本输出

```bash
Ddr used / total - 0.13 / 414.80 MiB
  Cmx used / total - 2.24 / 2.50 MiB
  LeonCss heap used / total - 4.17 / 46.41 MiB
  LeonMss heap used / total - 2.87 / 27.58 MiB
  Chip temperature - average: 38.59, css: 39.81, mss: 37.71, upa: 38.65, dss: 38.18
  Cpu usage - Leon CSS: 7.08%, Leon MSS: 1.48 %
  ----------------------------------------
  Ddr used / total - 0.13 / 414.80 MiB
  Cmx used / total - 2.24 / 2.50 MiB
  LeonCss heap used / total - 4.17 / 46.41 MiB
  LeonMss heap used / total - 2.87 / 27.58 MiB
  Chip temperature - average: 38.59, css: 39.58, mss: 37.94, upa: 38.18, dss: 38.65
  Cpu usage - Leon CSS: 1.55%, Leon MSS: 0.30 %
  ----------------------------------------
  Ddr used / total - 0.13 / 414.80 MiB
  Cmx used / total - 2.24 / 2.50 MiB
  LeonCss heap used / total - 4.17 / 46.41 MiB
  LeonMss heap used / total - 2.87 / 27.58 MiB
  Chip temperature - average: 38.94, css: 40.04, mss: 38.18, upa: 39.35, dss: 38.18
  Cpu usage - Leon CSS: 0.56%, Leon MSS: 0.06 %
  ----------------------------------------
  Ddr used / total - 0.13 / 414.80 MiB
  Cmx used / total - 2.24 / 2.50 MiB
  LeonCss heap used / total - 4.17 / 46.41 MiB
  LeonMss heap used / total - 2.87 / 27.58 MiB
  Chip temperature - average: 39.46, css: 40.28, mss: 38.88, upa: 39.81, dss: 38.88
  Cpu usage - Leon CSS: 0.51%, Leon MSS: 0.06 %
  ----------------------------------------
```

 * upa 表示 SHAVE 模块的温度
 * dss 表示 DDR 子系统的温度

这个示例需要DepthAI v3 API，参见[安装说明](https://docs.luxonis.com/software-v3/depthai.md)。

## 源代码

#### Python

```python
#!/usr/bin/env python3

import depthai as dai

def printSystemInformation(info: dai.SystemInformation):
    m = 1024 * 1024 # MiB
    print(f"Ddr used / total - {info.ddrMemoryUsage.used / m:.2f} / {info.ddrMemoryUsage.total / m:.2f} MiB")
    print(f"Cmx used / total - {info.cmxMemoryUsage.used / m:.2f} / {info.cmxMemoryUsage.total / m:.2f} MiB")
    print(f"LeonCss heap used / total - {info.leonCssMemoryUsage.used / m:.2f} / {info.leonCssMemoryUsage.total / m:.2f} MiB")
    print(f"LeonMss heap used / total - {info.leonMssMemoryUsage.used / m:.2f} / {info.leonMssMemoryUsage.total / m:.2f} MiB")
    t = info.chipTemperature
    print(f"Chip temperature - average: {t.average:.2f}, css: {t.css:.2f}, mss: {t.mss:.2f}, upa: {t.upa:.2f}, dss: {t.dss:.2f}")
    print(f"Cpu usage - Leon CSS: {info.leonCssCpuUsage.average * 100:.2f}%, Leon MSS: {info.leonMssCpuUsage.average * 100:.2f} %")
    print("----------------------------------------")

# 创建管道
pipeline = dai.Pipeline()

# 创建系统日志记录节点
sysLog = pipeline.create(dai.node.SystemLogger)
sysLog.setRate(1)  # 1 赫兹

# 创建输出
sysLogQueue = sysLog.out.createOutputQueue(maxSize=4, blocking=False)

# 启动管道
pipeline.start()
while pipeline.isRunning():
    sysInfo = sysLogQueue.get() # 阻塞调用，将等待直到有新数据到达
    printSystemInformation(sysInfo)
```

## Pipeline

### examples/system_information.pipeline.json

```json
{
  "pipeline": {
    "connections": [
      {
        "node1Id": 0,
        "node1Output": "out",
        "node1OutputGroup": "",
        "node2Id": 1,
        "node2Input": "in",
        "node2InputGroup": ""
      }
    ],
    "globalProperties": {
      "calibData": null,
      "cameraTuningBlobSize": null,
      "cameraTuningBlobUri": "",
      "leonCssFrequencyHz": 700000000.0,
      "leonMssFrequencyHz": 700000000.0,
      "pipelineName": null,
      "pipelineVersion": null,
      "sippBufferSize": 18432,
      "sippDmaBufferSize": 16384,
      "xlinkChunkSize": -1
    },
    "nodes": [
      [
        0,
        {
          "id": 0,
          "ioInfo": [
            [
              [
                "",
                "out"
              ],
              {
                "blocking": false,
                "group": "",
                "id": 1,
                "name": "out",
                "queueSize": 8,
                "type": 0,
                "waitForMessage": false
              }
            ]
          ],
          "name": "SystemLogger",
          "properties": {
            "rateHz": 1.0
          }
        }
      ],
      [
        1,
        {
          "id": 1,
          "ioInfo": [
            [
              [
                "",
                "in"
              ],
              {
                "blocking": true,
                "group": "",
                "id": 2,
                "name": "in",
                "queueSize": 8,
                "type": 3,
                "waitForMessage": true
              }
            ]
          ],
          "name": "XLinkOut",
          "properties": {
            "maxFpsLimit": -1.0,
            "metadataOnly": false,
            "streamName": "sysinfo"
          }
        }
      ]
    ]
  }
}
```

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
