Exemplo n.º 1
0
/**
  * Registers the end of the block.
  */
void profiler_end(void)
{
#if defined (mc_debugChecks) && mc_debugChecks == 1
    if(!profFile)		// Switches to the next block.
        error("profiler_end: profiler is not initialized.");

    if(profLevel * (mc_maxLevel - 1 - profLevel) < 0) error("profiler_end: bad level (%d).", profLevel);
#endif

    timeTick_t endAt;
    time_get(&endAt);	// Remembers finalization time of event.

    if(profAccumEvent) {
        sample_t *event = profAccumLevelBeginnings[profAccumLevel];
        event->accumulated += time_elapsed(&event->startAt, &endAt);
        if(event <= profAccumEvent) profAccumEvent = 0;

        if(profLevel == profAccumLevel && profAccumLevelBeginnings[profLevel] == profLevelBeginnings[profLevel])	// New blocks should be closed as usual.
            --profLevel;

        --profAccumLevel;
    }
    else {
        sample_t *event = profLevelBeginnings[profLevel];
        event->accumulated += time_elapsed(&event->startAt, &endAt);
        --profLevel;
    }
}
Exemplo n.º 2
0
void bench() {
	
	/*char p[] = "2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - 0 1";*/
	char p[] = "r2q1rk1/1ppnbppp/p2p1nb1/3Pp3/2P1P1P1/2N2N1P/PPB1QP2/R1B2RK1 b - - ";
	/*char p[] = "8/pR1b1kpp/8/8/3p2n1/3P4/P4qPP/Q6K b - - 0 28";
	char p[]="8/5kpp/2K5/p5q1/6P1/5P2/8/2q5 w - - 0 53";
	2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - 0 1
	*/
	double nps;
	unsigned int start_time, end_time, delta, c;
	nps = 0;
	delta = 0;

	/* Important area for testing */
	for (c = 0;c < 5;c++) {
			set_position(p);
			init_data();
			print_board();
			tree.max_depth = 8;
			tree.delta_time = (10 * 60 * 1000);
			start_time = time_elapsed();
			find_best_move(IO_CONSOLE,NEW_SEARCH);
			end_time = time_elapsed();
			nps += Nodes;
			delta += (end_time - start_time);
			}

	nps /= (double)(delta);
	nps *= 1000.0;
	printf("Nodes per second: %d\n", (int)nps);
	}
Exemplo n.º 3
0
static void thought_setup(void)
{
    /* generate a unique thought ID from the time */
    generate_thought_id();
    
    if (!g_debug)
    {
        /* 'daemonize' the current process */
        pid_t pid = fork();
        if (pid < 0)
        {
            lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Unable to go to background, aborting.\n",
                                  thought_id, time_elapsed());
            exit(EXIT_FAILURE);
        }
        if (pid > 0)
        {
            /* exit the parent process,
             returning control to the waiting caller */
            exit(EXIT_SUCCESS);
        }
    }
    
    /* set child process file creation mask;
     rw- (file) r-x (directory) */
    umask(0);
    
    /* reinitalize logging after forking */
    log_init(g_brain_log_name, SYSLOG_DAEMON);
    if (g_debug)
    {
        log_debug();
        log_stdout(1);
    }
    
    if (!g_debug)
    {
        /* create a new session ID for the child process */
        if (setsid() < 0) {
            lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Unable to obtain session ID, aborting.\n",
                                  thought_id, time_elapsed());
            exit(EXIT_FAILURE);
        }
    }
    
    /* change the current working directory */
    if (chdir(g_brain_thoughts) < 0) {
        lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Unable to access thought directory, aborting.\n",
                              thought_id, time_elapsed());
        exit(EXIT_FAILURE);
    }
    
    if (!g_debug)
    {
        /* close out the standard file descriptors */
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
    }
}
Exemplo n.º 4
0
  virtual void do_update_ui() {
    const unsigned c_width = 60;

    percent_done = calc_percent(extract_completed, extract_total);

    unsigned __int64 extract_speed;
    if (time_elapsed() == 0)
      extract_speed = 0;
    else
      extract_speed = al_round(static_cast<double>(extract_completed) / time_elapsed() * ticks_per_sec());

    if (extract_total && cache_total > extract_total)
      cache_total = extract_total;

    unsigned cache_stored_percent = calc_percent(cache_stored, cache_total);
    unsigned cache_written_percent = calc_percent(cache_written, cache_total);

    wostringstream st;
    st << fit_str(arc_path, c_width) << L'\n';
    st << L"\x1\n";
    st << fit_str(extract_file_path, c_width) << L'\n';
    st << setw(7) << format_data_size(extract_completed, get_size_suffixes()) << L" / " << format_data_size(extract_total, get_size_suffixes()) << L" @ " << setw(9) << format_data_size(extract_speed, get_speed_suffixes()) << L'\n';
    st << Far::get_progress_bar_str(c_width, percent_done, 100) << L'\n';
    st << L"\x1\n";
    st << fit_str(cache_file_path, c_width) << L'\n';
    st << L"(" << format_data_size(cache_stored, get_size_suffixes()) << L" - " << format_data_size(cache_written, get_size_suffixes()) << L") / " << format_data_size(cache_total, get_size_suffixes()) << L'\n';
    st << get_progress_bar_str(c_width, cache_written_percent, cache_stored_percent) << L'\n';
    progress_text = st.str();
  }
