Skip to content
Snippets Groups Projects
Commit 46f7e35f authored by Georges Da Costa's avatar Georges Da Costa
Browse files

Changes the load sensor to use pread

parent 00471708
No related branches found
No related tags found
No related merge requests found
......@@ -17,16 +17,21 @@
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#define LOAD_BUFFER_SIZE 1024
char buffer[LOAD_BUFFER_SIZE];
static int load_fid=-1;
void init_load() {
load_fid = open("/proc/stat", O_RDONLY);
}
void get_load(long long* results) {
FILE* f = fopen("/proc/stat", "rb");
fgets(buffer, LOAD_BUFFER_SIZE, f);
fclose(f);
pread(load_fid, buffer, LOAD_BUFFER_SIZE-1, 0);
int pos=0;
while(buffer[pos] > '9' || buffer[pos] < '0') pos++;
for(int i=0; i<10; i++) {
......@@ -35,3 +40,8 @@ void get_load(long long* results) {
pos++;
}
}
void clean_load() {
close(load_fid);
}
......@@ -18,4 +18,6 @@
*******************************************************/
void init_load();
void get_load(long long* results);
void clean_load();
......@@ -207,8 +207,10 @@ int main(int argc, char **argv) {
// Load initialization
long long load_values[10]={0,0,0,0,0,0,0,0,0,0};
long long tmp_load_values[10]={0,0,0,0,0,0,0,0,0,0};
if(load_mode == 0)
if(load_mode == 0) {
init_load();
get_load(load_values);
}
// RAPL initialization
_rapl_t* rapl=NULL;
......@@ -353,6 +355,8 @@ int main(int argc, char **argv) {
free(rapl_values);
free(tmp_rapl_values);
}
if(load_mode == 0)
clean_load();
if(dev!=NULL)
clean_network(network_sources);
if(infi_path!=NULL)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment