示例#1
0
int main(int argc, char** argv) {
  int time;
  int n;
  int i;
  for (i = 1; i < argc; i++) {
    char* val = strchr(argv[i], '=');
    if (val == NULL) {
      continue;
    }
    val++;
    if (strncmp("n", argv[i], 1) == 0) {
      n = atoi(val);
    } else if(strncmp("time", argv[i], 4) == 0) {
      time = atoi(val);
    }
  }
  unsigned int sleep = time * 1000;
  printf("actual sleep (ms)\n");
  long long then = current_timestamp();
  long long now;
  for (i = 0; i < n; i++) {
    usleep(sleep);
    now = current_timestamp();
    printf("%lld\n", now-then);
    then = now;
  }
}
示例#2
0
/* Measure the performance of a signing primitive when verifying messages */
static void perf_sign_verify(int id)
{
    char name[64];
    NoiseSignState *sign;
    uint8_t private_key[56];
    uint8_t message[32];
    uint8_t sig[56 * 2];
    size_t key_len;
    size_t sig_len;
    timestamp_t start, end;
    int count;
    double elapsed;

    if (noise_signstate_new_by_id(&sign, id) != NOISE_ERROR_NONE)
        return;
    key_len = noise_signstate_get_private_key_length(sign);
    sig_len = noise_signstate_get_signature_length(sign);
    memset(private_key, 0xAA, sizeof(private_key));
    noise_signstate_set_keypair_private(sign, private_key, key_len);
    memset(message, 0x66, sizeof(message));
    noise_signstate_sign(sign, message, sizeof(message), sig, sig_len);

    start = current_timestamp();
    for (count = 0; count < DH_COUNT; ++count)
        noise_signstate_verify(sign, message, sizeof(message), sig, sig_len);
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)DH_COUNT;
    snprintf(name, sizeof(name), "%s verify",
             noise_id_to_name(NOISE_SIGN_CATEGORY, id));
    printf("%-20s%8.2f          %8.2f\n", name, 1.0 / elapsed, units / elapsed);

    noise_signstate_free(sign);
}
示例#3
0
/* Measure the performance of a DH primitive when deriving keys */
static void perf_dh_derive(int id)
{
    char name[64];
    NoiseDHState *dh;
    uint8_t private_key[56];
    size_t key_len;
    timestamp_t start, end;
    int count;
    double elapsed;

    if (noise_dhstate_new_by_id(&dh, id) != NOISE_ERROR_NONE)
        return;
    key_len = noise_dhstate_get_private_key_length(dh);

    memset(private_key, 0xAA, sizeof(private_key));
    start = current_timestamp();
    for (count = 0; count < DH_COUNT; ++count)
        noise_dhstate_set_keypair_private(dh, private_key, key_len);
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)DH_COUNT;
    snprintf(name, sizeof(name), "%s derive key",
             noise_id_to_name(NOISE_DH_CATEGORY, id));
    printf("%-20s%8.2f          %8.2f\n", name, 1.0 / elapsed, units / elapsed);

    noise_dhstate_free(dh);
}
示例#4
0
/* Measure the performance of a hashing primitive */
static void perf_hash(int id)
{
    NoiseHashState *hash;
    uint8_t data[BLOCK_SIZE];
    timestamp_t start, end;
    int count;
    double elapsed;

    if (noise_hashstate_new_by_id(&hash, id) != NOISE_ERROR_NONE)
        return;

    memset(data, 0xAA, sizeof(data));
    noise_hashstate_reset(hash);
    start = current_timestamp();
    for (count = 0; count < (MB_COUNT * BLOCKS_PER_MB); ++count)
        noise_hashstate_update(hash, data, sizeof(data));
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)MB_COUNT;
    printf("%-20s%8.2f          %8.2f\n",
           noise_id_to_name(NOISE_HASH_CATEGORY, id),
           1.0 / elapsed, units / elapsed);

    noise_hashstate_free(hash);
}
示例#5
0
int main(){
	int n;
	printf("Enter the value of n greater than 0 : ");
	scanf("%d",&n);

	current_timestamp();
	printf("Fibonacci of n is %u\n",fibonacci_rec(n));
	current_timestamp();

	return 0;
}
示例#6
0
int main(int argc, char *argv[]) {
	uint8_t buf[1024];
	size_t n;
#ifdef FRSKY
	frsky_state_t fs;
#endif
	telemetry_data_t td;
	telemetry_init(&td);

	render_init();

	long long prev_time = current_timestamp();
	while(1) {
		FD_ZERO(&set);
		FD_SET(STDIN_FILENO, &set);
		timeout.tv_sec = 0;
		//read 100ms
		timeout.tv_usec = 100*1000;
		n = select(STDIN_FILENO + 1, &set, NULL, NULL, &timeout);
		//printf("%d\n",n);
		if(n > 0) {
			n = read(STDIN_FILENO, buf, sizeof(buf));

			if(n == 0) {
			//	break; //EOF
			}

			if(n<0) {
				perror("read");
				exit(-1);
			}
#ifdef FRSKY
			frsky_parse_buffer(&fs, &td, buf, n);
#elif defined(LTM)
			ltm_read(&td, buf, n);
#elif defined(MAVLINK)
			mavlink_read(&td, buf, n);
#endif
		}

	#ifdef DEBUG
		prev_time = current_timestamp();
		render(&td);
		long long took = current_timestamp() - prev_time;
		printf("Render took %lldms to execute.\n", took);
	#else
		render(&td);
	#endif

	}

	return 0;
}
示例#7
0
/* Calibrates the performance measurements to determine the "MD5 unit" */
static void calibrate_md5(void)
{
    md5_context_t context;
    uint8_t data[BLOCK_SIZE];
    timestamp_t start, end;
    int count;
    memset(data, 0xAA, sizeof(data));
    md5_reset(&context);
    start = current_timestamp();
    for (count = 0; count < (MB_COUNT * BLOCKS_PER_MB); ++count)
        md5_update(&context, data, sizeof(data));
    end = current_timestamp();
    units = elapsed_to_seconds(start, end) / (double)MB_COUNT;
}
示例#8
0
void set_flipped_engine(int engine, int value)
{
    unsigned long long currentTime;
    unsigned long deltaTime, flags;
    data_packet_list_node* storage_dp_list_element = NULL;

    if(!firstFlipOnEngines[engine])
    {
        if(value == 1)// first flip should switch to 1
        { 
            firstFlipOnEngines[engine] = true;
            lastFlipTime[engine] = current_timestamp();
        }
        else
        {
            return;
        }
    }

    currentTime = current_timestamp();
    deltaTime = currentTime - lastFlipTime[engine];
    if(currentTime < lastFlipTime[engine])
    {
        deltaTime = 86400000 + currentTime - lastFlipTime[engine];
    }

    if(deltaTime == 0) return;

    storage_dp_list_element = getNodeFromStorageList(true);
    storage_dp_list_element->dp.engine = engine;
    storage_dp_list_element->dp.deltaTime = deltaTime;
    lastFlipTime[engine] = currentTime;
    
    spin_lock_irqsave(&dp_list_lock, flags);

    addNodeToActiveList(storage_dp_list_element);
    if(wait_queue_flag == true)
    {
        wait_queue_flag = false;
        wake_up_interruptible(&wait_queue);
    }

    spin_unlock_irqrestore(&dp_list_lock, flags);
}
示例#9
0
time_t bay_get_occupation_time(bay *b)
{
    /* when no plane is parked, we can read the overall parking time of the last parked plane,
    otherwise, we read the time since the plane was parked */
    if(b->plane == NULL) {
        return b->parking_time;
    } else {
        return current_timestamp() - b->parking_time;
    }
}
// reference : http://www.paulgriffiths.net/program/c/srcs/echoservsrc.html
void threadMainFunction(void *data){
	int port = *((int*)data);
	int listenSocket;
	int connectedSocket;
	struct    sockaddr_in servaddr;  /*  socket address structure  */
	char buffer[BUFFER_LENGTH];
	FILE *pFile;

	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family      = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port        = htons(port);
	

	memset(buffer, 0, sizeof(buffer));
	sprintf(buffer, "%d.txt", port);
	pFile = fopen(buffer, "w");

	if ( (listenSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
		fprintf(stderr, "Error creating listening socket.\n");
		exit(EXIT_FAILURE);
	}


	if ( bind(listenSocket, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
		fprintf(stderr, "Error calling bind()\n");
		exit(EXIT_FAILURE);
	}

	if ( listen(listenSocket, 0) < 0 ) {
		fprintf(stderr, "Error calling listen()\n");
		exit(EXIT_FAILURE);
	}

	printf("listen port %d\n", port);

	if ( (connectedSocket = accept(listenSocket, NULL, NULL) ) < 0 ) {
		fprintf(stderr, "Error calling accept()\n");
		exit(EXIT_FAILURE);
	}

	printf("accpet port %d\n", port);


	while ( isEnd == 0 ) {
		int length = recv(connectedSocket, buffer, BUFFER_LENGTH, 0);
		if(length > 0){
			fprintf(pFile, "%lld\n", current_timestamp());
		}
	}
	fclose(pFile);
	return;
}
示例#11
0
/* Measure the performance of an AEAD primitive */
static void perf_cipher(int id)
{
    static uint8_t const key[32] = {
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
        0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
        0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
        0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20
    };
    static uint8_t const ad[32] = {
        0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
        0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x20,
        0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
        0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40
    };
    NoiseCipherState *cipher;
    uint8_t data[BLOCK_SIZE + 16];
    timestamp_t start, end;
    int count;
    double elapsed;
    NoiseBuffer mbuf;

    if (noise_cipherstate_new_by_id(&cipher, id) != NOISE_ERROR_NONE)
        return;

    memset(data, 0xAA, sizeof(data));
    noise_cipherstate_init_key(cipher, key, sizeof(key));
    start = current_timestamp();
    for (count = 0; count < (MB_COUNT * BLOCKS_PER_MB); ++count) {
        noise_buffer_set_inout(mbuf, data, sizeof(data) - 16, sizeof(data));
        noise_cipherstate_encrypt_with_ad(cipher, ad, sizeof(ad), &mbuf);
    }
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)MB_COUNT;
    printf("%-20s%8.2f          %8.2f\n",
           noise_id_to_name(NOISE_CIPHER_CATEGORY, id),
           1.0 / elapsed, units / elapsed);

    noise_cipherstate_free(cipher);
}
示例#12
0
static void on_timer(nw_timer *t, void *privdata)
{
    double now = current_timestamp();
    dict_iterator *iter = dict_get_iterator(dict_update);
    dict_entry *entry;
    while ((entry = dict_next(iter)) != NULL) {
        struct update_val *val = entry->val;
        if (val->create_time < (now - 86400)) {
            dict_delete(dict_update, entry->key);
        }
    }
    dict_release_iterator(iter);
}
示例#13
0
// do cp but only for milliseconds then stop
// return copied count in this cp time.  return 0 means all file copied.
off_t cp_for_time(const int fd_src, const int fd_target, const int msec)
{
    //static off_t cur_cp_pos = 0;

    long long start_time = current_timestamp();
    off_t cp_count = 0;

    char read_buf[1024 * 80] = "";
    for(;;)
    {
        ssize_t read_ret = read(fd_src, read_buf, sizeof(read_buf));
        if (read_ret == -1)
        {
            //if (errno == EINTER)
            //    continue;
            error_exit("read error");
        }

        // reading all done
        if (read_ret == 0)
        {
            fsync(fd_target); // force writting to file all.
            return 0;
        }
        
        ssize_t len = read_ret;
        cp_count += len;
        write_to_file(fd_target, read_buf, len);

        long long cur_time = current_timestamp();
        if ((cur_time - start_time) > msec)
        {
            fsync(fd_target);
            return cp_count;
        }
    }
}
示例#14
0
void do_cp(const int fd_src, const int fd_target, const struct stat* pstat_buf)
{
    int each_cp_time = 500 * 0.5;
    const off_t file_size = pstat_buf->st_size;
    off_t all_cp_count = 0;

    for(;;)
    {
        long long start_time = current_timestamp();
        off_t copied_count = cp_for_time(fd_src, fd_target, each_cp_time);
        if (copied_count == 0)
            return;
        long long end_cur_cp_time = current_timestamp();

        if ((end_cur_cp_time - start_time) > 500)
            each_cp_time *= 0.8;
        else
            each_cp_time *= 1.1;
        all_cp_count += copied_count;
        printf("%ld%% cur_cp_time milliseconds: %ld  sleep: 500  next read_time:%d\n", (long)(all_cp_count * 100 / file_size), (long)(end_cur_cp_time - start_time), each_cp_time);

        usleep(500 * 1000);
    }
}
示例#15
0
void udp_delays_ans_cb(evutil_socket_t sock, short ev, void *arg) {
  static uint64_t udp_delays_buff[2];
  struct sockaddr_in client_address;
  socklen_t rcva_len;
  ssize_t len;

  len = recvfrom(sock, (char *)udp_delays_buff, sizeof(uint64_t), 0,
      (struct sockaddr *) &client_address, &rcva_len);
  if (len != sizeof(uint64_t))
    return; // miala byc liczba 64 bitowa, nie musze zachowywac jakiejs
            // smiesznej zgodnosci
  udp_delays_buff[1] = htobe64(current_timestamp());
  sendto(sock, udp_delays_buff, 2 * sizeof(uint64_t), 0,
      (struct sockaddr *) &client_address, rcva_len);
  // nie dalo sie wyslac, coz zyje sie dalej :p
}
示例#16
0
/* Measure the performance of an ephemeral-only DH primitive (e.g NewHope) */
static void perf_dh_ephemeral_only(int id)
{
    char name[64];
    NoiseDHState *dh1;
    NoiseDHState *dh2;
    uint8_t shared_key[32];
    timestamp_t start, end;
    int count;
    double elapsed;

    if (noise_dhstate_new_by_id(&dh1, id) != NOISE_ERROR_NONE)
        return;
    if (noise_dhstate_new_by_id(&dh2, id) != NOISE_ERROR_NONE) {
        noise_dhstate_free(dh1);
        return;
    }

    start = current_timestamp();
    for (count = 0; count < PQ_DH_COUNT; ++count)
        noise_dhstate_generate_keypair(dh1);
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)PQ_DH_COUNT;
    snprintf(name, sizeof(name), "%s generate",
             noise_id_to_name(NOISE_DH_CATEGORY, id));
    printf("%-20s%8.2f          %8.2f\n", name, 1.0 / elapsed, units / elapsed);

    start = current_timestamp();
    for (count = 0; count < PQ_DH_COUNT; ++count)
        noise_dhstate_generate_dependent_keypair(dh2, dh1);
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)PQ_DH_COUNT;
    snprintf(name, sizeof(name), "%s sharedb",
             noise_id_to_name(NOISE_DH_CATEGORY, id));
    printf("%-20s%8.2f          %8.2f\n", name, 1.0 / elapsed, units / elapsed);

    start = current_timestamp();
    for (count = 0; count < PQ_DH_COUNT; ++count)
        noise_dhstate_calculate(dh1, dh2, shared_key, sizeof(shared_key));
    end = current_timestamp();

    elapsed = elapsed_to_seconds(start, end) / (double)PQ_DH_COUNT;
    snprintf(name, sizeof(name), "%s shareda",
             noise_id_to_name(NOISE_DH_CATEGORY, id));
    printf("%-20s%8.2f          %8.2f\n", name, 1.0 / elapsed, units / elapsed);

    noise_dhstate_free(dh1);
    noise_dhstate_free(dh2);
}
示例#17
0
int update_user_balance(bool real, uint32_t user_id, const char *asset, const char *business, uint64_t business_id, mpd_t *change, json_t *detail)
{
    struct update_key key;
    key.user_id = user_id;
    strncpy(key.asset, asset, sizeof(key.asset));
    strncpy(key.business, business, sizeof(key.business));
    key.business_id = business_id;

    dict_entry *entry = dict_find(dict_update, &key);
    if (entry) {
        return -1;
    }

    mpd_t *result;
    mpd_t *abs_change = mpd_new(&mpd_ctx);
    mpd_abs(abs_change, change, &mpd_ctx);
    if (mpd_cmp(change, mpd_zero, &mpd_ctx) >= 0) {
        result = balance_add(user_id, BALANCE_TYPE_AVAILABLE, asset, abs_change);
    } else {
        result = balance_sub(user_id, BALANCE_TYPE_AVAILABLE, asset, abs_change);
    }
    mpd_del(abs_change);
    if (result == NULL)
        return -2;

    struct update_val val = { .create_time = current_timestamp() };
    dict_add(dict_update, &key, &val);

    if (real) {
        double now = current_timestamp();
        json_object_set_new(detail, "id", json_integer(business_id));
        char *detail_str = json_dumps(detail, 0);
        append_user_balance_history(now, user_id, asset, business, change, detail_str);
        free(detail_str);
        push_balance_message(now, user_id, asset, business, change);
    }

    return 0;
}
示例#18
0
void udp_delays_ask_cb(evutil_socket_t sock, short ev, void *arg) {
  int id = * (int*) arg;
  struct sockaddr_in my_address;
  static uint64_t buffer[1];
  my_address.sin_family = AF_INET; // IPv4
	my_address.sin_addr.s_addr = htonl(found_ips[id].ip);
  my_address.sin_port = htons(delay_port);
  int i;




  int len, soc;

  soc = socket(AF_INET, SOCK_DGRAM, 0);

  buffer[0] = htobe64(current_timestamp());
	len = sendto(soc, (void*)buffer, sizeof(uint64_t), 0,
		(struct sockaddr *) &my_address, sizeof(my_address));

	if (len != sizeof(uint64_t)) {
    if(found_UDP[found_ips[id].udp_i])
		  free(found_UDP[found_ips[id].udp_i]);
    found_UDP[found_ips[id].udp_i] = NULL;
    found_ips[id].udp_i = -1;
    event_del(found_ips[id].ev[0]);
    event_free(found_ips[id].ev[0]);
    found_ips[id].ev[0] = NULL;
    for(i = 0; i < 10; ++i)
      found_ips[id].udp_delay[i] = 0;
	}
  else

  event_add(event_new(main_loop, soc, EV_READ, udp_delays_save_cb, arg),NULL);

}
示例#19
0
void __cyg_profile_func_exit (void *func, void *caller) {
  fprintf(trace, "x %p %p %lld\n", func, caller, current_timestamp());
}
示例#20
0
void bay_park_plane(bay *b, plane *p, int runway)
{
    b->plane = p;
    b->parking_time = current_timestamp();
    b->from_runway = runway;
}
示例#21
0
  void CTradeCleanupDB::DoTradeCleanupFrame1(const TTradeCleanupFrame1Input *pIn) {

#ifdef _TRACE
    cout << "TRACE: CTradeCleanupDB::DoTradeCleanupFrame1/1" << '\r' << endl;
#endif

    m_pDbc->StartTransaction();

    {
      TTrade trade_id;
      TIMESTAMP_STRUCT now_dts;

      CHandleStmt *pStmt;
      int p;

      current_timestamp(&now_dts);

      { // -- 0 --
        ((CTradeCleanupDBStmt0 *)m_pStmt[0])
          ->BindCol(&trade_id);

        if (m_pStmt[0]->Execute()) { // SELECT : trade_request

          for (INT32 max_trades = m_pStmt[0]->RowCount(), n = 0; n < max_trades; n++) {

            trade_id = 0;

            m_pStmt[0]->Fetch();

#ifdef _TRACE
            cout << "TRACE: [1,0:" << n << "] trade_id=" << trade_id << '\r' << endl;
#endif
            { // -- 1 --
              ((CTradeCleanupDBStmt1 *)(pStmt = m_pStmt[(p = 1)]))
                ->BindParameter(&trade_id, &now_dts,
                                pIn->st_submitted_id, sizeof(pIn->st_submitted_id));
#ifdef _TRACE
              cout << "TRACE: [1,0:" << n << "," << p << "] trade_id="
                   << trade_id << '\r' << endl;
              cout << "TRACE: [1,0:" << n << "," << p << "] now_dts="
                   << now_dts << '\r' << endl;
              cout << "TRACE: [1,0:" << n << "," << p << "] st_submitted_id="
                   << pIn->st_submitted_id << '\r' << endl;
#endif
              if (pStmt->Execute()) { // INSERT : trade_history
#ifdef _TRACE
                cout << "TRACE: [1,0:" << n << "," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
                pStmt->Cancel();
              }
            } // -- 1 --

            { // -- 2 --
              ((CTradeCleanupDBStmt2 *)(pStmt = m_pStmt[(p = 2)]))
                ->BindParameter(&trade_id, &now_dts,
                                pIn->st_canceled_id, sizeof(pIn->st_canceled_id));
#ifdef _TRACE
              cout << "TRACE: [1,0:" << n << "," << p << "] trade_id="
                   << trade_id << '\r' << endl;
              cout << "TRACE: [1,0:" << n << "," << p << "] now_dts="
                   << now_dts << '\r' << endl;
              cout << "TRACE: [1,0:" << n << "," << p << "] st_canceled_id="
                   << pIn->st_canceled_id << '\r' << endl;
#endif
              if (pStmt->Execute()) { // UPDATE : trade
#ifdef _TRACE
                cout << "TRACE: [1,0:" << n << "," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
                pStmt->Cancel();
              }
            } // -- 2 --

            { // -- 3 (=1) --
              ((CTradeCleanupDBStmt1 *)(pStmt = m_pStmt[1]))
                ->BindParameter(&trade_id, &now_dts,
                                pIn->st_canceled_id, sizeof(pIn->st_canceled_id));
#ifdef _TRACE
              cout << "TRACE: [1,0:" << n << ",3] trade_id="
                   << trade_id << '\r' << endl;
              cout << "TRACE: [1,0:" << n << ",3] now_dts="
                   << now_dts << '\r' << endl;
              cout << "TRACE: [1,0:" << n << ",3] st_canceled_id="
                   << pIn->st_canceled_id << '\r' << endl;
#endif
              if (pStmt->Execute()) { // INSERT : trade_history
#ifdef _TRACE
                cout << "TRACE: [1,0:" << n << ",3] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
                pStmt->Cancel();
              }
            } // -- 3 --

          } // for (max_trades)

          m_pStmt[0]->Cancel();
        }
      } // -- 0 --

      { // -- 4 --
        pStmt = m_pStmt[(p = 4)];
        if (pStmt->Execute()) { // DELETE : trade_request

#ifdef _TRACE
          cout << "TRACE: [1," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
          pStmt->Cancel();
        }
      } // -- 4 --

      { // -- 5 --
        ((CTradeCleanupDBStmt5 *)m_pStmt[5])
          ->BindParameter(pIn)
          ->BindCol(&trade_id);

#ifdef _TRACE
        cout << "TRACE: [1,5] start_trade_id=" << pIn->start_trade_id << '\r' << endl;
        cout << "TRACE: [1,5] st_submitted_id=" << pIn->st_submitted_id << '\r' << endl;
#endif
        if (m_pStmt[5]->Execute()) { // SELECT : trade

          for (int max_trades = m_pStmt[5]->RowCount(), n = 0; n < max_trades; n++) {

            trade_id = 0;

            m_pStmt[5]->Fetch();

#ifdef _TRACE
            cout << "TRACE: [1,5:" << n << "] trade_id=" << trade_id << '\r' << endl;
#endif
            { // -- 6 (=2) --
              ((CTradeCleanupDBStmt2 *)(pStmt = m_pStmt[2]))
                ->BindParameter(&trade_id, &now_dts,
                                pIn->st_canceled_id, sizeof(pIn->st_canceled_id));
#ifdef _TRACE
              cout << "TRACE: [1,5" << n << ",6] trade_id=" << trade_id << '\r' << endl;
              cout << "TRACE: [1,5" << n << ",6] now_dts=" << now_dts << '\r' << endl;
              cout << "TRACE: [1,5" << n << ",6] st_canceled_id=" << pIn->st_canceled_id << '\r' << endl;
#endif
              if (pStmt->Execute()) { // UPDATE : trade
#ifdef _TRACE
                cout << "TRACE: [1,5" << n << ",6] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
                pStmt->Cancel();
              }
            } // -- 6 --

            { // -- 7 (=1) --
              ((CTradeCleanupDBStmt1 *)(pStmt = m_pStmt[1]))
                ->BindParameter(&trade_id, &now_dts,
                                pIn->st_canceled_id, sizeof(pIn->st_canceled_id));
#ifdef _TRACE
              cout << "TRACE: [1,5" << n << ",7] trade_id=" << trade_id << '\r' << endl;
              cout << "TRACE: [1,5" << n << ",7] now_dts=" << now_dts << '\r' << endl;
              cout << "TRACE: [1,5" << n << ",7] st_canceled_id=" << pIn->st_canceled_id << '\r' << endl;
#endif
              if (pStmt->Execute()) { // INSERT : trade_history
#ifdef _TRACE
                cout << "TRACE: [1,5" << n << ",7] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
                pStmt->Cancel();
              }
            } // -- 7 --

          } // for (max_trades)
        }
      } // -- 5 --
    }

    m_pDbc->CommitTransaction();
  }