Exemplo n.º 5
0
/**
  * Registers the end of the block and starts new block (kind of barrier with only one call to timer).
  */
void profiler_endBegin(int id)
{
#if defined (mc_debugChecks) && mc_debugChecks == 1
    if(!profFile)		// Switches to the next block.
        error("profiler_end: profiler is not initialized.");

    if(profLevel * (mc_maxLevel - 1 - profLevel) < 0)
        error("profiler_end: bad level (%d).", profLevel);

    if(profEvent >= profEvents + mc_eventCacheN)
        error
        ("profiler_begin: small cache, %d events already registered.",
         profEvent - profEvents);
#endif

    timeTick_t endAt;
    time_get(&endAt);	// Remembers finalization time of event.

    if(profAccumEvent)	// End part.
    {
        sample_t *event = profAccumLevelBeginnings[profAccumLevel];
        event->accumulated += time_elapsed(&event->startAt, &endAt);
        if(event <= profAccumEvent) profAccumEvent = 0;

        if(profLevel == profAccumLevel && profAccumLevelBeginnings[profLevel] == profLevelBeginnings[profLevel])	// New blocks should be closed as usual.
            --profLevel;

        --profAccumLevel;
    }
    else {
        sample_t *event = profLevelBeginnings[profLevel];
        event->accumulated += time_elapsed(&event->startAt, &endAt);
        --profLevel;
    }

    if(profAccumEvent)	// Begin part.
    {
        sample_t *event = profAccumEvent;
        while(event < profEvent && event->id != id) ++event;

        if(event < profEvent) {
            event->startAt = endAt;	// Remembers start time and event type.
            profAccumLevel = event->level;
            profAccumLevelBeginnings[profAccumLevel] = event;
            return;
        }
    }

    profEvent->startAt = endAt;	// Remembers start time and event type.
    profEvent->id = id;
    profEvent->level = profAccumLevel = ++profLevel;
    profAccumLevelBeginnings[profLevel] = profLevelBeginnings[profLevel] = profEvent;	// Remembers descriptor of the start of event.
    ++profEvent;
}
Exemplo n.º 6
0
DECLARE_TEST(time, builtin) {
	tick_t tick, newtick, tps;
	deltatime_t dt;

	tps = time_ticks_per_second();
	EXPECT_GT(tps, 0);

	tick = time_current();
	thread_sleep(30);
	newtick = time_current();

	EXPECT_TICKNE(tick, 0);
	EXPECT_TICKGT(newtick, tick);

	EXPECT_TICKGT(time_diff(tick, newtick), 0);
	EXPECT_GT_MSGFORMAT(time_diff(tick, newtick), (tps / 100LL),
	                    "time elapsed not more than 10ms: %" PRId64 " (%" PRId64 ")", time_diff(tick, newtick),
	                    (tps / 100)); //more than 10 ms
	EXPECT_LT_MSGFORMAT(time_diff(tick, newtick), (tps / 20LL),
	                    "time elapsed not less than 50ms: %" PRId64 " (%" PRId64 ")", time_diff(tick, newtick),
	                    (tps / 33)); //less than 30 ms
	EXPECT_REALGT(time_elapsed(tick), 0);
	EXPECT_REALGT(time_elapsed(tick), 0.01f); //more than 10 ms
	EXPECT_TICKGT(time_elapsed_ticks(tick), 0);
	EXPECT_TICKGT(time_elapsed_ticks(tick), (tps / 100)); //more than 10 ms
	EXPECT_TICKLT(time_elapsed_ticks(tick), (tps / 20));  //less than 50 ms

	dt = time_ticks_to_seconds(newtick - tick);
	EXPECT_REALGT(dt, 0);
	EXPECT_GT_MSGFORMAT(dt, 0.01f, "time elapsed in seconds not more than 10ms: %.5f",
	                    dt);   //more than 10 ms
	EXPECT_LT_MSGFORMAT(dt, 0.05f, "time elapsed in seconds not less than 30ms: %.5f",
	                    dt);   //less than 30 ms

	tick = time_startup();
	EXPECT_TICKGT(tick, 0);
	EXPECT_TICKLT(tick, newtick);
	EXPECT_TICKEQ(tick, time_startup());

	tick = time_system();
	thread_sleep(100);
	newtick = time_system();

	EXPECT_TICKGT(tick, 0);
	EXPECT_TICKGT(newtick, 0);
	EXPECT_TICKGT(newtick, tick);
	EXPECT_GT_MSGFORMAT(newtick - tick, 50,
	                    "Elapsed system time less than 50ms, expected 100ms, got %" PRId64 "ms", newtick - tick);
	EXPECT_LT_MSGFORMAT(newtick - tick, 200,
	                    "Elapsed system time more than 200ms, expected 100ms, got %" PRId64 "ms", newtick - tick);

	return 0;
}
Exemplo n.º 7
0
// ---------------------------------------------------------------------------
/// Checks external termination request or time-out (decision is made <b>by master node only</b> thus everything is coherent).
// ---------------------------------------------------------------------------
static void
main_throwStopFlag (void)
{
   // Workers decide nothing.
   if (cpu_here)
      return;

   static int buffer[2];
   FILE *fp = cfg_open ("tmp/stop.flag", "rt", __func__);
   // "Fire alarm" and time limit in seconds.
   fscanf (fp, "%d %d", buffer, buffer + 1);
   fclose (fp);

   static timeTick_t now,
                     prevCheckTime;
   time_get (&now);

   // Checks if next check-point time < walltime.
   static double dT = 0;
   double estimate = time_elapsed (&stopFlag_startTime, &now)
                   + 1.2*dT + 1.5*stopFlag_saveTime;
   if (estimate >= buffer[1] || buffer[0]) {
      say ("main_throwStopFlag: time limit reached\n"
           "  o time = %f\n  o save time = %f\n"
           "  o interval between checks = %f\n"
           "  o estimate next hit time = %f\n  o time limit = %d\n",
           time_elapsed(&stopFlag_startTime, &now),
           stopFlag_saveTime,
           dT, estimate, buffer[1]);
      buffer[0] = 1;
   }

   // Updates estimate of step duration.
   static int first = 1;
   if (!first)
      dT = 0.8*time_elapsed (&prevCheckTime, &now) + 0.2*dT;
   prevCheckTime = now;

   ENSURE (cpu_total <= 1000,
           "increase 'stopFlag_requests' array at least up to %d", cpu_total);

   // Sends stop flag to everybody.
   buffer[1] = cpu_total;
   for (int cpu = 0 ; cpu < cpu_total ; cpu++) {
      MPI_Isend (buffer, 2, MPI_INT, cpu, TAG_STOP_REQUEST, MPI_COMM_WORLD,
                 stopFlag_requests + cpu);
   }
}
Exemplo n.º 8
0
void perft(char dep) {
	int start_time, end_time;
	char num[65];
	float time;
	/*char p0[]="r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1";
	char p0[]="8/PPP4k/8/8/8/8/4Kppp/8 w - - ";*/
	/*8/2p5/3p4/KP5r/1R3p1k/6P1/4P3/8 b - - 0 1*/
	/*char p0[]="8/2p5/3p4/KP5r/1R3p1k/6P1/4P3/8 b - - 0 1";*/
	/*8/5kpp/2K5/p5q1/6P1/5P2/8/2q5 w - - 0 53*/
	/*char p0[]="8/5kpp/2K5/p5q1/6P1/5P2/8/2q5 w - - 0 53";

	char p0[]="8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -";
	

		
	char p0[]="8/2p5/K2p4/1P5r/1R3p1k/8/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/1P5r/KR3p1k/8/4P1P1/8 b - - 0 1";//15----30


	char p0[]="8/2p5/3p4/KP5r/R4p1k/8/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/KP5r/5p1k/1R6/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/KP5r/5p1k/8/1R2P1P1/8 b - - 0 1";//16
	char p0[]="8/2p5/3p4/KP5r/5p1k/8/4P1P1/1R6 b - - 0 1";//16
	char p0[]="8/2p5/3p4/KP5r/2R2p1k/8/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/KP5r/3R1p1k/8/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/KP5r/4Rp1k/8/4P1P1/8 b - - 0 1";//15
	char p0[]="8/2p5/3p4/KP5r/5R1k/8/4P1P1/8 b - - 0 1";//2-----109

	char p0[]="8/2p5/3p4/KP5r/1R3p1k/4P3/6P1/8 b - - 0 1";//15 
	char p0[]="8/2p5/3p4/KP5r/1R2Pp1k/8/6P1/8 b - e3 0 1";//17----32 ERROR???

	char p0[]="8/2p5/3p4/KP5r/1R3p1k/6P1/4P3/8 b - - 0 1";//4
	char p0[]="8/2p5/3p4/KP5r/1R3pPk/8/4P3/8 b - g3 0 1";//18-----22
	*/
	init_board();
	/*set_position(p0);*/

	init_data();
	print_board();

	print_bitboard();
	start_time = time_elapsed();
	perf_t(dep);
	end_time = time_elapsed();
	_ui64toa(Nodes,num,10);
	time = ((end_time - start_time) / (float)1000);
	printf("\nmoves %s in %.3f sec.\n", num, time);
	}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
	int ch, ret;

	ret = 0;

	while ((ch = getopt(argc, argv, "tseES")) != -1) {
		switch (ch) {
		case 't':
			ret |= trivial();
			break;
		case 's':
			ret |= with_signal();
			break;
		case 'e':
			ret |= time_elapsed();
			break;
		case 'E':
			ret |= time_elapsed_with_signal();
			break;
		case 'S':
			ret |= short_time();
		default:
			fprintf(stderr, "Usage: nanosleep [-tse]\n");
			exit(1);
		}
	}

	return (ret);
}
Exemplo n.º 10
0
int livedrive_decode(struct ir_remote *remote, ir_code * prep, ir_code * codep, ir_code * postp, int *repeat_flagp,
		     lirc_t * min_remaining_gapp, lirc_t * max_remaining_gapp)
{
	lirc_t gap;

	if (!map_code(remote, prep, codep, postp, 16, pre, 16, code, 0, 0))
		return (0);

	gap = 0;
	if (start.tv_sec - last.tv_sec >= 2)
		*repeat_flagp = 0;
	else {
		gap = time_elapsed(&last, &start);

		if (gap < 300000)
			*repeat_flagp = 1;
		else
			*repeat_flagp = 0;
	}

	LOGPRINTF(1, "repeat_flag: %d", *repeat_flagp);
	LOGPRINTF(1, "gap: %lu", (__u32) gap);

	return (1);
}
Exemplo n.º 11
0
DECLARE_TEST( time, builtin )
{
	tick_t tick, newtick, tps;
	deltatime_t dt;

	tps = time_ticks_per_second();
	EXPECT_GT( tps, 0 );

	tick = time_current();
	thread_sleep( 20 );
	newtick = time_current();

	EXPECT_NE( tick, 0 );
	EXPECT_GT( newtick, tick );

	EXPECT_GT( time_diff( tick, newtick ), 0 );
	EXPECT_GT_MSGFORMAT( time_diff( tick, newtick ), ( tps / 100LL ), "time elapsed not more than 10ms: %lld (%lld)", time_diff( tick, newtick ), ( tps / 100LL ) ); //more than 10 ms
	EXPECT_LT_MSGFORMAT( time_diff( tick, newtick ), ( tps / 30LL  ), "time elapsed not less than 30ms: %lld (%lld)", time_diff( tick, newtick ), ( tps / 33LL  ) ); //less than 30 ms
	EXPECT_GT( time_elapsed( tick ), 0 );
	EXPECT_GT( time_elapsed( tick ), 0.01f ); //more than 10 ms
	EXPECT_GT( time_elapsed_ticks( tick ), 0 );
	EXPECT_GT( time_elapsed_ticks( tick ), ( tps / 100 ) ); //more than 10 ms

	dt = time_ticks_to_seconds( newtick - tick );
	EXPECT_GT( dt, 0 );
	EXPECT_GT_MSGFORMAT( dt, 0.01f, "time elapsed in seconds not more than 10ms: %.5f", dt ); //more than 10 ms
	EXPECT_LT_MSGFORMAT( dt, 0.03f, "time elapsed in seconds not less than 30ms: %.5f", dt ); //less than 30 ms

	tick = time_startup();
	EXPECT_GT( tick, 0 );
	EXPECT_LT( tick, newtick );
	EXPECT_EQ( tick, time_startup() );

	tick = time_system();
	EXPECT_GT( tick, 0 );

	thread_sleep( 100 );

	newtick = time_system();
	EXPECT_GT( newtick, 0 );
	EXPECT_GT( newtick, tick );
	EXPECT_GT( newtick - tick, 50 ); //more than 50 ms
	EXPECT_LT( newtick - tick, 200 ); //less than 200 ms

	return 0;
}
Exemplo n.º 12
0
/* Get time elapsed as a string. 
 * i.e 0:30 for 30 seconds 
 */
