// A compiler par gcc -DSCHEDSTAT schedstat_load_balance.c

#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int
main(int argc, char *argv[], char *arge[])
{
  char buf[512];
  FILE *pp;
  int i=26,j;
  char *c;

#ifdef SCHEDSTAT
  c=malloc(512*sizeof(char));
  if(c==NULL){
    perror("Probleme avec malloc\n");
    exit(1);
  }
  // on lance un 'cat du fichier /proc/schedstat
  if ((pp = popen ("cat /proc/schedstat", "r")) == NULL)
    {
      perror ("popen error");
      exit (1);
    }
  // on recherche sur chacune des lignes l'element
  // on utilise strtok() qui permet de "parser" une ligne selon un motif, ici " ".
  while(fgets (buf, sizeof (buf), pp) != NULL) {
    i=26; // pour lire le bon champs
    buf[strlen (buf) - 1] = '\0';
    /* prendre la ieme colonne dans buf */
    c=strtok(buf," ");
    //printf("%s\n%s\n",buf,c);
    if (!strcmp(c,"domain0")) {
        printf("ligne qui m'interesse\n");
	for(j=0;j<i-1;j++)
	  c=strtok(NULL," ");
	printf("%s\n",c); //  # of times active_load_balance() was called!
	i++;
	c=strtok(NULL," ");
	printf("%s\n",c); //  # of times active_load_balance() tried to move a task and failed
	i++;
	c=strtok(NULL," ");
	printf("%s\n",c); //  # of times active_load_balance() successfully moved a task
	i++;
    }
  }
  pclose (pp);
#endif

  return 1;
}