示例#22
0
文件: eigrp_ip6.c 项目: dervel/eigrp
void send_packets_neighbour_ip6(neighbour *n){
	long long current_time;
	long long delay = 1000; //Send or resend packets every 1 second

	current_time = current_timestamp();

	if(current_time - n->last_response > n->holdtime){
		printf("Neighbour is inactive removing him.\n");
		free_neighbour(n,"holding time expired");
		return;
	}

	if((!n->send_next_packet) && current_time - n->last_packet_sent < delay){
		return;
	}

	n->send_next_packet = false;

	if(linkedlist_isempty(&n->packet_queue)){
		if(n->last_ack_sent != n->pending_ack && n->pending_ack != -1){
			int length = sizeof(struct eigrphdr);
			packetv4_param *packet = create_empty_packet(OPCODE_HELLO,0, n->sin);


	
			n->last_ack_sent = n->pending_ack;
			create_eigrp_header(packet, length, OPCODE_HELLO, n->proc->proccess_id, 0, n->pending_ack, 0);

			//Record packets sent
			n->proc->stats.packets_sent[packet->opcode]++;
			if(n->pending_ack != 0)n->proc->stats.acks_sent++;

			send_ip4_packet(packet,n->interface->socket4);
			n->last_packet_sent = current_time;

			free(packet);
		}
	}else{
		packetv4_param *packet = linkedlist_peekfirst(&n->packet_queue);
		if(packet->seq_num == 0){
			int seq_num = n->proc->seq_num++; //increase the seq_num by 1
			packet->seq_num = seq_num; //assign the seq to the struct so it be retrived later to check for ack
			
			//create_eigrp_header(packet, packet->buffer_len, packet->opcode, n->proc->proccess_id, packet->seq_num , n->pending_ack, packet->flags);
			//n->last_ack_sent = n->pending_ack;

			//Save the seq num for the neighbour state change				
			if( flags_are_set(packet->flags, FLAG_INIT) ){
				n->init_seq = seq_num;
			}
		}

		int ack = n->pending_ack;
		if(ack == -1) ack = 0; 
		create_eigrp_header(packet, packet->buffer_len, packet->opcode, n->proc->proccess_id, packet->seq_num , ack, packet->flags);
		n->last_ack_sent = n->pending_ack;
		
		//Record packets sent
		n->proc->stats.packets_sent[packet->opcode]++;
		if(n->pending_ack != 0)n->proc->stats.acks_sent++;
		
		send_ip4_packet(packet,n->interface->socket4);
		n->last_packet_sent = current_time;
	}
}
示例#23
0
void CurrentTimestamp(const v8::FunctionCallbackInfo<v8::Value>& args){
  args.GetReturnValue().Set(static_cast<double>(current_timestamp()));
}
示例#24
0
文件: main.c 项目: dyu/ffi-overhead
static void wren_start(WrenVM* vm)
{
    //printf("start\n");
    ts_start = current_timestamp();
}
/**
 * entry point of the program.
 *
 * @function   main
 *
 * @date       2016-01-15
 *
 * @revision   none
 *
 * @designer   Eric Tsang
 *
 * @programmer Eric Tsang
 *
 * @note
 *
 * sets up synchronization primitives, spawns worker threads, generates tasks
 *   for workers, receives results from workers, waits for workers to terminate,
 *   writes results to a file, and stdout.
 *
 * @signature  int main(int argc,char** argv)
 *
 * @param      argc number of command line arguments
 * @param      argv array of c strings of command line arguments
 *
 * @return     status code.
 */