char *time_elapsed_string() {
    int time = time_elapsed();
    int seconds = time % 60;
    int minutes = (time / 60) % 60;
    char* str = (char *) malloc(5);
    sprintf(str, "%d:%02d", minutes, seconds);
    return str;
}
Exemplo n.º 13
0
/** Fire off all timed handlers that are ready.
 *  This function is called internally by the event loop.
 *
 *  @param ctx a Strophe context object
 *
 *  @return the time in milliseconds until the next handler will be ready
 */
uint64_t handler_fire_timed(xmpp_ctx_t * const ctx)
{
    xmpp_connlist_t *connitem;
    xmpp_handlist_t *handitem, *temp;
    int ret, fired;
    uint64_t elapsed, min;

    min = (uint64_t)(-1);

    connitem = ctx->connlist;
    while (connitem) {
	if (connitem->conn->state != XMPP_STATE_CONNECTED) {
	    connitem = connitem->next;
	    continue;
	}
	
	/* enable all handlers that were added */
	for (handitem = connitem->conn->timed_handlers; handitem;
	     handitem = handitem->next)
	    handitem->enabled = 1;

	handitem = connitem->conn->timed_handlers;
	while (handitem) {
	    /* skip newly added handlers */
	    if (!handitem->enabled) {
		handitem = handitem->next;
		continue;
	    }

	    /* only fire user handlers after authentication */
	    if (handitem->user_handler && !connitem->conn->authenticated) {
		handitem = handitem->next;
		continue;
	    }

	    fired = 0;
	    elapsed = time_elapsed(handitem->last_stamp, time_stamp());
	    if (elapsed >= handitem->period) {
		/* fire! */
		fired = 1;
		handitem->last_stamp = time_stamp();
		ret = ((xmpp_timed_handler)handitem->handler)(connitem->conn, handitem->userdata);
	    } else if (min > (handitem->period - elapsed))
		min = handitem->period - elapsed;
		
	    temp = handitem;
	    handitem = handitem->next;

	    /* delete handler if it returned false */
	    if (fired && !ret)
		xmpp_timed_handler_delete(connitem->conn, temp->handler);
	}

	connitem = connitem->next;
    }

    return min;
}
Exemplo n.º 14
0
/*Verifica le prestazioni del motore di generazione delle mosse
*/
void perf_gen() {
	char p[] = "r2qk2r/ppp2ppp/2np1n2/2b1p1B1/2B1P1b1/2NP1N2/PPP2PPP/R2QK2R w KQkq - 0 1";
	/*char p[]="rnbqkbnr/ppp2ppp/8/3pp3/3PP3/8/PPP2PPP/RNBQKBNR w KQkq ";
	char p[]="8/8/p1r5/6k1/KP6/8/8/5R2 b - - ";*/
	int i, moves, start_time, end_time;
	float time, speed;

	set_position(p);
	init_data();
	print_board();
	moves = 0;
	start_time = time_elapsed();

	for (i = 0;i <= 2000000;i++) {
			gen_all();
			moves += (tree.first_move[Ply + 1]);
			}

	end_time = time_elapsed();
	time = ((end_time - start_time) / (float)1000);
	speed = moves / time;
	printf("generated %d moves in %.3f sec.\n", moves, time);
	printf("move generator speed: %.3f mov/sec\n", speed);
	/*catture*/
	set_position(p);
	init_data();
	print_board();
	moves = 0;
	start_time = time_elapsed();

	for (i = 0;i <= 4000000;i++) {
			gen_all_captures();
			moves += (tree.first_move[Ply + 1]);
			}

	end_time = time_elapsed();
	time = ((end_time - start_time) / (float)1000);
	speed = moves / time;
	printf("generated %d captures in %.3f sec.\n", moves, time);
	printf("capture generator speed: %.3f mov/sec\n", speed);

	}
