应该是先调用一个接口,然后再调用另一个接口。之间有个时间差,这段时间可能ipu运行,也可能没运行,这样两个接口获得的利用率就不太一样展开
应该是先调用一个接口,然后再调用另一个接口。之间有个时间差,这段时间可能ipu运行,也可能没运行,这样两个接口获得的利用率就不太一样展开
#include <cndev.h> #include <stdio.h> #include <sys/time.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); struct timeval tv; 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++) { gettimeofday(&tv, NULL); printf("[time:%ld.%ld] ", tv.tv_sec, tv.tv_usec); printf("process %d:pid:%u, IPU Util:%u %%, Memory Util:%u %%\n", i, (procUtil + i)->pid, (procUtil + i)->ipuUtil, (procUtil + i)->memUtil); // printf("pid:%u, IPU Util:%u %%, jpu Util:%u %%, vpu Enc Util:%u %%, vpu Dec Util:%u %%\n", // (procUtil + i)->pid, (procUtil + i)->ipuUtil, // (procUtil + i)->jpuUtil, (procUtil + i)->vpuEncUtil, // (procUtil + i)->vpuDecUtil); } } free(procUtil); // get card[x]'s MLU utilization cndevUtilizationInfo_t utilInfo; utilInfo.version = CNDEV_VERSION_5; cndevCheckErrors(cndevGetDeviceUtilizationInfo(&utilInfo, devHandle)); gettimeofday(&tv, NULL); printf("[time:%ld.%ld] ", tv.tv_sec, tv.tv_usec); printf("Util:%d%%\n", utilInfo.averageCoreUtilization); usleep(100); } return 0; }
应该是先调用一个接口,然后再调用另一个接口。之间有个时间差,这段时间可能ipu运行,也可能没运行,这样两个接口获得的利用率就不太一样展开
#include
运行结果如下:
请登录后评论