Exemplo n.º 1
0
/*
 * Format: OPER, FD, POS, SIZE, T1, T2, [PATH]
 */
void IOSIG_posix_write_log (const char * operation, int fildes, off64_t position, 
        size_t size, struct timeval * start, struct timeval * end, 
        const char * path) {
    //return;
    struct timeval diffstart, diffend;
    timeval_diff(&diffstart, start, &bigbang);
    timeval_diff(&diffend, end, &bigbang);
    /* Format: OPEN, file_path, position, size, time1, time2 */

    //pthread_mutex_lock(&posix_fp_mutex);
    if (path) {
        sprintf(posix_logtext, "%-10s %3d %6ld %6ld %4ld.%06ld %4ld.%06ld %s\n", 
                operation, fildes, position, size,
                (long) diffstart.tv_sec, (long) diffstart.tv_usec, 
                (long) diffend.tv_sec, (long) diffend.tv_usec, path);
        __real_fwrite(posix_logtext, strlen(posix_logtext), 1, posix_fp);
    } else {
        sprintf(posix_logtext, "%-10s %3d %6ld %6ld %4ld.%06ld %4ld.%06ld -\n", 
                operation, fildes, position, size,
                (long) diffstart.tv_sec, (long) diffstart.tv_usec, 
                (long)diffend.tv_sec, (long) diffend.tv_usec);
        __real_fwrite(posix_logtext, strlen(posix_logtext), 1, posix_fp);
    }
    //pthread_mutex_unlock(&posix_fp_mutex);
}
Exemplo n.º 2
0
void hello_send(void *arg)
{
	RREP *rrep;
	u8_t flags = 0;
	struct in_addr dest;
	struct timeval now;
	long time_diff;
	
	gettimeofday(&now, NULL);

	if(timeval_diff(&now, &this_host.last_forward_time) > ACTIVE_ROUTE_TIMEOUT)
	{
		hello_stop();
		return;
	}

	time_diff = timeval_diff(&now, &this_host.last_broadcast_time);

	if(time_diff >= HELLO_INTERVAL)
	{
		rrep = rrep_create(flags, 0, 0, this_host.dev.ipaddr, this_host.seqno, this_host.dev.ipaddr, ALLOWED_HELLO_LOSS * HELLO_INTERVAL);

	/////////No ext	
	
		dest.s_addr = AODV_BROADCAST;
		aodv_socket_send((AODV_msg *)rrep, dest, RREP_SIZE, 1, &this_host.dev);

		timer_set_timeout(&hello_timer, HELLO_INTERVAL);
	}
	else
	{
		timer_set_timeout(&hello_timer, HELLO_INTERVAL - time_diff);
	}
}
Exemplo n.º 3
0
/*
 *	print_times -- Print absolute and delta time for debugging
 *
 *	Inputs:
 *
 *	None.
 *
 *	Returns:
 *
 *	None.
 *
 *	This function is only used for debugging.  It should not be called
 *	from production code.
 */