int main(int argc,char** argv)
{
    // parse command line arguments
    if (argc != 4)
    {
        fprintf(stderr,"usage: %s [integer] [path to log file] [num workers]\n",argv[0]);
        return 1;
    }
    if(mpz_set_str(prime.value,argv[1],10) == -1)
    {
        fprintf(stderr,"usage: %s [integer] [path to log file] [num workers]\n",argv[0]);
        return 1;
    }
    int logfile = open(argv[2],O_CREAT|O_WRONLY|O_APPEND);
    FILE* logFileOut = fdopen(logfile,"w");
    if(logfile == -1 || errno)
    {
        fprintf(stderr,"usage: %s [integer] [path to log file] [num workers]\nerror occurred: ",argv[0]);
        perror(0);
        return 1;
    }
    unsigned int numWorkers = atoi(argv[3]);
    if (numWorkers <= 0)
    {
        fprintf(stderr,"usage: %s [integer] [path to log file] [num workers]\n num workers must be larger than or equal to 1",argv[0]);
        return 1;
    }

    // set up synchronization primitives
    for(register unsigned int i; i < numWorkers*MAX_PENDING_TASKS_PER_WORKER; ++i)
    {
        tasksNotFullSem.post();
    }

    // get start time
    long startTime = current_timestamp();

    // create the worker threads
    std::vector<pthread_t> workers;
    for(register unsigned int i = 0; i < numWorkers; ++i)
    {
        pthread_t worker;
        pthread_create(&worker,0,worker_routine,0);
        workers.push_back(worker);
    }

    // create tasks and place them into the tasks vector
    {
        Number prevPercentageComplete;
        Number percentageComplete;
        Number tempLoBound;
        Number loBound;

        for(mpz_set_ui(loBound.value,1);
                mpz_cmp(loBound.value,prime.value) <= 0;
                mpz_add_ui(loBound.value,loBound.value,MAX_NUMBERS_PER_TASK))
        {
            // calculate and print percentage complete
            mpz_set(prevPercentageComplete.value,percentageComplete.value);
            mpz_mul_ui(tempLoBound.value,loBound.value,100);
            mpz_div(percentageComplete.value,tempLoBound.value,prime.value);
            if(mpz_cmp(prevPercentageComplete.value,percentageComplete.value) != 0)
            {
                gmp_fprintf(stdout,"%Zd%\n",percentageComplete.value);
                gmp_fprintf(logFileOut,"%Zd%\n",percentageComplete.value);
            }

            // insert the task into the task queue once there is room
            Number* newNum = new Number();
            mpz_set(newNum->value,loBound.value);
            tasksNotFullSem.wait();
            Lock scopelock(&taskAccess.sem);
            tasks.push_back(newNum);
        }
    }
    allTasksProduced = true;

    // join all worker threads
    for(register unsigned int i = 0; i < numWorkers; ++i)
    {
        void* unused;
        pthread_join(workers[i],&unused);
    }

    // get end time
    long endTime = current_timestamp();

    // print out calculation results
    std::sort(results.begin(),results.end(),[](Number* i,Number* j)
    {
        return mpz_cmp(i->value,j->value) < 0;
    });
    fprintf(stdout,"factors: ");
    fprintf(logFileOut,"factors: ");
    for(register unsigned int i = 0; i < results.size(); ++i)
    {
        gmp_fprintf(stdout,"%s%Zd",i?", ":"",results[i]->value);
        gmp_fprintf(logFileOut,"%s%Zd",i?", ":"",results[i]->value);
        delete results[i];
    }
    fprintf(stdout,"\n");
    fprintf(logFileOut,"\n");

    // print out execution results
    fprintf(stdout,"total runtime: %lums\n",endTime-startTime);
    fprintf(logFileOut,"total runtime: %lums\n",endTime-startTime);

    // release system resources
    fclose(logFileOut);
    close(logfile);

    return 0;
}
示例#26
0
文件: main.c 项目: dyu/ffi-overhead
static void wren_stop(WrenVM* vm)
{
    ts_stop = current_timestamp();
    //printf("stop\n");
}
示例#27
0
  void CTradeResultDB::DoTradeResultFrame2(const TTradeResultFrame2Input *pIn,
                                           TTradeResultFrame2Output *pOut) {
#ifdef _TRACE
    cout << "TRACE: CTradeResultDB::DoTradeResultFrame2/2" << '\r' << endl;
#endif

    {
      TTrade hold_id;
      double hold_price;
      INT32 hold_qty;
      INT32 needed_qty;

      CHandleStmt *pStmt;
      int p;

      current_timestamp(&pOut->trade_dts);

      { // -- 2 --
        ((CTradeResultDBStmt02 *)(pStmt = m_pStmt[(p = 2)]))
          ->BindParameter(pIn)
          ->BindCol(pOut);

#ifdef _TRACE
        cout << "TRACE: [2," << p << "] ca_id=" << pIn->acct_id << '\r' << endl;
#endif
        if (pStmt->Execute()) { // SELECT : customer_account

          for (SQLLEN size = pStmt->RowCount(), i = 0; i < size; i++) {

            pStmt->Fetch();

#ifdef _TRACE
            cout << "TRACE: [2," << p << ":" << i << "] broker_id=" << pOut->broker_id << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] cust_id=" << pOut->cust_id << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] tax_status=" << pOut->tax_status << '\r' << endl;
#endif
          }

          pStmt->Cancel();
        }
      } // -- 2 --

      if (0 == pIn->hs_qty) {

        { // -- 3 --
          ((CTradeResultDBStmt03 *)(pStmt = m_pStmt[(p = 3)]))
            ->BindParameter(pIn);

#ifdef _TRACE
          cout << "TRACE: [2," << p << "] hs_ca_id=" << pIn->acct_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] hs_s_symb=" << pIn->symbol << '\r' << endl;
          cout << "TRACE: [2," << p << "] hs_qty=" << pIn->trade_qty << '\r' << endl;
          cout << "TRACE: [2," << p << "] type_is_sell=" << pIn->type_is_sell << '\r' << endl;
#endif
          if (pStmt->Execute()) { // INSERT : holding_summary

#ifdef _TRACE
            cout << "TRACE: [2," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
            pStmt->Cancel();
          }
        } // -- 3 --

      } else if (abs(pIn->hs_qty) != pIn->trade_qty) {

        { // --  4 --
          ((CTradeResultDBStmt04 *)(pStmt = m_pStmt[(p = 4)]))
            ->BindParameter(pIn);

#ifdef _TRACE
          cout << "TRACE: [2," << p << "] hs_qty+=" << pIn->trade_qty << '\r' << endl;
          cout << "TRACE: [2," << p << "] hs_ca_id=" << pIn->acct_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] hs_s_symb=" << pIn->symbol << '\r' << endl;
          cout << "TRACE: [2," << p << "] type_is_sell=" << pIn->type_is_sell << '\r' << endl;
#endif
          if (pStmt->Execute()) { // UPDATE : holding_summary

#ifdef _TRACE
            cout << "TRACE: [2," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
            pStmt->Cancel();
          }
        } // -- 4 --

      }

      needed_qty = pIn->trade_qty;

      if (0 < abs(pIn->hs_qty)) {

        if (1 == pIn->is_lifo) {
          ((CTradeResultDBStmt06 *)(pStmt = m_pStmt[(p = 6)]))
            ->BindParameter(pIn)
            ->BindCol(&hold_id, &hold_qty, &hold_price);
        } else {
          ((CTradeResultDBStmt07 *)(pStmt = m_pStmt[(p = 7)]))
            ->BindParameter(pIn)
            ->BindCol(&hold_id, &hold_qty, &hold_price);
        }

#ifdef _TRACE
        cout << "TRACE: [2," << p << "] h_ca_id=" << pIn->acct_id << '\r' << endl;
        cout << "TRACE: [2," << p << "] h_s_symb=" << pIn->symbol << '\r' << endl;
#endif
        if (pStmt->Execute()) { // SELECT : holding [DESC|ASC]

          double buy_value = 0;
          double sell_value = 0;

          for (SQLLEN size = pStmt->RowCount(), i = 0; 0 != needed_qty && i < size; i++) {

            hold_id = 0;
            hold_qty = 0;
            hold_price = 0.0;

            pStmt->Fetch();

#ifdef _TRACE
            cout << "TRACE: [2," << p << ":" << i << "] hold_id=" << hold_id << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] hold_qty=" << hold_qty << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] hold_price=" << hold_price << '\r' << endl;
#endif
            CHandleStmt *pStmt2;
            int p2;

            if (hold_qty > needed_qty) {

              INT32 qty =
                hold_qty + (1 == pIn->type_is_sell ? needed_qty * -1 : needed_qty);

              { // -- 11 --
                ((CTradeResultDBStmt11 *)(pStmt2 = m_pStmt[(p2 = 11)]))
                  ->BindParameter(pIn, &hold_id, &pIn->trade_id, &hold_qty, &qty);
#ifdef _TRACE
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_h_t_id="
                     << hold_id << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_t_id="
                     << pIn->trade_id << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_before_qty="
                     << hold_qty << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_after_qty="
                     << qty << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] type_is_sell="
                     << pIn->type_is_sell << '\r' << endl;
#endif
                if (pStmt2->Execute()) { // INSERT : holding_history
#ifdef _TRACE
                  cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] row_count="
                       << pStmt2->RowCount() << '\r' << endl;
#endif
                  pStmt2->Cancel();
                }
              } // -- 11 --

              { // -- 9 -- : TODO, CURRENT_ROW
                ((CTradeResultDBStmt09 *)(pStmt2 = m_pStmt[(p2 = 9)]))
                  ->BindParameter(&hold_id, &qty);
#ifdef _TRACE
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] h_qty="
                     << qty << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] h_t_id="
                     << hold_id << '\r' << endl;
