void message_callback_binary(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
{
  ReceiveStats* data_obj = reinterpret_cast<ReceiveStats*>(obj);

  uint64_t rx_nsec;
  get_timestamp(rx_nsec);

  std::lock_guard<std::mutex> guard(data_obj->mutex);
  
  uint64_t tx_nsec;
  get_payload_timestamp_binary(message->payload, message->payloadlen, &tx_nsec);

  add_to_stats(data_obj, rx_nsec, tx_nsec, message->topic, message->payloadlen);
  report_stats(data_obj, rx_nsec);
}
void message_callback_json(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
{
  std::string payload((char *)message->payload,message->payloadlen);
  std::cout << HERE() << STR(message->topic) << ' ' << STR(payload) << '\n';
  ReceiveStats* data_obj = reinterpret_cast<ReceiveStats*>(obj);

  uint64_t rx_nsec;
  get_timestamp(rx_nsec);

  std::lock_guard<std::mutex> guard(data_obj->mutex);
  
  uint64_t tx_nsec;
  get_payload_timestamp_json(message->payload, message->payloadlen, &tx_nsec);

  add_to_stats(data_obj, rx_nsec, tx_nsec, message->topic, message->payloadlen);
  report_stats(data_obj, rx_nsec);
}
Example #3
0
int tmstats(Options* inOptions)
/*
**  As quick as possible, load the input file and report stats.
*/
{
    int retval = 0;
    tmreader* tmr = NULL;
    TMStats stats;

    memset(&stats, 0, sizeof(stats));
    stats.mOptions = inOptions;
    stats.uMinTicks = 0xFFFFFFFFU;

    /*
    **  Need a tmreader.
    */
    tmr = tmreader_new(inOptions->mProgramName, &stats);
    if(NULL != tmr)
    {
        int tmResult = 0;

        tmResult = tmreader_eventloop(tmr, inOptions->mInputName, tmEventHandler);
        if(0 == tmResult)
        {
            retval = __LINE__;
            ERROR_REPORT(retval, inOptions->mInputName, "Problem reading trace-malloc data.");
        }

        tmreader_destroy(tmr);
        tmr = NULL;

        if(0 == retval)
        {
            retval = report_stats(inOptions, &stats);
        }
    }
    else
    {
        retval = __LINE__;
        ERROR_REPORT(retval, inOptions->mProgramName, "Unable to obtain tmreader.");
    }

    return retval;
}
Example #4
0
void matlib_main()
{
    MATRIX *A, *B, *C;
    MATRIX *At, *Bt;
    long n, ni, i;
    double sum;

    random_1(-1);

    n = query_long("dimension of arrays", 3L);
    ni = query_long("number of iterations", 100L);

#ifdef VAX_VMS
    init_stats();
#endif

    m_alloc(&A, n, n);
    m_alloc(&At, n, n);
    m_alloc(&B, n, n);
    m_alloc(&Bt, n, n);
    m_alloc(&C, n, n);
    for (i=sum=0; i<ni; i++) {

        m_rand(At, -1.0L, 1.0L);
        m_trans(A, At);

        m_invert(B, A);
        m_mult(C, A, B);

        sum += fabs(m_det(C)-1.0);

    }
    m_free(&A);
    m_free(&At);
    m_free(&B);
    m_free(&Bt);
    m_free(&C);

    printf("M.A.D.{DET{A.INV(A))}-1} = %e\n", sum/ni);

#ifdef VAX_VMS
    report_stats(stdout, "stats: ");
#endif
}
Example #5
0
static void perform(void)
{
   word last_report_day = 9;

   // Initialise database
   {
      db_init(conf[conf_db_server], conf[conf_db_user], conf[conf_db_password], conf[conf_db_name]);

      word e;
      if((e=database_upgrade(vstpdb)))
      {
         _log(CRITICAL, "Error %d in upgrade_database().  Aborting.", e);
         exit(1);
      }
   }

   {
      time_t now = time(NULL);
      struct tm * broken = localtime(&now);
      if(broken->tm_hour >= REPORT_HOUR)
      {
         last_report_day = broken->tm_wday;
      }
   }
   while(run)
   {   
      stats[ConnectAttempt]++;
      int run_receive = !open_stompy(STOMPY_PORT);
      while(run_receive && run)
      {
         holdoff = 0;
         {
            time_t now = time(NULL);
            struct tm * broken = localtime(&now);
            if(broken->tm_hour >= REPORT_HOUR && broken->tm_wday != last_report_day)
            {
               last_report_day = broken->tm_wday;
               report_stats();
            }
         }

         word r = read_stompy(body, FRAME_SIZE, 64);
         _log(DEBUG, "read_stompy() returned %d.", r);
         if(!r && run && run_receive)
         {
            if(db_start_transaction())
            {
               run_receive = false;
            }
            if(run_receive) process_frame(body);

            if(!db_errored)
            {
               if(db_commit_transaction())
               {
                  db_rollback_transaction();
                  run_receive = false;
               }
               else
               {
                  // Send ACK
                  if(ack_stompy())
                  {
                     _log(CRITICAL, "Failed to write message ack.  Error %d %s", errno, strerror(errno));
                     run_receive = false;
                  }
               }
            }
            else
            {
               // DB error occurred during processing of frame.
               db_rollback_transaction();
               run_receive = false;
            }
         }
         else if(run && run_receive)
         {
            if(r != 3)
            {
               run_receive = false;
               _log(CRITICAL, "Receive error %d on stompy connection.", r);
            }
            else
            {
               // Don't report these because it is normal on VSTP stream
               // _log(MINOR, "Receive timeout on stompy connection."); 
            }
         }
      } // while(run_receive && run)
      close_stompy();
      {      
         word i;
         if(holdoff < 256) holdoff += 38;
         else holdoff = 256;
         for(i = 0; i < holdoff + 64 && run; i++) sleep(1);
      }
   }  // while(run)

   if(interrupt)
   {
      _log(CRITICAL, "Terminating due to interrupt.");
   }

   db_disconnect();
   report_stats();
}
Example #6
0
/******************************************************
 * Main entry point into the VM
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, endian;
  char *opstat_path = 0;
  FILE *opstats = 0;

  VM *vm = malloc(sizeof(VM));

  endian = 0;

  strcpy(vm->filename, "retroImage");

  init_vm(vm);
  dev_init(INPUT);

  vm->shrink = 0;
  vm->trace = 0;
  vm->trace_stacks = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      vm->trace = -1;
    }
    else if (strcmp(argv[i], "--trace-stacks") == 0)
    {
      vm->trace_stacks = -1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = -1;
    }
    else if (strcmp(argv[i], "--with") == 0)
    {
      i++; dev_include(argv[i]);
    }
    else if (strcmp(argv[i], "--opstats") == 0)
    {
      i++; opstat_path = argv[i];
      init_stats(&opstats, opstat_path, call_stats_please);
    }
    else if (strcmp(argv[i], "--callstats") == 0)
    {
      call_stats_please = 1;
      if (opstat_path)
      {
        init_stats(&opstats, opstat_path, call_stats_please);
      }
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm->shrink = 1;
    }
    else if ((strcmp(argv[i], "--help") == 0) ||
             (strcmp(argv[i], "-help") == 0)  ||
             (strcmp(argv[i], "/help") == 0)  ||
             (strcmp(argv[i], "/?") == 0)     ||
             (strcmp(argv[i], "/h") == 0)     ||
             (strcmp(argv[i], "-h") == 0))
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --about          Display some information about Ngaro\n");
      fprintf(stderr, "   --trace          Trace instructions being executed\n");
      fprintf(stderr, "     --trace-stacks Also trace data and return stack contents\n");
      fprintf(stderr, "   --endian         Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink         Shrink the image to the current heap size when saving\n");
      fprintf(stderr, "   --with [file]    Treat [file] as an input source\n");
      fprintf(stderr, "   --opstats [file] Write statistics about VM operations to [file]\n");
      fprintf(stderr, "      --callstats      Include how many times each address is called (slow)\n");
      fprintf(stderr, "                       Also includes distribution of stack depths.\n");
      exit(0);
    }
    else if ((strcmp(argv[i], "--about") == 0) ||
             (strcmp(argv[i], "--version") == 0))
    {
      fprintf(stderr, "Retro Language  [VM: C, console]\n\n");
      exit(0);
    }
    else
    {
      strcpy(vm->filename, argv[i]);
    }
  }

  dev_init(OUTPUT);

  a = vm_load_image(vm, vm->filename);
  if (a == -1)
  {
    dev_cleanup();
    printf("Sorry, unable to find %s\n", vm->filename);
    exit(1);
  }

  /* Swap endian if --endian was passed */
  if (endian == -1)
    swapEndian(vm);

  /* Process the image */
  if (opstats == 0)
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
      vm_process(vm);
  }
  else
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
    {
      collect_stats(vm);
      vm_process(vm);
    }
    report_stats(opstats);
  }

  /* Once done, cleanup */
  dev_cleanup();
  return 0;
}
Example #7
0
int main(int argc, char *argv[])
{
	int choice = atoi(argv[1]);
	bool isPairEnd = false;

	if (choice) {
	
		char *kmerPath = argv[2];
		char *refPath = argv[3];

		char *taxonomyNodesPath = argv[4];
		char *giTaxidPath = argv[5];
		char *dirPath = argv[6];
		

		//vector<uint64_t> fKmer;
		_kmer = (uint8_t) atoi(argv[7]); 
		string  bwt_s;
		vector<uint32_t> nKmerTaxonID;	
		
		fprintf(stderr,"start preprocessing......\n");
		
	
		uint64_t hash_index_size = (uint64_t)1 <<((PREINDEXLEN<<1) + 1);
		
		uint64_t *hash_index = new uint64_t[hash_index_size]();

		preprocess(refPath, kmerPath, taxonomyNodesPath, giTaxidPath,  bwt_s, nKmerTaxonID, hash_index);

		fprintf(stderr,"writing index....\n");
		//char *dirPath = ".";
		//
		bwt bt(bwt_s.c_str(), bwt_s.length(),hash_index);

		bt.bwt_init();

		bt.write_info(dirPath, nKmerTaxonID);
		//uint64_t sp,ep;	
		//bt.exactMatch("GCTTCGCTGTTATTGGCACCAATTGGATCAC",31, sp,ep);
	} else {
	
		char *readPath;
	
		
		char *taxonomyNodesPath;
		
		char * dirPath;
		
		char *readPath_s;	
		
		
		fprintf(stderr,"%d", argc);	
		if (argc > 7 ) {
			isPairEnd = true;
		
			readPath = argv[2];
		
			readPath_s = argv[3];	
			
			taxonomyNodesPath = argv[4];
			
			dirPath = argv[5];
			_kmer = (uint8_t) atoi(argv[6]);
			
			_interval = atoi(argv[7]);
	
		} else {
		
			readPath = argv[2];
			
			taxonomyNodesPath = argv[3];
			
			
			dirPath = argv[4];
			
			_kmer = (uint8_t) atoi(argv[5]);
			
			_interval = atoi(argv[6]);
		
		}


		--_kmer;
		
		bwt bt(_kmer);
		
		fprintf(stderr,"loading index\n");

		bt.load_info(dirPath);
		
		taxonTree(taxonomyNodesPath);
		//map<uint32_t, uint32_t>::iterator it = taxonomyTree.begin();
		//while (it!=taxonomyTree.end()) {
		//	cout<<it->first<<"\t"<<it->second<<endl;

		//	++it;
		//}
		//cout<<taxonomyTree.size()<<endl;
		fprintf(stderr,"classifying...\n");
		
		gzFile fp;
		
		//uint32_t *nKmerTaxonID = bt.taxonIDTab;	
		
		fp = gzopen(readPath, "r");

		if (!fp) return FILE_OPEN_ERROR;

		kstream_t *_fp = ks_init(fp);

		kseq_t *seqs = (kseq_t *) calloc(N_NEEDED, sizeof(kseq_t));

		if (!seqs) return MEM_ALLOCATE_ERROR;
		//
		//parameters for pair-end reads
		gzFile fp_s;
		kstream_t *_fp_s;
		kseq_t *seqs_s;

		if (isPairEnd) {
		
			fp_s = gzopen(readPath_s, "r");

			if (!fp_s) return FILE_OPEN_ERROR;

			_fp_s  = ks_init(fp_s);

			seqs_s = (kseq_t *) calloc(N_NEEDED, sizeof(kseq_t));
			
			if (!seqs_s) return MEM_ALLOCATE_ERROR;
		
		
		}

		if (!seqs) return MEM_ALLOCATE_ERROR;
		
		cly_r *results = (cly_r *)calloc(2 * N_NEEDED, sizeof(cly_r));




  		struct timeval tv1, tv2;
		
		int n_seqs;
		total_sequences = 0;
		gettimeofday(&tv1,NULL);
		if (isPairEnd) {
		
			while ((n_seqs = read_reads(_fp, seqs, N_NEEDED) )> 0 && read_reads(_fp_s, seqs_s, N_NEEDED)) {
				
				classify_seq(seqs, n_seqs , bt, results, 0);
				classify_seq(seqs_s, n_seqs, bt, results, 1);
				output_results(results, n_seqs, isPairEnd);
				total_sequences += n_seqs;
			}	
		
		
		} else {
		
			while ((n_seqs = read_reads(_fp, seqs, N_NEEDED) )> 0) {
			
				classify_seq(seqs, n_seqs , bt, results, 0);
				output_results(results, n_seqs, isPairEnd);
				total_sequences += n_seqs;

			}	
		
		}	
		gettimeofday(&tv2,NULL);
		report_stats(tv1,tv2);

		//fprintf(stderr,"%f seconds\n",((float)t)/CLOCKS_PER_SEC);
		if (results) free(results);
		if (seqs) free(seqs);

	}
	
	//char *st;
	
	//uint32_t *uts;

	//uint64_t z;
	//load_index(dirPath, st, uts, &z );		
	//cerr<<<<endl;
	//fprintf(stderr,"%s\n",st);
	
	//uint64_t sp, ep;

	//bwt b(st, uts, z);
	
	//b.bwt_init();
	//char *read = "GGCT";
	//cout<<b.exactMatch(read,4,sp,ep )<<endl;
	//cout<<sp<<"\t"<<ep<<endl;	
	//read reads file
	//output(kmerValue, kmerInfo, _2kmers);
	

	return NORMAL_EXIT;

}
Example #8
0
static void perform(void)
{
   int rc;
   time_t last_report;

   last_report = time(NULL) / REPORT_INTERVAL;

   // Initialise database
   db_init(conf.db_server, conf.db_user, conf.db_pass, conf.db_name);

   log_message("");
   log_message("");
   log_message("trustdb started.");

   create_database();

   while(run)
   {   
      stats[ConnectAttempt]++;
      _log(GENERAL, "Connecting socket ...");
      rc=stomp_connect("datafeeds.networkrail.co.uk", 61618);
      if(rc)
      {
         sprintf(zs,"Failed to connect.  Error %d %s", rc, report_error(rc));
         _log(CRITICAL, zs);
      }
      else
      {
         _log(GENERAL, "Connected.");
         holdoff = 0;
         {
            strcpy(headers, "CONNECT\n");
            strcat(headers, "login:"******"\npasscode:");
            strcat(headers, conf.nr_pass);
            strcat(headers, "\n");          
            if(debug)
            {
               sprintf(zs, "client-id:%s-trustdb-debug\n", conf.nr_user);
               strcat(headers, zs);
            }
            else
            {
               sprintf(zs, "client-id:%s-trustdb-%s\n", conf.nr_user, abbreviated_host_id());
               strcat(headers, zs);
            }          
            strcat(headers, "heart-beat:0,20000\n");          
            strcat(headers, "\n");
     
            rc = stomp_tx(headers);
         }
         if(rc)
         {
            sprintf(zs,"Failed to transmit CONNECT message.  Error %d %s", rc, report_error(rc));
            _log(CRITICAL, zs);
         }
         else
         {
            _log(GENERAL, "Sent CONNECT message.  Reading response.");
            rc = stomp_rx(headers, sizeof(headers), body, sizeof(body));
            if(rc)
            {
               sprintf(zs,"Failed to receive.  Error %d %s", rc, report_error(rc));
               _log(CRITICAL, zs);
            }
            else
            {
               sprintf(zs, "Response: Body=\"%s\", Headers:", body);
               _log(GENERAL, zs);
               dump_headers();
               {
                  strcpy(headers, "SUBSCRIBE\n");

                  // Headers
                  strcat(headers, "destination:/topic/TRAIN_MVT_ALL_TOC\n");      
                  if(debug)
                  {
                     sprintf(zs, "activemq.subscriptionName:%s-trustdb-debug\n", conf.nr_user);
                     strcat(headers, zs);
                  }
                  else
                  {
                     sprintf(zs, "activemq.subscriptionName:%s-trustdb-%s\n", conf.nr_user, abbreviated_host_id());
                     strcat(headers, zs);
                  }
                  strcat(headers, "id:1\n");      
                  strcat(headers, "ack:client\n");   
                  strcat(headers, "\n");

                  rc = stomp_tx(headers);
               }
               if(rc)
               {
                  sprintf(zs,"Failed to transmit SUBSCRIBE message.  Error %d %s", rc, report_error(rc));
                  _log(CRITICAL, zs);
               }
               else
               {
                  _log(GENERAL, "Sent SUBSCRIBE message.  Waiting for messages ...");

                  int run_receive = 1;
                  while(run && run_receive)
                  {
                     time_t waited = time(NULL);
                     if( waited / REPORT_INTERVAL != last_report)
                     {
                        report_stats();
                        last_report = waited / REPORT_INTERVAL;
                     }
                     rc = stomp_rx(headers, sizeof(headers), body, sizeof(body));
                     run_receive = (rc == 0);
                     if(rc && run)
                     {
                        // Don't report if the error is due to an interrupt
                        sprintf(zs, "Error receiving frame: %d %s", rc, report_error(rc));
                        _log(MAJOR, zs);
                     }
                     
                     if(run_receive)
                     {
                        time_t now = time(NULL);
                        waited = now - waited;
                        if(waited > 1) 
                        {
                           last_idle = now;
                           if(high_load) _log(MINOR, "Ceasing task shedding.");
                           high_load = false;
                        }
                        else
                        {
                           if(!high_load && now - last_idle > 64)
                           {
                              // Enter high load
                              high_load = true;
                              _log(MINOR, "High load detected.  Shedding tasks.");
                           }
                        }
                              
                        if(debug || waited < 2)
                        {
                           sprintf(zs, "Message receive wait time was %ld seconds.", waited);
                           _log(MINOR, zs);
                        }
                        char message_id[256];
                        message_id[0] = '\0';

                        stats[Bytes] += strlen(headers);
                        stats[Bytes] += strlen(body);

                        if(!strstr(headers, "MESSAGE"))
                        {
                           _log(MAJOR, "Frame received is not a MESSAGE:");
                           dump_headers();
                           run_receive = false;
                           stats[NotMessage]++;
                        }
                     
                        // Find message ID
                        char * message_id_header = strstr(headers, "message-id:");
                        if(run_receive)
                        {
                           if(message_id_header)
                           {
                              size_t i = 0;
                              message_id_header += 11;
                              while(*message_id_header != '\n') message_id[i++] = *message_id_header++;
                              message_id[i++] = '\0';
                           }
                           else
                           {
                              _log(MAJOR, "No message ID found:");
                              dump_headers();
                           }
                        }

                        //sprintf(zs, "Message id = \"%s\"", message_id);
                        //_log(GENERAL, zs);
                        
                        // Process the message
                        if(run_receive) process_message(body);

                        // Send ACK
                        if(run_receive && message_id[0])
                        {
                           strcpy(headers, "ACK\n");
                           strcat(headers, "subscription:1\n");
                           strcat(headers, "message-id:");
                           strcat(headers, message_id);
                           strcat(headers, "\n\n");
                           rc = stomp_tx(headers);
                           if(rc)
                           {
                              sprintf(zs,"Failed to transmit ACK message.  Error %d %s", rc, report_error(rc));
                              _log(CRITICAL, zs);
                              run_receive = false;
                           }
                           else
                           {
                              //_log(GENERAL, "Ack sent OK.");
                           }
                           //sprintf(zs, "%d messages, total size %ld bytes.", count, size);
                           //_log(GENERAL, zs);
                        }
                     }
                  } // while(run && run_receive)
               }
            }
         }
      }
      strcpy(headers, "DISCONNECT\n\n");
      rc = stomp_tx(headers);
      if(rc)
      {
         sprintf(zs, "Failed to send DISCONNECT:  Error %d %s", rc, report_error(rc));
         _log(GENERAL, zs);
      }
      else _log(GENERAL, "Sent DISCONNECT.");
      
      _log(GENERAL, "Disconnecting socket ...");
      rc = stomp_disconnect(); 
      if(rc)
      {
         sprintf(zs, "Failed to disconnect:  Error %d %s", rc, report_error(rc));
         _log(GENERAL, zs);
      }
      else _log(GENERAL, "Disconnected.");

      {      
         word i;
         if(holdoff < 128) holdoff += 16;
         else holdoff = 128;
         for(i = 0; i < holdoff && run; i++) sleep(1);
      }
   }  // while(run)

   db_disconnect();

   if(interrupt)
   {
      _log(CRITICAL, "Terminating due to interrupt.");
   }
   report_stats();
}
/**
 * The Main function
 */