void
print_times(void) {
   static struct timeval time_first;    /* When print_times() was first called */
   static struct timeval time_last;     /* When print_times() was last called */
   static int first_call=1;
   struct timeval time_now;
   struct timeval time_delta1;
   struct timeval time_delta2;

   Gettimeofday(&time_now);

   if (first_call) {
      first_call=0;
      time_first.tv_sec  = time_now.tv_sec;
      time_first.tv_usec = time_now.tv_usec;
      printf("%lu.%.6lu (0.000000) [0.000000]\n",
             (unsigned long)time_now.tv_sec, (unsigned long)time_now.tv_usec);
   } else {
      timeval_diff(&time_now, &time_last, &time_delta1);
      timeval_diff(&time_now, &time_first, &time_delta2);
      printf("%lu.%.6lu (%lu.%.6lu) [%lu.%.6lu]\n",
             (unsigned long)time_now.tv_sec,
             (unsigned long)time_now.tv_usec,
             (unsigned long)time_delta1.tv_sec,
             (unsigned long)time_delta1.tv_usec,
             (unsigned long)time_delta2.tv_sec,
             (unsigned long)time_delta2.tv_usec);
   }
   time_last.tv_sec  = time_now.tv_sec;
   time_last.tv_usec = time_now.tv_usec;
}
pslr_handle_t camera_connect( char *model, char *device, int timeout, char *error_message ) {
    struct timeval prev_time;
    struct timeval current_time;
    pslr_handle_t camhandle;
    int r;

    gettimeofday(&prev_time, NULL);
    while (!(camhandle = pslr_init( model, device ))) {
        gettimeofday(&current_time, NULL);
        DPRINT("diff: %f\n", timeval_diff(&current_time, &prev_time) / 1000000.0);
        if( timeout == 0 || timeout > timeval_diff(&current_time, &prev_time) / 1000000.0 ) {
          DPRINT("sleep 1 sec\n");
          sleep_sec(1);
        } else {
          snprintf(error_message, 1000, "%d %ds timeout exceeded\n", 1, timeout);
          return NULL;
        }
    }

    DPRINT("before connect\n");
    if (camhandle) {
      if ((r=pslr_connect(camhandle)) ) {
          if( r != -1 ) {
            snprintf(error_message, 1000, "%d Cannot connect to Pentax camera. Please start the program as root.\n",1);
          } else {
            snprintf(error_message, 1000, "%d Unknown Pentax camera found.\n",1);
          }
          return NULL;
        }
    }
    return camhandle;
}
Exemplo n.º 5
0
void OTExtensionWithMatrix::transfer(int nOTs,
        const BitVector& receiverInput)
{
#ifdef OTEXT_TIMER
    timeval totalstartv, totalendv;
    gettimeofday(&totalstartv, NULL);
#endif
    cout << "\tDoing " << nOTs << " extended OTs as " << role_to_str(ot_role) << endl;

    // resize to account for extra k OTs that are discarded
    BitVector newReceiverInput(nOTs);
    for (unsigned int i = 0; i < receiverInput.size_bytes(); i++)
    {
        newReceiverInput.set_byte(i, receiverInput.get_byte(i));
    }

    for (int loop = 0; loop < nloops; loop++)
    {
        extend<gf2n>(nOTs, newReceiverInput);
#ifdef OTEXT_TIMER
        gettimeofday(&totalendv, NULL);
        double elapsed = timeval_diff(&totalstartv, &totalendv);
        cout << "\t\tTotal thread time: " << elapsed/1000000 << endl << flush;
#endif
    }

#ifdef OTEXT_TIMER
    gettimeofday(&totalendv, NULL);
    times["Total thread"] +=  timeval_diff(&totalstartv, &totalendv);
#endif
}
Exemplo n.º 6
0
Arquivo: stats.c Projeto: DonCN/haiku
/*
 * Called by main thread only (in fact in tftpd_receive_request(), but
 * before stdin_mutex is released) every time a new thread is created.
 * We record the number of thread, the number of simultaeous thread, the
 * between threads.
 */
