打开微信,使用扫一扫进入页面后,点击右上角菜单,
点击“发送给朋友”或“分享到朋友圈”完成分享
我使用samples里面提供的devicequery代码来获取每个进程的利用率
当系统中只有一个进程时候,cndevGetProcessUtilization接口返回的mem_util是正确的,如下所示
当我有启动一个相同进程的时候,cndevGetProcessUtilization接口返回的mem_util异常,表现为其中一个进程的mem_util始终为0
代码如下
#include <cndev.h> #include <stdio.h> int main() { // init libcndev cndevRet_t ret = cndevInit(0); // you can compare cndevRet manually, or just use cndevCheckErrors if (CNDEV_SUCCESS != ret) { printf("cndev init failed: %s.\n", cndevGetErrorString(ret)); // should exit now exit(0); } cndevDevice_t devHandle; ret = cndevGetDeviceHandleByIndex(0, &devHandle); cndevCheckErrors(ret); while (1) { // get card[x]'s process utilization // in most cases, the number of processes running on a card will not exceed 10 // but if cndevProcessUtilization_t's space is not enough, CNDEV_ERROR_INSUFFICIENT_SPACE will be returned unsigned pCount = 10; cndevProcessUtilization_t *procUtil = NULL; procUtil = (cndevProcessUtilization_t *)malloc(pCount * sizeof(cndevProcessUtilization_t)); procUtil->version = CNDEV_VERSION_5; ret = cndevGetProcessUtilization(&pCount, procUtil, devHandle); if (ret == CNDEV_ERROR_NOT_SUPPORTED) { printf("cndevGetProcessUtilization is not supported.\n"); } else { // if ret is CNDEV_ERROR_INSUFFICIENT_SPACE, should get again while (ret == CNDEV_ERROR_INSUFFICIENT_SPACE) { procUtil = (cndevProcessUtilization_t *)realloc(procUtil, pCount * sizeof(cndevProcessUtilization_t)); ret = cndevGetProcessUtilization(&pCount, procUtil, devHandle); } cndevCheckErrors(ret); printf("process: count: %d\n", pCount); for (unsigned int i = 0; i < pCount; i++) { printf( "process %d:pid:%u, IPU Util:%u %%, JPU Util:%u %%, VPU Decoder Util:%u %%, VPU Encoder Util:%u %%, Memory Util:%u " "%%\n", i, (procUtil + i)->pid, (procUtil + i)->ipuUtil, (procUtil + i)->jpuUtil, (procUtil + i)->vpuDecUtil, (procUtil + i)->vpuEncUtil, (procUtil + i)->memUtil); } } free(procUtil); usleep(1000000); } return 0; }
热门帖子
精华帖子