Exemplo n.º 15
0
static void uci_print_pv(Pos *pos, Depth depth, Value alpha, Value beta)
{
  TimePoint elapsed = time_elapsed() + 1;
  RootMoves *rm = pos->rootMoves;
  int pvIdx = pos->pvIdx;
  int multiPV = min(option_value(OPT_MULTI_PV), rm->size);
  uint64_t nodes_searched = threads_nodes_searched();
  uint64_t tbhits = threads_tb_hits();
  char buf[16];

  flockfile(stdout);
  for (int i = 0; i < multiPV; i++) {
    int updated = (i <= pvIdx && rm->move[i].score != -VALUE_INFINITE);

    if (depth == ONE_PLY && !updated)
        continue;

    Depth d = updated ? depth : depth - ONE_PLY;
    Value v = updated ? rm->move[i].score : rm->move[i].previousScore;

    int tb = TB_RootInTB && abs(v) < VALUE_MATE - MAX_MATE_PLY;
    if (tb)
      v = rm->move[i].tbScore;

    // An incomplete mate PV may be caused by cutoffs in qsearch() and
    // by TB cutoffs. We try to complete the mate PV if we may be in the
    // latter case.
    if (   abs(v) > VALUE_MATE - MAX_MATE_PLY
        && rm->move[i].pvSize < VALUE_MATE - abs(v)
        && TB_MaxCardinalityDTM > 0)
      TB_expand_mate(pos, &rm->move[i]);

    printf("info depth %d seldepth %d multipv %d score %s",
           d / ONE_PLY, rm->move[i].selDepth, i + 1,
           uci_value(buf, v));

    if (!tb && i == pvIdx)
      printf("%s", v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");

    printf(" nodes %"PRIu64" nps %"PRIu64, nodes_searched,
                              nodes_searched * 1000 / elapsed);

    if (elapsed > 1000)
      printf(" hashfull %d", tt_hashfull());

    printf(" tbhits %"PRIu64" time %"PRIi64" pv", tbhits, elapsed);

    for (int idx = 0; idx < rm->move[i].pvSize; idx++)
      printf(" %s", uci_move(buf, rm->move[i].pv[idx], is_chess960()));
    printf("\n");
  }
  fflush(stdout);
  funlockfile(stdout);
}
double loop_overhead() {
	__int64 iTotalTime = 0;
	for (int i = 0; i < NUM_TESTS; i++) {
		QueryPerformanceFrequency(&freq);
		QueryPerformanceCounter(&start_time_stamp);
		for (int j = 0; j <= 0; j++) {}
		QueryPerformanceCounter(&end_time_stamp);
		iTotalTime += time_elapsed();
	}
	double dTotalTime = static_cast<double>(iTotalTime);
	return dTotalTime / NUM_TESTS;
}
double measurement_overhead() {
	__int64 iTotalTime = 0;
	for (int i = 0; i < NUM_TESTS; i++) {
		QueryPerformanceFrequency(&freq);
		QueryPerformanceCounter(&start_time_stamp);
		// do nothing
		QueryPerformanceCounter(&end_time_stamp);
		iTotalTime += time_elapsed();
	}
	double dTotalTime = static_cast<double>(iTotalTime);
	return dTotalTime / NUM_TESTS;
}
Exemplo n.º 18
0
  virtual void do_update_ui() {
    const unsigned c_width = 60;

    if (total == 0)
      percent_done = 0;
    else
      percent_done = al_round(static_cast<double>(completed) * 100 / total);
    if (percent_done > 100)
      percent_done = 100;

    unsigned __int64 speed;
    if (time_elapsed() == 0)
      speed = 0;
    else
      speed = al_round(static_cast<double>(completed) / time_elapsed() * ticks_per_sec());

    wostringstream st;
    st << setw(7) << format_data_size(completed, get_size_suffixes()) << L" / " << format_data_size(total, get_size_suffixes()) << L" @ " << setw(9) << format_data_size(speed, get_speed_suffixes()) << L'\n';
    st << Far::get_progress_bar_str(c_width, percent_done, 100) << L'\n';
    progress_text = st.str();
  }
Exemplo n.º 19
0
/*######################## limit_transfer_rate() ########################*/
void
limit_transfer_rate(int bytes, off_t limit_rate, clock_t clktck)
{
   double delta_time,
          elapsed_time,
          expected;

   elapsed_time = time_elapsed(clktck);
   delta_time = elapsed_time - chunk_start;
   chunk_bytes += bytes;

   /* Calculate the time it should take to download at the given rate. */
   expected = 1000.0 * (double)chunk_bytes / (double)limit_rate;

   if (expected > delta_time)
   {
      double sleep_time;

      sleep_time = expected - delta_time + sleep_adjust;
      if (sleep_time >= (double)(2 * clktck))
      {
         double t0, t1;

         t0 = elapsed_time;
         (void)my_usleep((unsigned long)(1000 * sleep_time));
         t1 = time_elapsed(clktck);

         sleep_adjust = sleep_time - (t1 - t0);
         elapsed_time = t1;
      }
      else
      {
         return;
      }
   }
   chunk_bytes = 0;
   chunk_start = elapsed_time;

   return;
}
Exemplo n.º 20
0
static void check_time(void)
{
  TimePoint elapsed = time_elapsed();

  // An engine may not stop pondering until told so by the GUI
  if (Limits.ponder)
    return;

  if (   (use_time_management() && elapsed > time_maximum() - 10)
      || (Limits.movetime && elapsed >= Limits.movetime)
      || (Limits.nodes && threads_nodes_searched() >= Limits.nodes))
        Signals.stop = 1;
}
Exemplo n.º 21
0
static lirc_t get_next_rec_buffer_internal(lirc_t maxusec)
{
	if (rec_buffer.rptr < rec_buffer.wptr) {
		logprintf(3, "<%c%lu", rec_buffer.data[rec_buffer.rptr] & PULSE_BIT ? 'p' : 's', (__u32)
			  rec_buffer.data[rec_buffer.rptr] & (PULSE_MASK));
		rec_buffer.sum += rec_buffer.data[rec_buffer.rptr] & (PULSE_MASK);
		return (rec_buffer.data[rec_buffer.rptr++]);
	} else {
		if (rec_buffer.wptr < RBUF_SIZE) {
			lirc_t data = 0;
			unsigned long elapsed = 0;

			if (timerisset(&rec_buffer.last_signal_time)) {
				struct timeval current;

				gettimeofday(&current, NULL);
				elapsed = time_elapsed(&rec_buffer.last_signal_time, &current);
			}
			if (elapsed < maxusec) {
				data = hw.readdata(maxusec - elapsed);
			}
			if (!data) {
				logprintf(3, "timeout: %u", maxusec);
				return 0;
			}
			if (LIRC_IS_TIMEOUT(data)) {
				logprintf(1, "timeout received: %lu", (__u32) LIRC_VALUE(data));
				if (LIRC_VALUE(data) < maxusec) {
					return get_next_rec_buffer_internal(maxusec - LIRC_VALUE(data));
				}
				return 0;
			}

			rec_buffer.data[rec_buffer.wptr] = data;
			if (rec_buffer.data[rec_buffer.wptr] == 0)
				return (0);
			rec_buffer.sum += rec_buffer.data[rec_buffer.rptr]
			    & (PULSE_MASK);
			rec_buffer.wptr++;
			rec_buffer.rptr++;
			logprintf(3, "+%c%lu", rec_buffer.data[rec_buffer.rptr - 1] & PULSE_BIT ? 'p' : 's', (__u32)
				  rec_buffer.data[rec_buffer.rptr - 1]
				  & (PULSE_MASK));
			return (rec_buffer.data[rec_buffer.rptr - 1]);
		} else {
			rec_buffer.too_long = 1;
			return (0);
		}
	}
	return (0);
}
Exemplo n.º 22
0
/**************************************************************************
 * Receive a code (1 byte) from the remote.
 * This function is called by the LIRC daemon when I/O is pending
 * from a registered client, e.g. irw.
 *
 * return NULL if nothing have been received or a lirc code
 **************************************************************************/
char *mplay_rec(struct ir_remote *remotes)
{
	unsigned char rc_code;
	signed int len;
	struct timeval current_time;
	LOGPRINTF(1, "Entering mplay_rec()");
	len = read(hw.fd, &rc_code, 1);
	gettimeofday(&current_time, NULL);
	if (len != 1) {
		/* Something go wrong during the read, we close the device
		   for prevent endless looping when the device
		   is disconnected */
		LOGPRINTF(1, "Reading error in mplay_rec()");
		mplay_deinit();
		return NULL;
	} else {
		/* We have received a code */
		if (rc_code == MPLAY_REPEAT_CODE) {
			if (mplay_local_data.timeout_repetition_flag == 1) {
				/* We ignore the repetition */
				return NULL;
			} else {
				if (time_elapsed(&mplay_local_data.last_reception_time, &current_time) <=
				    MAX_TIME_BETWEEN_TWO_REPETITION_CODE) {
					/* This reception is a repeat */
					mplay_local_data.repeat_flag = 1;
					/* We save the reception time */
					mplay_local_data.last_reception_time = current_time;
				} else {
					/* To much time between repetition,
					   the receiver have  probably miss
					   a valide key code. We ignore the
					   repetition */
					mplay_local_data.timeout_repetition_flag = 1;
					mplay_local_data.repeat_flag = 0;
					return NULL;
				}
			}
		} else {
			/* This is a new code */
			mplay_local_data.rc_code = rc_code;
			mplay_local_data.repeat_flag = 0;
			mplay_local_data.timeout_repetition_flag = 0;
			mplay_local_data.last_reception_time = current_time;
		}
		LOGPRINTF(1, "code: %u", (unsigned int)mplay_local_data.rc_code);
		LOGPRINTF(1, "repeat_flag: %d", mplay_local_data.repeat_flag);
		return decode_all(remotes);
	}
}
Exemplo n.º 23
0
/*!
 * prints current average data transfer rate at no less than 30-second intervals
 */
static void
printDatarate(void)
{
    static float oldseconds = 0.0;
    static afs_uint64 oldxfered = 0;
    float seconds;

    gettimeofday(&now, &Timezone);
    seconds = time_elapsed(&opentime, &now);
    if ((seconds - oldseconds) > 30) {
	fprintf(stderr, "%llu MB transferred, present data rate = %.3f MB/sec.\n", xfered >> 20,	/* total bytes transferred, in MB */
		(xfered - oldxfered) / (seconds - oldseconds) / MEGABYTE_F);
	oldxfered = xfered;
	oldseconds = seconds;
    }
Exemplo n.º 24
0
static void
blast_client_report_progress(blast_client_t* client, bool force) {
	int progress = (int)((real)((float64_t)((client->seq - array_size(client->pending)) *
	                                        PACKET_CHUNK_SIZE) / (float64_t)client->readers[client->current]->size) * REAL_C(100.0));
	if (force || (progress > (client->last_progress_percent + 5)) ||
	        (time_elapsed(client->last_progress) > 1.0f)) {
		if (client->packets_sent > 0) {
			real resend_rate = (real)((float64_t)client->packets_resent / (float64_t)client->packets_sent) *
			                   REAL_C(100.0);
			log_infof(HASH_BLAST, STRING_CONST("Progress: %.*s %d%% (resend rate %.2" PRIreal "%% %lld/%lld))"),
			          STRING_FORMAT(client->readers[client->current]->name), progress, resend_rate,
			          client->packets_resent,
			          client->packets_sent);
		}
		client->last_progress = time_current();
		client->last_progress_percent = progress;
	}
}
Exemplo n.º 25
0
            virtual void test()
            {
                SET& rMap = m_Map   ;

                m_nInsertSuccess =
                    m_nInsertFailed =
                    m_nDeleteSuccess =
                    m_nDeleteFailed =
                    m_nFindSuccess =
                    m_nFindFailed = 0 ;

                actions * pAct = getTest().m_arrShuffle ;
                unsigned int i = 0 ;
                size_t const nNormalize = size_t(-1) / (c_nInitialMapSize * 2) ;

                size_t nRand = 0 ;
                while ( !time_elapsed() ) {
                    nRand = cds::bitop::RandXorShift(nRand) ;
                    size_t n = nRand / nNormalize ;
                    switch ( pAct[i] ) {
                    case do_find:
                        if ( rMap.find( n ))
                            ++m_nFindSuccess ;
                        else
                            ++m_nFindFailed ;
                        break;
                    case do_insert:
                        if ( rMap.insert( n ))
                            ++m_nInsertSuccess ;
                        else
                            ++m_nInsertFailed ;
                        break;
                    case do_delete:
                        if ( rMap.erase( n ))
                            ++m_nDeleteSuccess ;
                        else
                            ++m_nDeleteFailed ;
                        break;
                    }

                    if ( ++i >= c_nShuffleSize )
                        i = 0 ;
                }
            }
Exemplo n.º 26
0
void bbr_idle(U32 *tone_timestamp, bool *tone_active, ActuatorState behavior_actuations[], ActuatorState availableStates[])
{
	// if time elapsed
	if (  (time_elapsed(nx_systick_get_ms(),*tone_timestamp,idle_tone_interval)) == TRUE  )
	{
		*tone_timestamp=nx_systick_get_ms();	// update current timestamp

		// Toggle Tone Active status
		if (*tone_active==FALSE)
			*tone_active=TRUE;
		else
			*tone_active=FALSE;

		if (*tone_active==FALSE)
			copyActuatorState(BBR_IDLE, behavior_actuations, availableStates,BBR_IDLE_OFF);
		else
			copyActuatorState(BBR_IDLE, behavior_actuations, availableStates, BBR_IDLE_ON);
	}
}
Exemplo n.º 27
0
static char* rec(struct ir_remote* remotes)
{
	unsigned char rc_code;
	ssize_t size;
	struct timeval current;

	size = snd_hwdep_read(hwdep, &rc_code, 1);
	if (size < 1)
		return NULL;
	gettimeofday(&current, NULL);
	last_code = code;
	code = (ir_code)rc_code;
	/* delay for repeating buttons is up to 320 ms */
	repeat_flag = code == last_code && current.tv_sec - last_time.tv_sec <= 2
		      && time_elapsed(&last_time, &current) <= 350000;
	last_time = current;
	LOGPRINTF(1, "code: %llx", (__u64)code);
	LOGPRINTF(1, "repeat_flag: %d", repeat_flag);
	return decode_all(remotes);
}
Exemplo n.º 28
0
DBusMessage *
dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
  DBusPendingCall *pending;
  SpiReentrantCallClosure *closure;
  const char *unique_name = dbus_bus_get_unique_name (bus);
  const char *destination = dbus_message_get_destination (message);
  struct timeval tv;
  DBusMessage *ret;

  if (unique_name && destination &&
      strcmp (destination, unique_name) != 0)
    return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);

  closure = g_new0 (SpiReentrantCallClosure, 1);
  closure->reply = NULL;
  atspi_dbus_connection_setup_with_g_main(bus, NULL);
  if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
      return NULL;
  if (!pending)
    return NULL;
  dbus_pending_call_set_notify (pending, set_reply, (void *) closure, g_free);

  closure->reply = NULL;
  gettimeofday (&tv, NULL);
  dbus_pending_call_ref (pending);
  while (!closure->reply)
    {
      if (!dbus_connection_read_write_dispatch (bus, dbind_timeout) ||
          time_elapsed (&tv) > dbind_timeout)
        {
          dbus_pending_call_unref (pending);
          return NULL;
        }
    }
  
  ret = closure->reply;
  dbus_pending_call_unref (pending);
  return ret;
}
Exemplo n.º 29
0
  virtual void do_update_ui() {
    const unsigned c_width = 60;

    percent_done = calc_percent(completed, total);

    unsigned __int64 time = time_elapsed();
    unsigned __int64 speed;
    if (time == 0)
      speed = 0;
    else
      speed = al_round(static_cast<double>(completed) / time * ticks_per_sec());

    unsigned __int64 total_time;
    if (completed)
      total_time = static_cast<unsigned __int64>(static_cast<double>(total) / completed * time);
    else
      total_time = 0;
    if (total_time < time)
      total_time = time;

    wostringstream st;
    st << fit_str(arc_path, c_width) << L'\n';
    st << L"\x1\n";
    st << fit_str(file_path, c_width) << L'\n';
    st << setw(7) << format_data_size(file_completed, get_size_suffixes()) << L" / " <<
      format_data_size(file_total, get_size_suffixes()) << L'\n';
    st << Far::get_progress_bar_str(c_width, calc_percent(file_completed, file_total), 100) << L'\n';
    st << L"\x1\n";
    st << setw(7) << format_data_size(completed, get_size_suffixes()) << L" / " <<
      format_data_size(total, get_size_suffixes()) << L" @ " << setw(9) <<
      format_data_size(speed, get_speed_suffixes()) << L" -" << format_time((total_time - time) / ticks_per_sec()) << L'\n';
    st << setw(7) << format_data_size(total_data_read, get_size_suffixes()) << L" \x2192 " <<
      setw(7) << format_data_size(total_data_written, get_size_suffixes()) << L" = " <<
      setw(2) << calc_percent(total_data_written, total_data_read) << L"%" << L'\n';
    st << Far::get_progress_bar_str(c_width, percent_done, 100) << L'\n';
    progress_text = st.str();
  }
Exemplo n.º 30
0
int livedrive_decode(struct ir_remote* remote, struct decode_ctx_t* ctx)
{
	lirc_t gap;

	if (!map_code(remote, ctx, 16, pre, 16, code, 0, 0))
		return 0;

	gap = 0;
	if (start.tv_sec - last.tv_sec >= 2) {
		ctx->repeat_flag = 0;
	} else {
		gap = time_elapsed(&last, &start);

		if (gap < 300000)
			ctx->repeat_flag = 1;
		else
			ctx->repeat_flag = 0;
	}

	LOGPRINTF(1, "repeat_flag: %d", ctx->repeat_flag);
	LOGPRINTF(1, "gap: %lu", (__u32)gap);

	return 1;
}