#endif
                if (pStmt2->Execute()) { // UPDATE : holding
#ifdef _TRACE
                  cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] row_count="
                       << pStmt2->RowCount() << '\r' << endl;
#endif
                  pStmt2->Cancel();
                }
              } // -- 9 --

              if (1 == pIn->type_is_sell) {
                sell_value += needed_qty * pIn->trade_price;
                buy_value  += needed_qty * hold_price;
                needed_qty  = 0;
              } else {
                sell_value += needed_qty * hold_price;
                buy_value  += needed_qty * pIn->trade_price;
                needed_qty  = 0;
              }

            } else { // hold_qty <= needed_qty


              INT32 qty = 0;

              { // -- 11 --
                ((CTradeResultDBStmt11 *)(pStmt2 = m_pStmt[(p2 = 11)]))
                  ->BindParameter(pIn, &hold_id, &pIn->trade_id, &hold_qty, &qty);
#ifdef _TRACE
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_h_t_id="
                     << hold_id << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_t_id="
                     << pIn->trade_id << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_before_qty="
                     << hold_qty << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] hh_after_qty="
                     << qty << '\r' << endl;
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] type_is_sell="
                     << pIn->type_is_sell << '\r' << endl;
#endif
                if (pStmt2->Execute()) { // INSERT : holding_history
#ifdef _TRACE
                  cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] row_count="
                       << pStmt2->RowCount() << '\r' << endl;
