Exemplo n.º 1
0
int main(int argc, char* argv[]) {
    wp_index* index;

    if(argc < 2) {
        fprintf(stderr, "Usage: %s <filename>+\n", argv[0]);
        return -1;
    }

    DIE_IF_ERROR(wp_index_create(&index, "index"));
    //wp_index_dumpinfo(index, stdout);

    printf("starting...\n");
    unsigned long total_bytes = 0;
    unsigned long chunk_bytes = 0;
    START_TIMER(total);
    START_TIMER(chunk);

    for(int i = 1; i < argc; i++) {
        FILE* f = fopen(argv[i], "r");
        if(f == NULL) {
            fprintf(stderr, "can't open %s: %s\n", argv[i], strerror(errno));
            break;
        }

        uint64_t doc_id;
        wp_entry* entry = wp_entry_new();
        DIE_IF_ERROR(wp_entry_add_file(entry, "body", f));
        DIE_IF_ERROR(wp_index_add_entry(index, entry, &doc_id));
        DIE_IF_ERROR(wp_entry_free(entry));
        fclose(f);

        struct stat fstat;
        stat(argv[i], &fstat);
        total_bytes += fstat.st_size;
        chunk_bytes += fstat.st_size;

        MARK_TIMER(chunk);
        if(TIMER_MS(chunk) > 1000) {
            MARK_TIMER(total);
#define STUFF(k, t) k / 1024, t / 1000.0, ((float)(k) / 1024.0) / ((float)(t) / 1000.0)
            fprintf(stderr, "processed %5luk in %3.1fs = %6.1fk/s. total: %5luk in %5.1fs = %6.1fk/s\n", STUFF(chunk_bytes, TIMER_MS(chunk)), STUFF(total_bytes, TIMER_MS(total)));
            RESET_TIMER(chunk);
            chunk_bytes = 0;
        }
    }
    //po = MMAP_OBJ(segment.postings, postings_list); // may have moved
    //fprintf(stderr, "after: segment has %d docs and %d postings\n", po->num_docs, po->num_postings);

    MARK_TIMER(total);
    fprintf(stderr, "In total, processed %luk in %.1fs = %.1fk/s\n", STUFF(total_bytes, TIMER_MS(total)));

    DIE_IF_ERROR(wp_index_unload(index));
    return 0;
}
Exemplo n.º 2
0
static void envia(void){
  //Coprovar 3 cops si pot enviar.
  if (intens < MAX_TRY){
    if(lan_can_put()){
      // Si el canal no esat ocupat enviem
      ether_block_put(tx);
      for(uint8_t i=0; i<64;i++) tx[i]='\0';
    }
    else{
      // Si el canal esta ocupat sumem 1 als intents
      intens++;
      // Esperem un temps aleatori i tornem a provar.
      timer_after(TIMER_MS(rand()%((10+1)*1000)),envia);
    }
  }
  // En el cas de que no s'hagi pogut enviar encenem el LED
  else pin_w(pin,true);
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {
  if(argc < 2) {
    fprintf(stderr, "Usage: %s <filename>+\n", argv[0]);
    return -1;
  }

  fprintf(stderr, "starting...\n");

  new_query = 1;

  unsigned long total_bytes = 0;
  unsigned long chunk_bytes = 0;
  START_TIMER(total);
  START_TIMER(chunk);

  for(int i = 1; i < argc; i++) {
    FILE* f = fopen(argv[i], "r");
    if(f == NULL) {
      fprintf(stderr, "can't open %s: %s\n", argv[i], strerror(errno));
      break;
    }
    parse_file(f);
    fclose(f);

    struct stat fstat;
    stat(argv[i], &fstat);
    total_bytes += fstat.st_size;
    chunk_bytes += fstat.st_size;

    MARK_TIMER(chunk);
    if(TIMER_MS(chunk) > 1000) {
      MARK_TIMER(total);
#define STUFF(k, t) k / 1024, t / 1000.0, ((float)(k) / 1024.0) / ((float)(t) / 1000.0)
      fprintf(stderr, "processed %5luk in %3.1fs = %6.1fk/s. total: %5luk in %5.1fs = %6.1fk/s\n", STUFF(chunk_bytes, TIMER_MS(chunk)), STUFF(total_bytes, TIMER_MS(total)));
      RESET_TIMER(chunk);
      chunk_bytes = 0;
    }
  }

  MARK_TIMER(total);
  fprintf(stderr, "In total, processed %luk in %.1fs = %.1fk/s\n", STUFF(total_bytes, TIMER_MS(total)));

  return 0;
}
Exemplo n.º 4
0
void control_init(void){
  /*Inicialitza el mòdul de control. ës imprescindible cridar la funció
    abans d'usar el mòdul. Una vegada inicialitzat deixa els semàfors
    apagats i cal engegar-los explícitament.*/
  
  /*Inicialitza el timer y activa les interrupcions.*/
  //Inicialitza els Semafors A i B, amb els seus ports corresponents.
  semaph_init(&(SemA.state), &PORTD, 5, &PORTD, 6, &PORTD, 7);    
  semaph_init(&(SemB.state), &PORTD, 4, &PORTC, 3, &PORTC, 2);
  //Posa a l'estat d'apagat els semafors.
  semaph_set(&(SemA.state),SemOff);                             
  semaph_set(&(SemB.state),SemOff);
  //Indiquem a la variable global que estemx a l'estat d'off.
  (control).estat = Off;
  timer_init();
  i=timer_every(TIMER_MS(100),control_change);
  //Activem interrupcions
  sei();
}
Exemplo n.º 5
0
void netifc_set_timer(uint32_t ms) {
    if (net_timer == 0) {
        return;
    }
    gBS->SetTimer(net_timer, TimerRelative, TIMER_MS(ms));
}