zhangmeng
2019-05-31 6f0c11092b0a39265c6af723571906e4f834706d
gpu/info.cpp
@@ -301,7 +301,7 @@
                goto gpu_fail;
            }
            if(process_buf_size >= 0){
            if(process_buf_size > 0){
                infos->devices[i].running_processes = process_buf_size;
            }
    
@@ -369,7 +369,7 @@
    return suitable_gpu;
}
int getGPU(const int need){
int getIdleGPU(const int need){
    nvGpuInfo_t gpu_buf;
    int ret = get_gpu_info(&gpu_buf);
@@ -381,6 +381,60 @@
    return -1;
}
    // unsigned int decoder_utilization;
    // unsigned int encoder_utilization;
    // unsigned int gpu_utilization;
    // unsigned int memory_utilization;
    // unsigned int temperature;
    // unsigned int running_processes;
    // unsigned long long memory_total;
    // unsigned long long memory_free;
    // unsigned long long memory_used;
char *getGpuInfo(){
    nvGpuInfo_t gpu_info;
    int flag = get_gpu_info(&gpu_info);
    char * ret= NULL;
    if(!flag){
        char f[] = "gpu";
        char s[] = "|";
        ret = (char*)malloc(1024 * gpu_info.device_count);
        int len = 0;
        char tmp[1024];
        for(int i = 0; i < gpu_info.device_count; i++){
            memset(tmp, 0, 1024);
            nvGpuUnitInfo_t g = gpu_info.devices[i];
            sprintf(tmp, "%s%s%d%s%d%s%d%s%d%s%d%s%llu%s%llu%s%llu%s",
            f,s,
            g.gpu_utilization,s,
            g.temperature,s,
            g.decoder_utilization,s,
            g.encoder_utilization,s,
            g.running_processes,s,
            g.memory_total,s,
            g.memory_free,s,
            g.memory_used,s);
            int l = strlen(tmp);
            memcpy(ret+len, tmp, l);
            len += l;
        }
        ret[len] = '\0';
    }
    return ret;
}
int test(void)
{
    nvGpuInfo_t gpu_buf;