static inline void check_timeout_random_component (struct context *c) { if (now >= c->c2.update_timeout_random_component) check_timeout_random_component_dowork (c); if (c->c2.timeval.tv_sec >= 1) tv_add (&c->c2.timeval, &c->c2.timeout_random_component); }
int count_syscall(struct tcb *tcp, struct timeval *tv) { tcp->flags &= ~TCB_INSYSCALL; if (tcp->scno < 0 || tcp->scno >= nsyscalls) return 0; if (!counts) { counts = calloc(nsyscalls, sizeof(*counts)); if (!counts) { fprintf(stderr, "strace: out of memory for call counts\n"); exit(1); } } counts[tcp->scno].calls++; if (tcp->u_error) counts[tcp->scno].errors++; tv_sub(tv, tv, &tcp->etime); #ifdef LINUX if (tv_cmp(tv, &tcp->dtime) > 0) { static struct timeval one_tick; if (one_tick.tv_usec == 0) { /* Initialize it. */ struct itimerval it; memset(&it, 0, sizeof it); it.it_interval.tv_usec = 1; setitimer(ITIMER_REAL, &it, NULL); getitimer(ITIMER_REAL, &it); one_tick = it.it_interval; } if (tv_nz(&tcp->dtime)) *tv = tcp->dtime; else if (tv_cmp(tv, &one_tick) > 0) { if (tv_cmp(&shortest, &one_tick) < 0) *tv = shortest; else *tv = one_tick; } } #endif /* LINUX */ if (tv_cmp(tv, &shortest) < 0) shortest = *tv; tv_add(&counts[tcp->scno].time, &counts[tcp->scno].time, tv); return 0; }
static void dump_perf_stats(double wallclock) { /* Prints performance statistics in JSON format */ tv_add(&g.total_stime, &g.total_utime); /* Use the systime variable to * store the total process * time */ printf( "###OUTPUT: {\"Total_memory\": %ld, \ \"Wallclock_time\": %f, \"Total_processes\": %d, \ \"Total_process_time\": %ld.%06ld, \ \"Total_user_time\": %ld.%06ld}\n",
void count_syscall(struct tcb *tcp, const struct timeval *syscall_exiting_tv) { struct timeval wtv; struct timeval *tv = &wtv; struct call_counts *cc; unsigned long scno = tcp->scno; if (!SCNO_IN_RANGE(scno)) return; if (!counts) counts = xcalloc(nsyscalls, sizeof(*counts)); cc = &counts[scno]; cc->calls++; if (tcp->u_error) cc->errors++; /* tv = wall clock time spent while in syscall */ tv_sub(tv, syscall_exiting_tv, &tcp->etime); /* Spent more wall clock time than spent system time? (usually yes) */ if (tv_cmp(tv, &tcp->dtime) > 0) { static struct timeval one_tick = { -1, 0 }; if (one_tick.tv_sec == -1) { /* Initialize it. */ struct itimerval it; memset(&it, 0, sizeof it); it.it_interval.tv_usec = 1; setitimer(ITIMER_REAL, &it, NULL); getitimer(ITIMER_REAL, &it); one_tick = it.it_interval; //FIXME: this hack doesn't work (tested on linux-3.6.11): one_tick = 0.000000 //tprintf(" one_tick.tv_usec:%u\n", (unsigned)one_tick.tv_usec); } if (tv_nz(&tcp->dtime)) /* tv = system time spent, if it isn't 0 */ tv = &tcp->dtime; else if (tv_cmp(tv, &one_tick) > 0) { /* tv = smallest "sane" time interval */ if (tv_cmp(&shortest, &one_tick) < 0) tv = &shortest; else tv = &one_tick; } } if (tv_cmp(tv, &shortest) < 0) shortest = *tv; tv_add(&cc->time, &cc->time, count_wallclock ? &wtv : tv); }
void tfrc_recv_rtt(struct tfrc *state, struct timeval curr_time, uint32_t rtt) { /* Called whenever the receiver gets an RTCP APP packet telling */ /* it the RTT to the sender. Not performance critical. */ /* Note: RTT is in microseconds. */ validate_tfrc_state(state); if (state->RTT == 0) { state->feedback_timer = curr_time; tv_add(&(state->feedback_timer), rtt); } state->RTT = rtt; }
int __event_add(struct event *ev, const struct timeval *timeout) { assert((ev->flags & (EV_PENDING|EV_CURRENT)) == 0); if (timeout != NULL) { gettimeofday(&ev->expire, NULL); tv_add(&ev->expire, timeout); ev->timeout = *timeout; ev->flags |= EV_HAS_TIMEOUT; } else ev->flags &= ~EV_HAS_TIMEOUT; __event_link(ev); return (0); }
void count_syscall(struct tcb *tcp, struct timeval *tv) { if (!SCNO_IN_RANGE(tcp->scno)) return; if (!counts) { counts = calloc(nsyscalls, sizeof(*counts)); if (!counts) die_out_of_memory(); } counts[tcp->scno].calls++; if (tcp->u_error) counts[tcp->scno].errors++; tv_sub(tv, tv, &tcp->etime); if (tv_cmp(tv, &tcp->dtime) > 0) { static struct timeval one_tick; if (one_tick.tv_usec == 0) { /* Initialize it. */ struct itimerval it; memset(&it, 0, sizeof it); it.it_interval.tv_usec = 1; setitimer(ITIMER_REAL, &it, NULL); getitimer(ITIMER_REAL, &it); one_tick = it.it_interval; } if (tv_nz(&tcp->dtime)) *tv = tcp->dtime; else if (tv_cmp(tv, &one_tick) > 0) { if (tv_cmp(&shortest, &one_tick) < 0) *tv = shortest; else *tv = one_tick; } } if (tv_cmp(tv, &shortest) < 0) shortest = *tv; tv_add(&counts[tcp->scno].time, &counts[tcp->scno].time, tv); }
double tfrc_feedback_txrate(struct tfrc *state, struct timeval curr_time) { /* Calculate the appropriate transmission rate, to be included */ /* in a feedback message to the sender. */ validate_tfrc_state(state); assert(tfrc_feedback_is_due(state, curr_time)); state->feedback_timer.tv_sec = curr_time.tv_sec; state->feedback_timer.tv_usec = curr_time.tv_usec; tv_add(&(state->feedback_timer), state->RTT); state->p = compute_loss_event(state); //compute_transfer_rate (); if (state->ii >= N) { abort(); /* FIXME */ } return 0.0; /* FIXME */ }
int fibril_condvar_wait_timeout(fibril_condvar_t *fcv, fibril_mutex_t *fm, suseconds_t timeout) { awaiter_t wdata; assert(fibril_mutex_is_locked(fm)); if (timeout < 0) return ETIMEOUT; awaiter_initialize(&wdata); wdata.fid = fibril_get_id(); wdata.to_event.inlist = timeout > 0; wdata.wu_event.inlist = true; futex_down(&async_futex); if (timeout) { getuptime(&wdata.to_event.expires); tv_add(&wdata.to_event.expires, timeout); async_insert_timeout(&wdata); } list_append(&wdata.wu_event.link, &fcv->waiters); _fibril_mutex_unlock_unsafe(fm); fibril_switch(FIBRIL_TO_MANAGER); fibril_mutex_lock(fm); /* async_futex not held after fibril_switch() */ futex_down(&async_futex); if (wdata.to_event.inlist) list_remove(&wdata.to_event.link); if (wdata.wu_event.inlist) list_remove(&wdata.wu_event.link); futex_up(&async_futex); return wdata.to_event.occurred ? ETIMEOUT : EOK; }
static struct pbuf_node *create_new_pnode(rtp_packet * pkt) { struct pbuf_node *tmp; perf_record(UVP_CREATEPBUF, pkt->ts); tmp = malloc(sizeof(struct pbuf_node)); if (tmp != NULL) { tmp->magic = PBUF_MAGIC; tmp->nxt = NULL; tmp->prv = NULL; tmp->decoded = 0; tmp->rtp_timestamp = pkt->ts; tmp->mbit = pkt->m; gettimeofday(&(tmp->arrival_time), NULL); gettimeofday(&(tmp->playout_time), NULL); /* Playout delay... should really be adaptive, based on the */ /* jitter, but we use a (conservative) fixed 32ms delay for */ /* now (2 video frames at 60fps). */ tv_add(&(tmp->playout_time), 0.032); tmp->cdata = malloc(sizeof(struct coded_data)); if (tmp->cdata != NULL) { tmp->cdata->nxt = NULL; tmp->cdata->prv = NULL; tmp->cdata->seqno = pkt->seq; tmp->cdata->data = pkt; } else { free(pkt); free(tmp); return NULL; } } else { free(pkt); } return tmp; }
void tfrc_recv_data(struct tfrc *state, struct timeval curr_time, uint16_t seqnum, unsigned length) { /* This is called each time an RTP packet is received. Accordingly, */ /* it needs to be _very_ fast, otherwise we'll drop packets. */ validate_tfrc_state(state); if (state->RTT > 0) { save_arrival(state, curr_time, seqnum); state->p_prev = state->p; #ifdef NDEF state->p = compute_loss_event(state); if (state->p - state->p_prev > 0.00000000001) { gettimeofday(&(state->feedback_timer), NULL); tv_add(&(state->feedback_timer), (unsigned int)state->RTT); compute_transfer_rate(); } #endif } state->s = length; /* packet size is needed transfer_rate */ }
void extend_line( PLINE pline, timeval xval, int yval) { PLOTTER p; if (!pline) return; p = pline->plotter; #ifdef OLD /* attach a label to the first non-zero point */ if (!pline->labelled) { if (yval != 0) { plotter_temp_color(p, pline->color); plotter_text(p, xval, yval, "l", pline->label); pline->labelled = 1; } } #endif /* attach a label midway on the first line segment above 0 */ /* for whom the second point is NOT 0 */ if (!pline->labelled) { if ((yval != 0) && (!ZERO_TIME(&pline->last_time))) { timeval tv_elapsed; timeval tv_avg; int avg_yval; /* computer elapsed time for these 2 points */ tv_elapsed = xval; tv_sub(&tv_elapsed,pline->last_time); /* divide elapsed time by 2 */ tv_elapsed.tv_sec /= 2; tv_elapsed.tv_usec /= 2; /* add 1/2 of the elapsed time to the oldest point */ /* (giving us the average time) */ tv_avg = pline->last_time; tv_add(&tv_avg, tv_elapsed); /* average the Y values */ avg_yval = (1 + pline->last_y+yval)/2; /* (rounding UP, please) */ /* draw the label */ plotter_temp_color(p, pline->color); plotter_text(p, tv_avg, avg_yval, "l", pline->label); /* remember that it's been done */ pline->labelled = 1; } } /* draw a dot at the current point */ plotter_perm_color(p, pline->color); plotter_dot(p, xval, yval); /* if this isn't the FIRST point, connect with a line */ if (!ZERO_TIME(&pline->last_time)) { plotter_line(p, xval, yval, pline->last_time, pline->last_y); } /* remember this point for the next line segment */ pline->last_time = xval; pline->last_y = yval; }
static void call_summary_pers(FILE *outf) { int i, j; int call_cum, error_cum; struct timeval tv_cum, dtv; double percent; char *dashes = "-------------------------"; char error_str[16]; int *sorted_count = calloc(sizeof(int), nsyscalls); if (!sorted_count) { fprintf(stderr, "strace: out of memory for call summary\n"); return; } call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0; if (overhead.tv_sec == -1) { tv_mul(&overhead, &shortest, 8); tv_div(&overhead, &overhead, 10); } for (i = 0; i < nsyscalls; i++) { sorted_count[i] = i; if (counts == NULL || counts[i].calls == 0) continue; tv_mul(&dtv, &overhead, counts[i].calls); tv_sub(&counts[i].time, &counts[i].time, &dtv); call_cum += counts[i].calls; error_cum += counts[i].errors; tv_add(&tv_cum, &tv_cum, &counts[i].time); } if (counts && sortfun) qsort((void *) sorted_count, nsyscalls, sizeof(int), sortfun); fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n", "% time", "seconds", "usecs/call", "calls", "errors", "syscall"); fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n", dashes, dashes, dashes, dashes, dashes, dashes); if (counts) { for (i = 0; i < nsyscalls; i++) { j = sorted_count[i]; if (counts[j].calls == 0) continue; tv_div(&dtv, &counts[j].time, counts[j].calls); if (counts[j].errors) sprintf(error_str, "%d", counts[j].errors); else error_str[0] = '\0'; percent = (100.0 * tv_float(&counts[j].time) / tv_float(&tv_cum)); fprintf(outf, "%6.2f %11.6f %11ld %9d %9.9s %s\n", percent, tv_float(&counts[j].time), (long) 1000000 * dtv.tv_sec + dtv.tv_usec, counts[j].calls, error_str, sysent[j].sys_name); } } free(sorted_count); fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n", dashes, dashes, dashes, dashes, dashes, dashes); if (error_cum) sprintf(error_str, "%d", error_cum); else error_str[0] = '\0'; fprintf(outf, "%6.6s %11.6f %11.11s %9d %9.9s %s\n", "100.00", tv_float(&tv_cum), "", call_cum, error_str, "total"); }
static void call_summary_pers(FILE *outf) { unsigned int i; int call_cum, error_cum; struct timeval tv_cum, dtv; double float_tv_cum; double percent; const char *dashes = "----------------"; char error_str[sizeof(int)*3]; int *sorted_count; fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n", "% time", "seconds", "usecs/call", "calls", "errors", "syscall"); fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n", dashes, dashes, dashes, dashes, dashes, dashes); sorted_count = xcalloc(sizeof(int), nsyscalls); call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0; if (overhead.tv_sec == -1) { tv_mul(&overhead, &shortest, 8); tv_div(&overhead, &overhead, 10); } for (i = 0; i < nsyscalls; i++) { sorted_count[i] = i; if (counts == NULL || counts[i].calls == 0) continue; tv_mul(&dtv, &overhead, counts[i].calls); tv_sub(&counts[i].time, &counts[i].time, &dtv); call_cum += counts[i].calls; error_cum += counts[i].errors; tv_add(&tv_cum, &tv_cum, &counts[i].time); } float_tv_cum = tv_float(&tv_cum); if (counts) { if (sortfun) qsort((void *) sorted_count, nsyscalls, sizeof(int), sortfun); for (i = 0; i < nsyscalls; i++) { double float_syscall_time; int idx = sorted_count[i]; struct call_counts *cc = &counts[idx]; if (cc->calls == 0) continue; tv_div(&dtv, &cc->time, cc->calls); error_str[0] = '\0'; if (cc->errors) sprintf(error_str, "%u", cc->errors); float_syscall_time = tv_float(&cc->time); percent = (100.0 * float_syscall_time); if (percent != 0.0) percent /= float_tv_cum; /* else: float_tv_cum can be 0.0 too and we get 0/0 = NAN */ fprintf(outf, "%6.2f %11.6f %11lu %9u %9.9s %s\n", percent, float_syscall_time, (long) (1000000 * dtv.tv_sec + dtv.tv_usec), cc->calls, error_str, sysent[idx].sys_name); } } free(sorted_count); fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n", dashes, dashes, dashes, dashes, dashes, dashes); error_str[0] = '\0'; if (error_cum) sprintf(error_str, "%u", error_cum); fprintf(outf, "%6.6s %11.6f %11.11s %9u %9.9s %s\n", "100.00", float_tv_cum, "", call_cum, error_str, "total"); }
tv_t tv_inc(tv_t tv) { return tv_add(tv, (DPData.cf_explevel_inc_third ? 0004 : 0003)); }