void stats_new_thread(int number_of_thread)
{
     struct timeval tmp;

     if (number_of_thread > s_stats.max_simul_threads)
          s_stats.max_simul_threads = number_of_thread;

     /* calculate the arrival time of this thread */
     if (s_stats.prev_time.tv_sec != 0)
     {
          gettimeofday(&s_stats.curr_time, NULL);
          timeval_diff(&s_stats.diff_time, &s_stats.curr_time,
                       &s_stats.prev_time);
          if (timeval_diff(&tmp, &s_stats.diff_time,
                           &s_stats.min_time) < 0)
               memcpy(&s_stats.min_time, &s_stats.diff_time,
                      sizeof(struct timeval));
          if (timeval_diff(&tmp, &s_stats.diff_time,
                           &s_stats.max_time) > 0)
               memcpy(&s_stats.max_time, &s_stats.diff_time,
                      sizeof(struct timeval));
          memcpy(&s_stats.prev_time, &s_stats.curr_time,
                 sizeof(struct timeval));
     }
     else
          gettimeofday(&s_stats.prev_time, NULL);
}
Exemplo n.º 7
0
void OTExtensionWithMatrix::hash_outputs(int nOTs)
{
    //cout << "Hashing... " << flush;
    octetStream os, h_os(HASH_SIZE);
    square128 tmp;
    MMO mmo;
#ifdef OTEXT_TIMER
    timeval startv, endv;
    gettimeofday(&startv, NULL);
#endif

    for (int i = 0; i < nOTs / 128; i++)
    {
        if (ot_role & SENDER)
        {
            tmp = senderOutputMatrices[0].squares[i];
            tmp ^= baseReceiverInput;
            senderOutputMatrices[0].squares[i].hash_row_wise<T>(mmo, senderOutputMatrices[0].squares[i]);
            senderOutputMatrices[1].squares[i].hash_row_wise<T>(mmo, tmp);
        }
        if (ot_role & RECEIVER)
        {
            receiverOutputMatrix.squares[i].hash_row_wise<T>(mmo, receiverOutputMatrix.squares[i]);
        }
    }
    //cout << "done.\n";
#ifdef OTEXT_TIMER
    gettimeofday(&endv, NULL);
    double elapsed = timeval_diff(&startv, &endv);
    cout << "\t\tOT ext hashing took time " << elapsed/1000000 << endl << flush;
    times["Hashing"] += timeval_diff(&startv, &endv);
#endif
}
Exemplo n.º 8
0
void OTExtensionWithMatrix::transpose(int start, int slice)
{
    BitMatrixSlice receiverOutputSlice(receiverOutputMatrix, start, slice);
    BitMatrixSlice senderOutputSlices[2] = {
            BitMatrixSlice(senderOutputMatrices[0], start, slice),
            BitMatrixSlice(senderOutputMatrices[1], start, slice)
    };

    // transpose t0[i] onto receiverOutput and tmp (q[i]) onto senderOutput[i][0]

    //cout << "Starting matrix transpose\n" << flush << endl;
#ifdef OTEXT_TIMER
    timeval transt1, transt2;
    gettimeofday(&transt1, NULL);
#endif
    // transpose in 128-bit chunks
    if (ot_role & RECEIVER)
        receiverOutputSlice.transpose();
    if (ot_role & SENDER)
        senderOutputSlices[0].transpose();

#ifdef OTEXT_TIMER
    gettimeofday(&transt2, NULL);
    double transtime = timeval_diff(&transt1, &transt2);
    cout << "\t\tMatrix transpose took time " << transtime/1000000 << endl << flush;
    times["Matrix transpose"] += timeval_diff(&transt1, &transt2);
#endif
}
Exemplo n.º 9
0
static bool
check_read_stop()
{
    uint64_t diff, history_diff, cur_diff;

    history_diff = timeval_diff(&first_pack_time, &last_pack_time);
    cur_diff     = timeval_diff(&base_time, &cur_time);

    if (clt_settings.accelerated_times > 1) {
        cur_diff = cur_diff * clt_settings.accelerated_times;
    }

    if (clt_settings.interval > 0) {
        if (adj_v_pack_diff > 0 && adj_v_pack_diff > clt_settings.interval) {
            accumulated_diff += adj_v_pack_diff;
            tc_log_info(LOG_NOTICE, 0, "accumulated time saved:%llu",
                    accumulated_diff);
        }
        cur_diff = cur_diff + accumulated_diff;
    }


    if (history_diff <= cur_diff) {
        return false;
    }

    diff = history_diff - cur_diff;
    if (diff > 0) {
        return true;
    }

    return false;
}
Exemplo n.º 10
0
static void 
print_diff (struct mi_timestamp *start, struct mi_timestamp *end)
  {
    fprintf_unfiltered
      (raw_stdout,
       ",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}", 
       timeval_diff (start->wallclock, end->wallclock) / 1000000.0, 
       timeval_diff (start->utime, end->utime) / 1000000.0, 
       timeval_diff (start->stime, end->stime) / 1000000.0);
  }
