Example #1
0
void
stats_swap(struct stats *st)
{
    if (!stats_enabled) {
        return;
    }

    if (st->aggregate == 1) {
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as aggregator "
                  "is busy", st->current.elem, st->shadow.elem);
        return;
    }

    if (st->updated == 0) {
        log_debug(LOG_PVERB, "skip swap of current %p shadow %p as there is "
                  "nothing new", st->current.elem, st->shadow.elem);
        return;
    }

    log_debug(LOG_PVERB, "swap stats current %p shadow %p", st->current.elem,
              st->shadow.elem);


    //set the latencies
    histo_compute(&st->latency_histo);

    histo_compute(&st->payload_size_histo);

    st->alloc_msgs = msg_alloc_msgs();

    array_swap(&st->current, &st->shadow);

    /*
     * Reset current (a) stats before giving it back to generator to keep
     * stats addition idempotent
     */
    stats_pool_reset(&st->current);
    st->updated = 0;

    st->aggregate = 1;

}
Example #2
0
int main(int argc, char *argv[]) {
  module_t *module;
  void *result; // future : use for rmf,dumb,histo : 
                // it is an array of everything
  int type;     // float,int,double... for result[]
  int size_result;

  int steg = 0;
  int plot = 0;
  int size, feature;
  char filename[MAXLEN_FILENAME];
  char svmfilename[MAXLEN_FILENAME];
  int outfile;
  char algoname[MAXLEN_ALGONAME];
  filename[0] = 0;
  svmfilename[0] = 0;  
  int opt;
  int option_index = 0;

  FILE *svmfile = NULL;
    


  // set default module option

  strcpy(algoname,"dumb");


  for(;;) {
    opt = getopt_long (argc, argv, "012345",
		       long_options, &option_index);

    if(opt==-1) break;
    switch (opt) {
    case 0: // --module=modulename
      //printf ("option %s", long_options[option_index].name);
      if (optarg) {
	if(strlen(optarg)<MAXLEN_ALGONAME) {
	strcpy(algoname,optarg);
	}
      }
      else {
	printf("Error : module name too long\n");
	exit(0);
      }
      break;
    case 1: // --file=filename
      if (optarg) {
	if(strlen(optarg)<MAXLEN_FILENAME) {
	  strcpy(filename,optarg);
	}
	else {
	  printf("Error : filename too long\n");
	  exit(0);
	}
      }
      break;
      
    case 2: // --svm=filename
      if (optarg) {
	if(strlen(optarg)<MAXLEN_FILENAME) {
	  strcpy(svmfilename,optarg);
	}
	else {
	  printf("Error : svm filename too long\n");
	  exit(0);
	}
      }
      break;

    case 3: // --steg
      steg = 1;
      //if (optarg) {
	//steg = atoi(optarg);
      //}
      break;

    case 4: // --plot
      plot = 1;
      break;

    case 5: // --help
      printhelp(argv[0]);
      break;
    }
  }

  if(filename[0]==0) {
    printf("please give a file name.\n");
    printhelp(argv[0]);
    exit(1);
  }


  // extract DCT's
  size = extract_dct(filename);
  //printf("*** Number of DCTs: %d ***\n", size);

  /*********************** dumb **************************/
  if(!strcmp(algoname,"dumb")) {
    dumb_hello_module();

    // initializes module
    dumb_init();
    
    // compute sum (dumb feature) for each DCT
    int x,y,z;
    dumb_reset(size);
    for (z=0; z<size; z++) {
      dumb_compute(dct[z]);
    }

    // get features (average of sum in this case)
    feature = dumb_get_features();
    printf("Average of sum of DCTs = %d\n", feature);

    // free allocations
    dumb_release();
  }

  /*********************** histo **************************/
  if(!strcmp(algoname,"histo")) {
    int *tab; // used for result

    printf("applying ");
    histo_hello_module();

    // initializes module
    histo_init();
    
    // compute histogram for each DCT
    int x,y,z;
    histo_reset(size);
    for (z=0; z<size; z++) {
      histo_compute(dct[z]);
    }

    // get features (histogram)
    size_result = histo_get_count();
    int *numbers;
    numbers = malloc(size_result*sizeof(int));
    result = (void *) malloc(size_result*sizeof(int));
    tab = (int *) result;
    histo_get_features(numbers, tab, plot);

    // free allocations
    histo_release();
  }

  /*********************** rmf **************************/
  else if(!strcmp(algoname,"rmf")) {
    int i;
    param_t param;
    float *tab; // used for rmf = result

    printf("applying ");
    rmf_hello_module();
    param.nb_dct = size;

    // initializes module
    rmf_init();
    
    int x,y,z;

    module = rmf_get_module();
    result = (void *) malloc(sizeof(float) * module->features);
    tab = (float *) result;
    rmf_reset(&param);
    for (z=0; z<size; z++) {
      //printf("%d ",z);fflush(stdout);
      rmf_compute((int *) dct[z]);
      if(z % (size/100) == 1) {
      	printf("%d%% ", (1 + z *100 / size));fflush(stdout);
      }
    }
    printf("\n");

    rmf_get_features(tab);
    size_result = module->features;
    // free allocations
    rmf_release();
  }


  /*********************** SVM **************************/
  if(svmfilename[0]!=0) {
    int i;
    svmfile = fopen(svmfilename,"a");
    if(svmfile != NULL) {
      fprintf(svmfile, "%f ",(float) steg);
      
      if(!strcmp(algoname,"histo")) {
	int *tab = result;
	for(i=0;i<size_result;i++) {
	  fprintf(svmfile, "%d:%d ",i+1, tab[i]);
	}
        free(result);
      }
      if(!strcmp(algoname,"rmf")) {
	float *tab = result;
	for(i=0;i<size_result;i++) {
	  fprintf(svmfile, "%d:%f ",i+1, tab[i]);
	}
        free(result);
      }
      fprintf(svmfile, "\n");
      fclose(svmfile);
    }
    else {
      printf("Cannot open file %s \n", svmfilename);
    }
  }
  

  return 0;

}