4.14版本内核查看camera ion内存分配情况的方法

转载自https://www.cnblogs.com/szsky/articles/10825335.html

使用4.14版本的内核,ion debug的接口相对于老版本4.9内核发生了变化。4.9版本的内核的ion debug接口在/sys/kernel/debug/ion/clients/和/sys/kernel/debug/ion/heaps/两个目录下,4.14版本已经没有了这两个目录。4.14版本增加了/sys/kernel/debug/dma_buf/dmaprocs节点来导出各进程的ion内存使用情况。

下面以camera为例来看看在4.14版本上如何查看ion内存使用信息。

首先获得要查询进程的PID,我们通过进程名称,在ps命令的输出中查找:

:/ # ps -A | grep camera                                                                                                                                                                          
cameraserver   708     1  749220  47176 binder_ioctl_write_read 0 S android.hardware.camera.provider@2.4-service_64
cameraserver   939     1   39152  18524 binder_ioctl_write_read 0 S cameraserver

输出显示进程android.hardware.camera.provider@2.4-service_64的PID号为708.

然后,在/sys/kernel/debug/dma_buf/dmaprocs节点中查找该PID进程所占用的内存情况:

:/ # cat /sys/kernel/debug/dma_buf/dmaprocs | grep 708                                                                                                                                            
provider@2.4-se (PID 708) size: 205448

输出显示进程名为provider@2.4-se(这是截短的进程名),PID为708,总共使用ion的size为205448,单位为K。

在测试过程中,我们可以通过这种方法来监控该进程的ion内存占用变化情况,判断是否出现ion内存泄漏。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是针对 Linux 内核 4.14 版本的基于 sysfs 的 GPIO 控制和读取的示例程序: ```c #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #define GPIO_OUT_PIN "17" #define GPIO_IN_PIN "18" int main() { int fd_export, fd_direction, fd_value; char gpio_export_path[128], gpio_direction_path[128], gpio_value_path[128]; char value[2]; // 导出 GPIO 引脚 fd_export = open("/sys/class/gpio/export", O_WRONLY); if (fd_export < 0) { perror("无法导出 GPIO 引脚"); return -1; } write(fd_export, GPIO_OUT_PIN, strlen(GPIO_OUT_PIN)); write(fd_export, GPIO_IN_PIN, strlen(GPIO_IN_PIN)); close(fd_export); // 设置 GPIO 引脚为输出模式 snprintf(gpio_direction_path, sizeof(gpio_direction_path), "/sys/class/gpio/gpio%s/direction", GPIO_OUT_PIN); fd_direction = open(gpio_direction_path, O_WRONLY); if (fd_direction < 0) { perror("无法设置 GPIO 引脚为输出模式"); return -1; } write(fd_direction, "out", 3); close(fd_direction); // 设置 GPIO 引脚为输入模式 snprintf(gpio_direction_path, sizeof(gpio_direction_path), "/sys/class/gpio/gpio%s/direction", GPIO_IN_PIN); fd_direction = open(gpio_direction_path, O_WRONLY); if (fd_direction < 0) { perror("无法设置 GPIO 引脚为输入模式"); return -1; } write(fd_direction, "in", 2); close(fd_direction); // 控制 GPIO 输出引脚为高电平 snprintf(gpio_value_path, sizeof(gpio_value_path), "/sys/class/gpio/gpio%s/value", GPIO_OUT_PIN); fd_value = open(gpio_value_path, O_WRONLY); if (fd_value < 0) { perror("无法控制 GPIO 输出引脚电平"); return -1; } write(fd_value, "1", 1); close(fd_value); // 读取 GPIO 输入引脚电平 snprintf(gpio_value_path, sizeof(gpio_value_path), "/sys/class/gpio/gpio%s/value", GPIO_IN_PIN); fd_value = open(gpio_value_path, O_RDONLY); if (fd_value < 0) { perror("无法读取 GPIO 输入引脚电平"); return -1; } read(fd_value, value, sizeof(value)); close(fd_value); // 判断输入电平是否与输出电平一致 if (value[0] == '1') { printf("输入电平与输出电平一致,返回 0\n"); return 0; } else { printf("输入电平与输出电平不一致,返回 -1\n"); return -1; } } ``` 请确保将 `GPIO_OUT_PIN` 和 `GPIO_IN_PIN` 的值分别设置为所需的输出和输入引脚的 GPIO 编号。请根据您的实际硬件进行调整。 此程序使用 sysfs 接口来控制和读取 GPIO 引脚的状态。它首先导出指定的 GPIO 引脚,然后设置输出引脚为输出模式,输入引脚为输入模式。接下来,它控制输出引脚为高电平,并读取输入引脚的电平。最后,根据比较结果返回 0 或 -1。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值