Exemplo n.º 11
0
static void reciver_looper(void)
{
    if (shut_down_flag)
    {
        int i;
        for (i = 0; i < settings.hash_table_num; ++i)
        {
            flush_table(&settings.tables[i]);
        }

        log_vip("reciver, shut down...");

        exit(0);
    }

    struct timeval now;
    gettimeofday(&now, NULL);

    dlog_check(NULL, &now);

    static time_t last_log_min;
    time_t curr_min = now.tv_sec / 60;
    if (curr_min != last_log_min)
    {
        if (last_log_min != 0)
        {
            log_info("reciver: recv pkg: %d, succ: %d, fail: %d", \
                    recv_pkg_count, process_pkg_succ_count, process_pkg_fail_count);

            recv_pkg_count = 0;
            process_pkg_succ_count = 0;
            process_pkg_fail_count = 0;
        }

        last_log_min = curr_min;
    }

    static struct timeval last_check;
    if (settings.cache_time_in_ms && ((timeval_diff(&last_check, &now) / 1000) > (uint64_t)settings.check_time_in_ms))
    {
        int i;
        for (i = 0; i < settings.hash_table_num; ++i)
        {
            if (settings.tables[i].buf_use &&
                    (timeval_diff(&settings.tables[i].start, &now) / 1000) > (uint64_t)settings.cache_time_in_ms)
            {
                flush_table(&settings.tables[i]);
            }
        }

        last_check = now;
    }

    return;
}
Exemplo n.º 12
0
void mem_calibrate(void)
{
    int i, p;
// Limits for interval_rand()
    int lr = 0, hr = 100;
// No of loops to calibrate with.
    int calib_length = MEM_CALIBRATION_LOOPS;
// Working set size used for calibration.
    int calib_wss = MEM_CALIBRATION_WSS;
    long long start_usec, end_usec;
// No of loops needed to achieve loop_length
    long long calib_loops;

    /*
     * Initialize the memness_array. This is done in such a way that each structure
     * points to the next one in the array, which is chosen at random. Care is
     * taken to ensure that there are no loops created with these pointers.
     */
    for (i = 0; i < MEMNESS_INT_ARRAY_SIZE; i++) {
        memness_array[i].num = interval_rand(lr, hr);
        memness_array[i].touched = 1;
        memness_array[i].next = NULL;
    }
    randomize_array(memness_array, MEMNESS_INT_ARRAY_SIZE);

    if (!WILEE_CALIBRATE)
        return;
    /*
     * Calibrate by checking how long it takes to run calib_length number of
     * loops on a calib_wss sized working set.
     */

    gettimeofday(&pr, NULL);
    mem_inner_loop(calib_length, calib_wss, p);
    gettimeofday(&ne, NULL);
    time_per_memness_iteration = (float)(timeval_diff(&pr, &ne))
                                 / (float)calib_length;
    calib_loops = loop_length / time_per_memness_iteration;
//	calib_loops = 0;

    gettimeofday(&pr, NULL);
    mem_inner_loop(calib_loops, calib_wss, p);
    gettimeofday(&ne, NULL);

    printf("------------------\n");
    printf("Memory Calibration\n");
    printf("------------------\n");
    printf("Working set size used: %d\n", calib_wss);
    printf("Time per iteration: %f\n", time_per_memness_iteration);
    printf("Number of loops for 100%% Memory-ness: %lld\n", calib_loops);
    printf("Time for above loops: %ld\n", timeval_diff(&pr, &ne));
}
Exemplo n.º 13
0
void OTExtensionWithMatrix::extend_correlated(int nOTs_requested, BitVector& newReceiverInput)
{
//    if (nOTs % nbaseOTs != 0)
//        throw invalid_length(); //"nOTs must be a multiple of nbaseOTs\n");
    if (nOTs_requested == 0)
        return;
    nOTs_requested = DIV_CEIL(nOTs_requested, 128) * 128;
    // add k + s to account for discarding k OTs
    int nOTs = nOTs_requested + 2 * 128;

    int slice = nOTs / nsubloops / 128;
    nOTs = slice * nsubloops * 128;
    resize(nOTs);
    newReceiverInput.resize(nOTs);

    // randomize last 128 + 128 bits that will be discarded
    for (int i = 0; i < 4; i++)
        newReceiverInput.set_word(nOTs/64 - i - 1, G.get_word());

    // subloop for first part to interleave communication with computation
    for (int start = 0; start < nOTs / 128; start += slice)
    {
        expand<gf2n>(start, slice);
        correlate<gf2n>(start, slice, newReceiverInput, true);
        transpose(start, slice);
    }

#ifdef OTEXT_TIMER
    double elapsed;
#endif
    // correlation check
    if (!passive_only)
    {
#ifdef OTEXT_TIMER
        timeval startv, endv;
        gettimeofday(&startv, NULL);
#endif
        check_correlation(nOTs, newReceiverInput);
#ifdef OTEXT_TIMER
        gettimeofday(&endv, NULL);
        elapsed = timeval_diff(&startv, &endv);
        cout << "\t\tTotal correlation check time: " << elapsed/1000000 << endl << flush;
        times["Total correlation check"] += timeval_diff(&startv, &endv);
#endif
    }

    receiverOutputMatrix.resize(nOTs_requested);
    senderOutputMatrices[0].resize(nOTs_requested);
    senderOutputMatrices[1].resize(nOTs_requested);
    newReceiverInput.resize(nOTs_requested);
}
Exemplo n.º 14
0
Arquivo: main.c Projeto: adamsch1/ff
int main () {
    char * request_uri;

    /* Load the controller .so from this sub directory */
    route_import_controllers("controllers/");

    /* Initialize session system */
    session_init();

    while (FCGI_Accept() >= 0) {
      /* Record start time */
      gettimeofday(&start_time,NULL);

      request_uri = cleanrequest( getenv("REQUEST_URI"));

      /* Initialize session for this request */
      fprintf(stderr, "Request for %s\n", request_uri );

      /* Dispatch the request to the correct controller */
      route_dispatch(request_uri);
      free(request_uri);
     
      /* Calculate total runtime of the operation */
      gettimeofday(&end_time,NULL);
      timeval_diff( &difference_time, &end_time, &start_time );      

      printf("time: %ld.%06ld\n", difference_time.tv_sec, difference_time.tv_usec);

      FCGI_Finish();
    }

    fprintf(stderr, "FF Exiting\n");
    return 0;
}
Exemplo n.º 15
0
/* This is called when we stop receiveing hello messages from a
   node. For now this is basically the same as a route timeout. */
