# DDR流量检测工具
## 简介
ddr_perf_monitor利用axi协议，监控不同子系统，如CpuSys、McuSys，CamSys的DDR流量。
## 工具组成
1. 内核driver：ddr_perf_monitor.ko。根据设定的监控范围和监控时间，周期采样，保存在缓冲区中，等待用户态工具获取。
2. 用户态工具 hrut_ddr，用于读取用户输入，设置采样周期，采样范围等信息，通过写到ddr perf monitor的寄存器中。纯文本格式输出到console或者以csv格式输出，可用excel软件或python进行解析。
3. 后处理，利用excel或python后处理。
## 基本使用
```bash
hrut_ddr -t all   # 监测总的流量
hrut_ddr -t cam  # 监测camsys流量
```
```bash
root@hobot:~# hrut_ddr -h
Usage: hrut_ddr [OPTION]...
Show and calculate memory throughput through AIX bus in each period.

Mandatory arguments to long options are mandatory for short options too.
   -t, --type     The type of monitoring range.    Supported
                  values for type are(case-insensitive)
                  when multiple type specified, Enclose in quotation marks
                  e.g. -t "mcu cpu"
                  If the types exceeds 1, a RoundRobin method is used.
                        For accuracy, set as less types as possible
                  e.g. In the first period the mcu data is read, second period the cpu data is read.
                  The elapsed time get averaged, and each type result in one round put into one table
                    all  vdo  cam  cpe0  cpe1  cpelite  gpu  vdsp
                   peri  his  sram  bpu  mcu  top  cpu  secland

                        cpu             only monitor the throughput of CPU master range
                        bpu             only monitor the throughput of BPU master range
                        cam             only monitor the throughput of Camera master range
                        all             monitor the throughput of all range types (default)
                        rr_all  RoundRobin between all range types
   -p, --period   The sample period for monitored range. (unit: us, default: 1000)
   -d, --device   The char device of DDR Perf Monitor. [0~5] 0: ddrsys0 mon0, 2 ddrsys1_mon0
                                  2: DDR2, 6: all (default)
   -n, --number   The sampling period times for monitored range before copying to userspace. (0~400] default: 100
                                  !!!When in roundrobin mode, this is forcely set to 1
   -N, --over_all Over_all read times. i.e., approximately how many tables you get in commands line
   -f, --filename the csv output filename
   -r, --raw      Output raw data, hexadecimal format, without conversion. Decimal by default
   -c, --csv      Output csv format data
   -D, --dissh    Disable shell output


J6E SOC, of 3 DDR systems, 2 monitors each SYS, 1 port each monitor
Example:
hrut_ddr -t all -p 1000 -d 0
hrut_ddr -t all -p 1000 -r
hrut_ddr -t cpu -p 1000
hrut_ddr -t "cpu mcu" -p 1000 -f "mon0.csv"
hrut_ddr -d "0 1" -p 1000
```

## 结果分析
### 文本结果分析
> hrut_ddr -t "cam mcu cpu"

![avatar](./media/cam_mcu_cpu.png)
### csv格式分析
* 预览：csv格式可以使用excel或vscode安装“Excel Viewer”插件。
* 格式：按照先monitor总信息，后各port信息的格式。
![avatar](./media/csv1.png)
![avatar](./media/csv2.png)
### csv格式重要列含义解析
* raddr_tx_num：-t指定的DDR读带宽，单位MB/S。
* rdata_tx_num：DDR总的读带宽，单位MB/S
* waddr_tx_num: -t指定的DDR写带宽，单位MB/S
* wdata_tx_num: DDR总的写带宽，单位MB/S