#endif
                  pStmt2->Cancel();
                }
              } // -- 11 --

              { // -- 10 -- : TODO, CURRENT_ROW
                ((CTradeResultDBStmt10 *)(pStmt2 = m_pStmt[(p2 = 10)]))
                  ->BindParameter(&hold_id);
#ifdef _TRACE
                cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] h_t_id="
                     << hold_id << '\r' << endl;
#endif
                if (pStmt2->Execute()) { // DELETE : holding
#ifdef _TRACE
                  cout << "TRACE: [2," << p << ":" << i << "," << p2 << "] row_count="
                       << pStmt2->RowCount() << '\r' << endl;
#endif
                  pStmt2->Cancel();
                }
              } // -- 10 --

              if (1 == pIn->type_is_sell) {
                sell_value += hold_qty * pIn->trade_price;
                buy_value  += hold_qty * hold_price;
                needed_qty -= hold_qty;
              } else {
                sell_value -= hold_qty * hold_price;
                buy_value  -= hold_qty * pIn->trade_price;
                needed_qty += hold_qty;
              }

            } // hold_qty <= needed_qty

#ifdef _TRACE
            cout << "TRACE: [2," << p << ":" << i << "] sell_value=" << sell_value << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] buy_value=" << buy_value << '\r' << endl;
            cout << "TRACE: [2," << p << ":" << i << "] needed_qty=" << needed_qty << '\r' << endl;