void NS_CLASS hello_timeout(void *arg)
{
    rt_table_t *rt;
    struct timeval now;

    rt = (rt_table_t *) arg;

    if (!rt)
        return;

    gettimeofday(&now, NULL);

    DEBUG(LOG_DEBUG, 0, "LINK/HELLO FAILURE %s last HELLO: %d",
          ip_to_str(rt->dest_addr), timeval_diff(&now, &rt->last_hello_time));

    if (rt && rt->state == VALID && !(rt->flags & RT_UNIDIR)) {

        /* If the we can repair the route, then mark it to be
           repaired.. */
        if (local_repair && rt->hcnt <= MAX_REPAIR_TTL) {
            rt->flags |= RT_REPAIR;
            DEBUG(LOG_DEBUG, 0, "Marking %s for REPAIR",
                  ip_to_str(rt->dest_addr));
#ifdef NS_PORT
            /* Buffer pending packets from interface queue */
            interfaceQueue((nsaddr_t) rt->dest_addr.s_addr, IFQ_BUFFER);
#endif
        }
        neighbor_link_break(rt);
    }
}
/*
 *    Time since a timeval
 */
static int
time_since(const struct timeval *when)
{
    struct timeval now;
    gettimeofday(&now, NULL);
    return timeval_diff(when, &now);
}
Exemplo n.º 17
0
static void __agent_schedule_abs(struct ice_agent *ag, const struct timeval *tv) {
	struct timeval nxt;
	long long diff;

	if (!ag) {
		ilog(LOG_ERR, "ice ag is NULL");
		return;
	}

	nxt = *tv;

	mutex_lock(&ice_agents_timers_lock);
	if (ag->last_run.tv_sec) {
		/* make sure we don't run more often than we should */
		diff = timeval_diff(&nxt, &ag->last_run);
		if (diff < TIMER_RUN_INTERVAL * 1000)
			timeval_add_usec(&nxt, TIMER_RUN_INTERVAL * 1000 - diff);
	}
	if (ag->next_check.tv_sec && timeval_cmp(&ag->next_check, &nxt) <= 0)
		goto nope; /* already scheduled sooner */
	if (!g_tree_remove(ice_agents_timers, ag))
		obj_hold(ag); /* if it wasn't removed, we make a new reference */
	ag->next_check = nxt;
	g_tree_insert(ice_agents_timers, ag, ag);
	cond_broadcast(&ice_agents_timers_cond);
nope:
	mutex_unlock(&ice_agents_timers_lock);
}
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
  struct timeval tvStart, tvEnd;
  int err;
  int num; // number of operations for compute
  if(argc!=2)
    exit(EXIT_FAILURE);
  else
    num=atoi(argv[1]);

  err=gettimeofday(&tvStart, NULL);
  if(err!=0)
    exit(EXIT_FAILURE);

  // long computation
  compute(num);

  err=gettimeofday(&tvEnd, NULL);
  if(err!=0)
    exit(EXIT_FAILURE);

  printf("Duration : %ld microseconds\n", timeval_diff(&tvEnd, &tvStart));

  return(EXIT_SUCCESS);
}
Exemplo n.º 19
0
Arquivo: stats.c Projeto: DonCN/haiku
/*
 * Called at the end of the main thread, when no other threads are
 * running, to print the final statistics.
 */