int main (int argc, char ** argv) {
    apex::init("openmp test", 0, 1);
    parse_arguments(argc, argv);

#ifdef APEX_HAVE_ACTIVEHARMONY
    int num_inputs = 2; // 2 for threads, block size; 3 for threads, block size, method
    long * inputs[3] = {0L,0L,0L};
    long mins[3] = {1,1,DIVIDE_METHOD};    // all minimums are 1
    long maxs[3] = {0,0,0};    // we'll set these later
    long steps[3] = {1,1,1};   // all step sizes are 1
    inputs[0] = &active_threads;
    inputs[1] = &block_size;
    inputs[2] = &method;
    maxs[0] = active_threads;
    maxs[1] = num_cells/omp_get_max_threads();
    maxs[2] = MULTIPLY_METHOD;
    std::cout <<"Tuning Parameters:" << std::endl;
    std::cout <<"\tmins[0]: " << mins[0] << ", maxs[0]: " << maxs[0] << ", steps[0]: " << steps[0] << std::endl;
    my_custom_event = apex::register_custom_event("Perform Re-block");
    apex::setup_throughput_tuning((apex_function_address)solve_iteration,
                    APEX_MINIMIZE_ACCUMULATED, my_custom_event, num_inputs,
                    inputs, mins, maxs, steps);
    long original_block_size = block_size;
    long original_active_threads = active_threads;
#else
    std::cerr << "Active Harmony not enabled" << std::endl;
#endif
    std::cout <<"Running 1D stencil test..." << std::endl;

    std::vector<double> * prev = initialize(false);
    std::vector<double> * next = initialize(true);
    std::vector<double> * tmp = prev;
    double prev_accumulated = 0.0;
    for (int i = 0 ; i < num_iterations ; i++) {
        solve_iteration(prev, next);
        //dump_array(next);
        tmp = prev;
        prev = next;
        next = tmp;
        if (i % update_interval == 0 && i > 0) {
            apex_profile * p = apex::get_profile((apex_function_address)solve_iteration);
            if (p != nullptr) {
                double next_accumulated = p->accumulated - prev_accumulated;
                prev_accumulated = p->accumulated;
                std::cout << "Iteration: " << i << " accumulated: " << next_accumulated << std::endl;
            }
            apex::custom_event(my_custom_event, NULL);
            std::cout << "New thread count: " << active_threads;
            std::cout << ", New block size: " << block_size;
            std::cout << ", New method: " << method_names[method-1] << std::endl;
        }
    }
    //dump_array(tmp);
    report_stats();
    delete(prev);
    delete(next);
    std::cout << "done." << std::endl;
#ifdef APEX_HAVE_ACTIVEHARMONY
    if (original_active_threads != active_threads || original_block_size != block_size) {
        std::cout << "Test passed." << std::endl;
    }
#else
    std::cout << "Test passed (but APEX was built without Active Harmony.)." << std::endl;
#endif
    apex::finalize();
}
Example #10
0
static void perform(void)
{
   word last_report_day = 9;
   word stompy_timeout = true;

   // Initialise database connection
   while(db_init(conf[conf_db_server], conf[conf_db_user], conf[conf_db_password], conf[conf_db_name]) && run) 
   {
      _log(CRITICAL, "Failed to initialise database connection.  Will retry...");
      word i;
      for(i = 0; i < 64 && run; i++) sleep(1);
   }

   create_database();

   handle = 0xfff0;

   {
      time_t now = time(NULL);
      struct tm * broken = localtime(&now);
      if(broken->tm_hour >= REPORT_HOUR)
      {
         last_report_day = broken->tm_wday;
      }
      last_message_count_report = now;
      message_count = message_count_rel = 0;
   }

   // Status
   status_last_td_processed = 0;
   {
      word describer;
      for(describer = 0; describer < DESCRIBERS; describer++)
      {
         status_last_td_actual[describer] = last_td_processed[describer] = 0;
         timeout_reported[describer] = false;
      }
   }

   // Signalling
   {
      word i,j;
      for(i = 0; i < DESCRIBERS; i++)
      {
         for(j = 0; j < SIG_BYTES; j++)
         {
            signalling[i][j] = 0xffff;
         }
      }
   }

   while(run)
   {   
      stats[ConnectAttempt]++;
      int run_receive = !open_stompy(STOMPY_PORT);
      while(run_receive && run)
      {
         holdoff = 0;
         {
            time_t now = time(NULL);
            struct tm * broken = localtime(&now);
            if(broken->tm_hour >= REPORT_HOUR && broken->tm_wday != last_report_day)
            {
               last_report_day = broken->tm_wday;
               report_stats();
            }
            if(now - last_message_count_report > MESSAGE_COUNT_REPORT_INTERVAL)
            {
               char query[256];
               sprintf(query, "INSERT INTO message_count VALUES('tddb', %ld, %d)", now, message_count);
               if(!db_query(query))
               {
                  message_count = 0;
                  last_message_count_report = now;
               }
               sprintf(query, "INSERT INTO message_count VALUES('tddbrel', %ld, %d)", now, message_count_rel);
               if(!db_query(query))
               {
                  message_count_rel = 0;
               }
            }
         }

         int r = read_stompy(body, FRAME_SIZE, 64);
         _log(DEBUG, "read_stompy() returned %d.", r);
         if(!r && run && run_receive)
         {
            if(stompy_timeout)
            {
               _log(MINOR, "TD message stream - Receive OK.");
               stompy_timeout = false;
            }
            if(db_start_transaction())
            {
               run_receive = false;
            }
            if(run_receive) process_frame(body);

            if(!db_errored)
            {
               if(db_commit_transaction())
               {
                  db_rollback_transaction();
                  run_receive = false;
               }
               else
               {
                  // Send ACK
                  if(ack_stompy())
                  {
                     _log(CRITICAL, "Failed to write message ack.  Error %d %s", errno, strerror(errno));
                     run_receive = false;
                  }
               }
            }
            else
            {
               // DB error.
               db_rollback_transaction();
               run_receive = false;
            }
         }
         else if(run && run_receive)
         {
            if(r != 3)
            {
               run_receive = false;
               _log(CRITICAL, "Receive error %d on stompy connection.", r);
            }
            else
            {
               if(!stompy_timeout) _log(MINOR, "TD message stream - Receive timeout."); 
               stompy_timeout = true;
            }
         }
         if(run) check_timeout();
      } // while(run_receive && run)

      close_stompy();
      if(run) check_timeout();
      {      
         word i;
         if(holdoff < 256) holdoff += 34;
         else holdoff = 256;
         for(i = 0; i < holdoff + 64 && run; i++) sleep(1);
      }
   }    
   if(interrupt)
   {
      _log(CRITICAL, "Terminating due to interrupt.");
   }

   db_disconnect();
   report_stats();
}
Example #11
0
/******************************************************************************

  main()
  
******************************************************************************/
int main(int argc, char **argv)
{
  int is_ignore_list = 0;
  // setup
  setup(argv[0]);
  
  /* The --ignore option is comma saperated list of test cases to skip and
     should be very first command line option to the test suite. 

     The usage is now:
     mysql_test_run --ignore=test1,test2 test3 test4
     where test1 and test2 are test cases to ignore
     and test3 and test4 are test cases to run.
  */
  if (argc >= 2 && !strnicmp(argv[1], "--ignore=", sizeof("--ignore=")-1))
  {
    char *temp, *token;
    temp= strdup(strchr(argv[1],'=') + 1);
    for (token=str_tok(temp, ","); token != NULL; token=str_tok(NULL, ","))
    {
      if (strlen(ignore_test) + strlen(token) + 2 <= PATH_MAX-1)
        sprintf(ignore_test+strlen(ignore_test), " %s ", token);
      else
      {
        free(temp);
        die("ignore list too long.");
      }
    }
    free(temp);
    is_ignore_list = 1;
  }
  // header
  log_msg("MySQL Server %s, for %s (%s)\n\n", VERSION, SYSTEM_TYPE, MACHINE_TYPE);
  
  log_msg("Initializing Tests...\n");
  
  // install test databases
  mysql_install_db();
  
  log_msg("Starting Tests...\n");
  
  log_msg("\n");
  log_msg(HEADER);
  log_msg(DASH);

  if ( argc > 1 + is_ignore_list )
  {
    int i;

    // single test
    single_test = TRUE;

    for (i = 1 + is_ignore_list; i < argc; i++)
    {
      // run given test
      run_test(argv[i]);
    }
  }
  else
  {
    // run all tests
    DIR *dir = opendir(test_dir);
    DIR *entry;
    char test[NAME_MAX];
    char *p;
    
    // single test
    single_test = FALSE;    

    if (dir == NULL)
    {
      die("Unable to open tests directory.");
    }
    
    while((entry = readdir(dir)) != NULL)
    {
      if (!S_ISDIR(entry->d_type))
      {
        strcpy(test, strlwr(entry->d_name));
        
        // find the test suffix
        if ((p = strindex(test, TEST_SUFFIX)) != NULL)
        {
          // null terminate at the suffix
          *p = '\0';

          // run test
          run_test(test);
        }
      }
    }
    
    closedir(dir);
  }

  // stop server
  mysql_stop();

  log_msg(DASH);
  log_msg("\n");

  log_msg("Ending Tests...\n");

  // report stats
  report_stats();

  // close log
  if (log_fd) fclose(log_fd);

  // keep results up
  pressanykey();

  return 0;
}