#endif
          } // for (size)

          pStmt->Cancel();
        }
      } // 0 < hs_qty

#ifdef _TRACE
      cout << "TRACE: [2] needed_qty=" << needed_qty << '\r' << endl;
#endif

      if (0 < needed_qty) {

        { // -- 11 --
          hold_qty = 0;

          ((CTradeResultDBStmt11 *)(pStmt = m_pStmt[(p = 11)]))
            ->BindParameter(pIn, &pIn->trade_id, &pIn->trade_id, &hold_qty, &needed_qty);

#ifdef _TRACE
          cout << "TRACE: [2," << p << "] hh_h_t_id=" << pIn->trade_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] hh_t_id=" << pIn->trade_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] hh_before_qty=" << hold_qty << '\r' << endl;
          cout << "TRACE: [2," << p << "] hh_after_qty=" << needed_qty << '\r' << endl;
          cout << "TRACE: [2," << p << "] type_is_sell=" << pIn->type_is_sell << '\r' << endl;
#endif
          if (pStmt->Execute()) { // INSERT : holding_history

#ifdef _TRACE
            cout << "TRACE: [2," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
            pStmt->Cancel();
          }
        } // -- 11 --

        { // -- 8 --
          ((CTradeResultDBStmt08 *)(pStmt = m_pStmt[(p = 8)]))
            ->BindParameter(pIn, pOut, &needed_qty);

#ifdef _TRACE
          cout << "TRACE: [2," << p << "] h_t_id=" << pIn->trade_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] h_ca_id=" << pIn->acct_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] h_s_symb=" << pIn->symbol << '\r' << endl;
          cout << "TRACE: [2," << p << "] h_dts=" << pOut->trade_dts << '\r' << endl;
          cout << "TRACE: [2," << p << "] h_price=" << pIn->trade_price << '\r' << endl;
          cout << "TRACE: [2," << p << "] h_qty=" << needed_qty << '\r' << endl;
          cout << "TRACE: [2," << p << "] type_is_sell=" << pIn->type_is_sell << '\r' << endl;
#endif
          if (pStmt->Execute()) { // INSERT : holding

#ifdef _TRACE
            cout << "TRACE: [2," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
            pStmt->Cancel();
          }
        } // -- 8 --

      } else if (abs(pIn->hs_qty) == pIn->trade_qty) {

        { // -- 5 --
          ((CTradeResultDBStmt05 *)(pStmt = m_pStmt[(p = 5)]))
            ->BindParameter(pIn);

#ifdef _TRACE
          cout << "TRACE: [2," << p << "] hs_ca_id=" << pIn->acct_id << '\r' << endl;
          cout << "TRACE: [2," << p << "] hs_s_symb=" << pIn->symbol << '\r' << endl;
#endif
          if (pStmt->Execute()) { // DELETE : holding_summary

#ifdef _TRACE
            cout << "TRACE: [2," << p << "] row_count=" << pStmt->RowCount() << '\r' << endl;
#endif
            pStmt->Cancel();
          }
        } // -- 5 --

      } // hs_qtr == trade_qty
    }
  }