void stats_print(void)
{
     struct timeval tmp;

     timeval_diff(&tmp, &s_stats.end_time, &s_stats.start_time);
     times(&s_stats.tms);
     s_stats.tms.tms_utime += s_stats.tms_thread.tms_utime;
     s_stats.tms.tms_stime += s_stats.tms_thread.tms_stime;

     logger(LOG_INFO, "  Load measurements:");
     logger(LOG_INFO, "   User: %8.3fs  Sys:%8.3fs",
            (double)(s_stats.tms.tms_utime) / CLK_TCK,
            (double)(s_stats.tms.tms_stime) / CLK_TCK);
     logger(LOG_INFO, "   Total:%8.3fs  CPU:%8.3f%%", 
            (double)(tmp.tv_sec + tmp.tv_usec * 1e-6),
            (double)(s_stats.tms.tms_utime + s_stats.tms.tms_stime) /
            (double)(tmp.tv_sec + tmp.tv_usec * 1e-6));
     logger(LOG_INFO, "  Time between connections:");
     if (s_stats.min_time.tv_sec == LONG_MAX)
          logger(LOG_INFO, "   Min: -----   Max: -----");
     else
          logger(LOG_INFO, "   Min: %.3fs Max: %.3fs",
                 (double)(s_stats.min_time.tv_sec + s_stats.min_time.tv_usec * 1e-6),
                 (double)(s_stats.max_time.tv_sec + s_stats.max_time.tv_usec * 1e-6));
     logger(LOG_INFO, "  Thread stats:");
     logger(LOG_INFO, "   simultaneous threads:     %d", s_stats.max_simul_threads);
     logger(LOG_INFO, "   number of servers:        %d", s_stats.number_of_server);
     logger(LOG_INFO, "   number of aborts:         %d", s_stats.number_of_abort);
     logger(LOG_INFO, "   number of errors:         %d", s_stats.number_of_err);
     logger(LOG_INFO, "   number of files sent:     %d", s_stats.num_file_send);
     logger(LOG_INFO, "   number of files received: %d", s_stats.num_file_recv);
}
Exemplo n.º 20
0
void timer_cb(mrp_timer_t *timer, void *user_data)
{
    test_timer_t   *t = (test_timer_t *)user_data;
    struct timeval  now;
    double          diff, error;

    MRP_UNUSED(timer);

    timeval_now(&now);
    diff  = timeval_diff(&now, &t->prev) / 1000.0;
    error = diff - t->interval;
    if (error < 0.0)
        error = -error;

    info("MRPH timer #%d: %d/%d, diff %.2f (lag %.2f, %.3f %%)",
         t->id, t->count, t->target, diff, error, 100 * error / diff);

    t->count++;
    t->prev = now;

    if (t->count >= t->target) {
        info("MRPH timer #%d has finished.", t->id);

        mrp_del_timer(t->timer);
        t->timer = NULL;
        cfg.nrunning--;
    }
}
Exemplo n.º 21
0
static void
progress_cb (guestfs_h *g, void *vp, uint64_t event,
             int eh, int flags,
             const char *buf, size_t buflen,
             const uint64_t *array, size_t arraylen)
{
  uint64_t transferred;
  struct timeval now;
  int64_t millis;

  assert (event == GUESTFS_EVENT_PROGRESS);
  assert (arraylen >= 4);

  gettimeofday (&now, NULL);

  /* Bytes transferred. */
  transferred = array[2];

  /* Calculate the speed of the upload or download. */
  millis = timeval_diff (&start, &now);
  assert (millis >= 0);

  if (millis != 0) {
    rate = 1000 * transferred / millis;
    printf ("%s: %" PRIi64 " bytes/sec          \r",
            operation, rate);
    fflush (stdout);
  }
}
Exemplo n.º 22
0
//kernel code identification
int kdi(unsigned startVirtualAddr, Mem * mem, int pageSize,
        unsigned cr3Pages[], int *kdi_time, int *allPages)
{
    struct timeval earlier;
    struct timeval later;
    if (gettimeofday(&earlier, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    //generate step 1 clusters
    unsigned cluster_index =
        getClusters(startVirtualAddr, mem, pageSize, allPages);
    
    print_clusters(cluster_index);

    findKernelCodePageByCr3(startVirtualAddr, mem, pageSize, cr3Pages);

    if (gettimeofday(&later, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    (*kdi_time) = timeval_diff(NULL, &later, &earlier) / 1000;
    printf
        ("step1,all pages: %d, cluster: %d,kdi time cost is %d milliseconds\n",
         *allPages, cluster_index, (*kdi_time));
    return cluster_index;
}
void end(struct timeval *timer)
{
	struct timeval tend, tdiff;
	gettimeofday(&tend, NULL);
	timeval_diff(&tdiff, timer, &tend);
	printf("Elapsed Time = %ld.%06ld(s)\n",tdiff.tv_sec, tdiff.tv_usec);
}
Exemplo n.º 24
0
static gboolean glib_timer_cb(gpointer user_data)
{
    glib_timer_t   *t = (glib_timer_t *)user_data;
    struct timeval  now;
    double          diff, error;

    timeval_now(&now);
    diff  = timeval_diff(&now, &t->prev) / 1000.0;
    error = diff - t->interval;
    if (error < 0.0)
        error = -error;

    info("GLIB timer #%d: %d/%d, diff %.2f (lag %.2f, %.3f %%)",
         t->id, t->count, t->target, diff, error, 100 * error / diff);

    t->count++;
    t->prev = now;

    if (t->count >= t->target) {
        info("GLIB timer #%d has finished.", t->id);

        t->gsrc = 0;
        cfg.nrunning--;
        return FALSE;
    }
    else
        return TRUE;
}
Exemplo n.º 25
0
static void wakeup_cb(mrp_wakeup_t *w, mrp_wakeup_event_t event,
                      void *user_data)
{
    static struct timeval  prev[2] = { {0, 0}, {0, 0} };
    const char            *evt;
    struct timeval         now;
    double                 diff;
    int                    id;

    MRP_UNUSED(w);
    MRP_UNUSED(user_data);

    timeval_now(&now);

    switch (event) {
    case MRP_WAKEUP_EVENT_TIMER: evt = "timer";           break;
    case MRP_WAKEUP_EVENT_IO:    evt = "I/O (or signal)"; break;
    case MRP_WAKEUP_EVENT_LIMIT: evt = "limit";           break;
    default:                     evt = "???";
    }

    id = user_data ? 1 : 0;

    if (MRP_LIKELY(prev[id].tv_usec != 0)) {
        diff = timeval_diff(&now, &prev[id]) / 1000.0;
        info("woken up #%d by %s, %.2f msecs since previous", id, evt, diff);
    }

    prev[id] = now;
}
Exemplo n.º 26
0
int main(int argc, char *argv[]) {
  
  int *vector;
  long mesures[LOOP], sum;

  struct timeval tvStart, tvEnd; 
  int err;

  vector=(int *)malloc(SIZE*sizeof(int));
  free(vector);

  for(int i=0;i<LOOP+1;i++) {
    err=gettimeofday(&tvStart, NULL);
    if(err!=0)
      exit(EXIT_FAILURE);
    
     vector=(int *)calloc(SIZE,sizeof(int));
     //vector=(int *)malloc(SIZE*sizeof(int));
    err=gettimeofday(&tvEnd, NULL);
    if(err!=0)
      exit(EXIT_FAILURE);
    
    mesures[i]=timeval_diff(&tvEnd, &tvStart);
    sum+=mesures[i];
    free(vector);
  }
  printf("Durée moyenne : %ld \n",sum/LOOP);

  return(EXIT_SUCCESS);
}
Exemplo n.º 27
0
//signatures match
void sigMatch(range range, Mem *mem, int pageSize, int dsmPages[], int *match_time) {
	int i;
	struct timeval earlier;
	struct timeval later;
	//begin match
	int osNumber = initDb();
	extern fingerprint fingerprints[FINGERPRINT_NO];
	if (gettimeofday(&earlier, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}
	int availableOs[FINGERPRINT_NO], matchCounts[FINGERPRINT_NO];
	for (i = 0; i < FINGERPRINT_NO; i++) {
		availableOs[i] = 1;
		matchCounts[i] = 0;
	}
	unsigned startVirtualAddr = range.start;
	for (; startVirtualAddr <= range.end; startVirtualAddr += 0x1000) {
		unsigned pAddr = vtop(mem->mem, mem->mem_size, mem->pgd, startVirtualAddr);
		if (pAddr == -1 || pAddr > mem->mem_size)
			continue;

		int pageIndex = pAddr / pageSize;
		if (dsmPages[pageIndex] == 1) {
			int offset = (startVirtualAddr - range.start) / 4096;
			void *startAdress = (void*) ((unsigned) mem->mem + pageIndex * pageSize);
			unsigned char md5digest[16];
			MDMem(startAdress, pageSize, md5digest);
			//	printf("%x ", vaddr); //print vaddr
			MDPrint(md5digest);
			printf("\n");
			int ret = matchByIndex(osNumber, md5digest, offset, availableOs, matchCounts);
			//			if(ret ==1)
		}
	}

	int maxIndex = -1;
	int maxMatch = 0;
	for (i = 0; i < FINGERPRINT_NO; i++) {
		if (matchCounts[i] > maxMatch) {
			maxIndex = i;
			maxMatch = matchCounts[i];
		}
	}
	if (maxMatch > 0)
		printf("Os is %s, match count is %d\n", fingerprints[maxIndex].osVersion, maxMatch);

	else
		puts("Unknown OS!");

	if (gettimeofday(&later, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}

	*match_time = timeval_diff(NULL, &later, &earlier) / 1000;
	printf("match time cost is %d milliseconds\n", *match_time);
}
Exemplo n.º 28
0
void OTExtensionWithMatrix::correlate(int start, int slice,
        BitVector& newReceiverInput, bool useConstantBase, int repeat)
{
    vector<octetStream> os(2);

    BitMatrixSlice receiverOutputSlice(receiverOutputMatrix, start, slice);
    BitMatrixSlice senderOutputSlices[2] = {
            BitMatrixSlice(senderOutputMatrices[0], start, slice),
            BitMatrixSlice(senderOutputMatrices[1], start, slice)
    };
    BitMatrixSlice t1Slice(t1, start, slice);
    BitMatrixSlice uSlice(u, start, slice);

    // create correlation
    if (ot_role & RECEIVER)
    {
        t1Slice.rsub<T>(receiverOutputSlice);
        t1Slice.add<T>(newReceiverInput, repeat);
        t1Slice.pack(os[0]);

//        t1 = receiverOutputMatrix;
//        t1 ^= newReceiverInput;
//        receiverOutputMatrix.print_side_by_side(t1);
    }
#ifdef OTEXT_TIMER
    timeval commst1, commst2;
    gettimeofday(&commst1, NULL);
#endif
    // send t0 + t1 + x
    send_if_ot_receiver(player, os, ot_role);

    // sender adjusts using base receiver bits
    if (ot_role & SENDER)
    {
        // u = t0 + t1 + x
        uSlice.unpack(os[1]);
        senderOutputSlices[0].conditional_add<T>(baseReceiverInput, u, !useConstantBase);
    }
#ifdef OTEXT_TIMER
    gettimeofday(&commst2, NULL);
    double commstime = timeval_diff(&commst1, &commst2);
    cout << "\t\tCommunication took time " << commstime/1000000 << endl << flush;
    times["Communication"] += timeval_diff(&commst1, &commst2);
#endif
}
Exemplo n.º 29
0
inline __useconds_t
get_timeval_passed(struct timeval *since, struct timeval *diff)
{
	struct timeval now;

	gettimeofday(&now, NULL);

	return timeval_diff(&now, since, diff);
}
Exemplo n.º 30
0
static 
bool check_read_stop()
{
    uint64_t history_diff = timeval_diff(&first_pack_time, &last_pack_time);
    uint64_t cur_diff     = timeval_diff(&base_time, &cur_time);
    uint64_t diff;
    tc_log_debug2(LOG_DEBUG, "diff,old:%llu,new:%llu", 
            history_diff, cur_diff);
    if(history_diff <= cur_diff){
        return false;
    }
    diff = history_diff - cur_diff;
    /* More than 1 seconds */
    if(diff > 1000){
        return true;
    }
    return false;
}