add tests, initial protobuf and rabbitmq support, ...
This commit is contained in:
parent
54adfcee2a
commit
7510c2a7b3
13 changed files with 421 additions and 39 deletions
43
resource_handler/resource_handler.c
Normal file
43
resource_handler/resource_handler.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "resource_handler/resource_handler.h"
|
||||
|
||||
int extract_numbers(char* str, int* res) {
|
||||
bool is_digit=false,last_digit=false;
|
||||
int cur=0;
|
||||
int begin=-1;
|
||||
int* old_res=res;
|
||||
bool go=true;
|
||||
while(go) {
|
||||
go=(*str)!=0;
|
||||
is_digit = *str <= '9' && *str >= '0';
|
||||
if(is_digit) {
|
||||
cur *= 10;
|
||||
cur += *str - '0';
|
||||
}
|
||||
else if(last_digit) {
|
||||
if(*str == '-') {
|
||||
begin = cur;
|
||||
} else if(begin != -1) {
|
||||
for(int core = begin; core <= cur; core++) {
|
||||
*res = core;
|
||||
res++;
|
||||
}
|
||||
begin = -1;
|
||||
} else {
|
||||
*res = cur;
|
||||
res++;
|
||||
begin = -1;
|
||||
}
|
||||
cur = 0;
|
||||
}
|
||||
str++;
|
||||
last_digit = is_digit;
|
||||
}
|
||||
return res - old_res;
|
||||
}
|
||||
|
||||
int get_isolated_cores(int** res) {
|
||||
char buf[MAX_OPTION];
|
||||
read(open("/sys/devices/system/cpu/isolated", O_RDONLY),buf,MAX_OPTION);
|
||||
*res=malloc(sizeof(int)*MAX_CORES);
|
||||
return extract_numbers(buf,*res);
|
||||
}
|
10
resource_handler/resource_handler.h
Normal file
10
resource_handler/resource_handler.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#define MAX_CORES 128
|
||||
#define MAX_OPTION 4096
|
||||
|
||||
int extract_numbers(char* str, int* res);
|
||||
int get_isolated_cores(int** res);
|
Loading…
Add table
Add a link
Reference in a new issue