/* {{{ proto array accelerator_get_scripts()
   Get the scripts which are accelerated by ZendAccelerator */
static zval* accelerator_get_scripts(TSRMLS_D)
{
	uint i;
	zval *return_value,*persistent_script_report;
	zend_accel_hash_entry *cache_entry;
	struct tm *ta;
	struct timeval exec_time;
	struct timeval fetch_time;

	if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock(TSRMLS_C) != SUCCESS) {
		return 0;
	}

	MAKE_STD_ZVAL(return_value);
	array_init(return_value);
	for (i = 0; i<ZCSG(hash).max_num_entries; i++) {
		for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
			zend_persistent_script *script;
			char *str;
			size_t len;

			if (cache_entry->indirect) continue;

			script = (zend_persistent_script *)cache_entry->data;

			MAKE_STD_ZVAL(persistent_script_report);
			array_init(persistent_script_report);
			add_assoc_stringl(persistent_script_report, "full_path", script->full_path, script->full_path_len, 1);
			add_assoc_long(persistent_script_report, "hits", script->dynamic_members.hits);
			add_assoc_long(persistent_script_report, "memory_consumption", script->dynamic_members.memory_consumption);
			ta = localtime(&script->dynamic_members.last_used);
			str = asctime(ta);
			len = strlen(str);
			if (len > 0 && str[len - 1] == '\n') len--;
			add_assoc_stringl(persistent_script_report, "last_used", str, len, 1);
			add_assoc_long(persistent_script_report, "last_used_timestamp", script->dynamic_members.last_used);
			if (ZCG(accel_directives).validate_timestamps) {
				add_assoc_long(persistent_script_report, "timestamp", (long)script->timestamp);
			}
			timerclear(&exec_time);
			timerclear(&fetch_time);

			zend_hash_update(return_value->value.ht, cache_entry->key, cache_entry->key_length, &persistent_script_report, sizeof(zval *), NULL);
		}
	}
	accelerator_shm_read_unlock(TSRMLS_C);

	return return_value;
}
Esempio n. 2
0
static int init_begin(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile)
{
  adns_state ads;
  

  ads = MyMalloc(sizeof(*ads));

  /* Under hybrid, MyMalloc would have aborted already */
#if 0
 if (!ads) return errno;
#endif

  ads->iflags= flags;
  ads->diagfile= diagfile;
  ads->configerrno= 0;
  ADNS_LIST_INIT(ads->udpw);
  ADNS_LIST_INIT(ads->tcpw);
  ADNS_LIST_INIT(ads->childw);
  ADNS_LIST_INIT(ads->output);
  ads->forallnext= 0;
  ads->nextid= 0x311f;
  ads->udpsocket= ads->tcpsocket= -1;
  adns__vbuf_init(&ads->tcpsend);
  adns__vbuf_init(&ads->tcprecv);
  ads->tcprecv_skip= 0;
  ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0;
  ads->searchndots= 1;
  ads->tcpstate= server_disconnected;
  timerclear(&ads->tcptimeout);
  ads->searchlist= 0;

  *ads_r= ads;
  return 0;
}
NwRcT nwTimerStart( NwGreTimerMgrHandleT tmrMgrHandle,
    NwU32T timeoutSec,
    NwU32T timeoutUsec,
    NwU32T tmrType,
    void*  timeoutArg,
    NwGreTimerHandleT* hTmr)
{
  NwRcT rc = NW_OK;
#ifdef __WITH_LIBEVENT__
  NwMiniTmrMgrEntityT *pTmr;
  struct timeval tv;

  pTmr = (NwMiniTmrMgrEntityT*) malloc (sizeof(NwMiniTmrMgrEntityT));

  /* set the timevalues*/
  timerclear(&tv);
  tv.tv_sec     = timeoutSec;
  tv.tv_usec    = timeoutUsec;

  pTmr->timeoutArg = timeoutArg;
  evtimer_set(&pTmr->ev, nwMiniTmrMgrHandleTimeout, pTmr);

  /*add event*/

  event_add(&(pTmr->ev), &tv);
#else
#warning "Timer library not defined!"
#endif

  *hTmr = (NwGreTimerHandleT)pTmr;

  return NW_OK;
}
Esempio n. 4
0
		void TCPConnection::__setup_socket(ibrcommon::clientsocket *sock, bool server)
		{
			if ( dtn::daemon::Configuration::getInstance().getNetwork().getTCPOptionNoDelay() )
			{
				sock->set(ibrcommon::clientsocket::NO_DELAY, true);
			}

			_socket_stream = new ibrcommon::socketstream(sock);

			// set an initial time-out
			timeval timeout;
			timerclear(&timeout);
			timeout.tv_sec = _timeout;
			_socket_stream->setTimeout(timeout);

#ifdef WITH_TLS
			// initialize security layer if available
			_sec_stream = new ibrcommon::TLSStream(_socket_stream);
			if (server) dynamic_cast<ibrcommon::TLSStream&>(*_sec_stream).setServer(true);
			else dynamic_cast<ibrcommon::TLSStream&>(*_sec_stream).setServer(false);
#endif

			// create a new stream connection
			dtn::data::Length chunksize = dtn::daemon::Configuration::getInstance().getNetwork().getTCPChunkSize();

			ibrcommon::RWLock l(_protocol_stream_mutex);
			if (_protocol_stream != NULL) delete _protocol_stream;
			_protocol_stream = new dtn::streams::StreamConnection(*this, (_sec_stream == NULL) ? *_socket_stream : *_sec_stream, chunksize);
			_protocol_stream->exceptions(std::ios::badbit | std::ios::eofbit);
		}
Esempio n. 5
0
void doTiming(FunctorT f, size_t reps)
{
    struct timeval begin;
    gettimeofday(&begin, NULL);
    for (size_t i = 0; i < reps; ++i)
    {
        f();
    }

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

    struct timeval length;
    timerclear(&length);
    if (end.tv_usec < begin.tv_usec)
    {
        // handle borrow
        length.tv_sec = (end.tv_sec - 1) - begin.tv_sec;
        length.tv_usec = end.tv_usec - begin.tv_usec + 1000000;
    }
    else
    {
        length.tv_sec = end.tv_sec - begin.tv_sec;
        length.tv_usec = end.tv_usec - begin.tv_usec;
    }
    std::cout << f.name() << " x " << reps << '\n';
    std::cout << std::setw(8) << std::setfill(' ') << length.tv_sec << '.' << std::setw(6) << std::setfill('0') << length.tv_usec << std::endl;
}
Esempio n. 6
0
void profile_in(glui32 addr, glui32 stackuse, int accel)
{
  frame_t *fra;
  function_t *func;
  struct timeval now;

  if (!profiling_active)
    return;

  /* printf("### IN: %lx%s\n", addr, (accel?" accel":"")); */

  if (profiling_call_counts && current_frame) {
    function_t *parfunc = current_frame->func;
    callcount_t **ccref;
    for (ccref = &parfunc->outcalls; *ccref; ccref = &((*ccref)->next)) {
      if ((*ccref)->toaddr == addr) 
        break;
    }
    if (*ccref) {
      (*ccref)->count += 1;
    }
    else {
      *ccref = glulx_malloc(sizeof(callcount_t));
      (*ccref)->toaddr = addr;
      (*ccref)->count = 1;
      (*ccref)->next = NULL;
    }
  }

  gettimeofday(&now, NULL);

  func = get_function(addr);
  func->call_count += 1;
  if (accel)
    func->accel_count += 1;
  if (!func->entry_depth) {
    func->entry_start_time = now;
    func->entry_start_op = profile_opcount;
  }
  func->entry_depth += 1;

  if (func->max_stack_use < stackuse)
    func->max_stack_use = stackuse;

  fra = (frame_t *)glulx_malloc(sizeof(frame_t));
  if (!fra)
    fatal_error("Profiler: cannot malloc frame.");
  memset(fra, 0, sizeof(frame_t));

  fra->parent = current_frame;
  current_frame = fra;

  if (fra->parent)
    fra->depth = fra->parent->depth + 1;
  fra->func = func;
  fra->entry_time = now;
  fra->entry_op = profile_opcount;
  timerclear(&fra->children_time);
  fra->children_ops = 0;
}
Esempio n. 7
0
		void Clock::getdtntimeofday(struct timeval *tv)
		{
			struct timezone tz;
			::gettimeofday(tv, &tz);

			// correct by the local offset
			if (!Clock::shouldModifyClock())
			{
				if (!Clock::_offset_init)
				{
					timerclear(&Clock::_offset);
					Clock::_offset_init = true;
				}

				// add offset
				timersub(tv, &Clock::_offset, tv);
			}

			// do we believe we are before the year 2000?
			if (dtn::data::Timestamp(tv->tv_sec) < TIMEVAL_CONVERSION)
			{
				tv->tv_sec = 0;
			}
			else
			{
				// do bundle protocol time conversion
				tv->tv_sec -= TIMEVAL_CONVERSION.get<time_t>();
			}
		}
Esempio n. 8
0
		void Clock::setOffset(struct timeval &tv)
		{
			if (!modify_clock)
			{
				if (!Clock::_offset_init)
				{
					timerclear(&Clock::_offset);
					Clock::_offset_init = true;
				}
				timeradd(&Clock::_offset, &tv, &Clock::_offset);
				IBRCOMMON_LOGGER(info) << "[Clock] new local offset: " << _offset.tv_sec << " seconds and " << _offset.tv_usec << " microseconds" << IBRCOMMON_LOGGER_ENDL;
			}
			else
			{
				struct timezone tz;
				struct timeval now;
				::gettimeofday(&now, &tz);

				// adjust by the offset
				timersub(&now, &tv, &now);

				// set the local clock to the new timestamp
				::settimeofday(&now, &tz);
			}
		}
NwRcT nwTimerStart( NwGtpv2cTimerMgrHandleT tmrMgrHandle,
                    uint32_t timeoutSec,
                    uint32_t timeoutUsec,
                    uint32_t tmrType,
                    void*  timeoutArg,
                    NwGtpv2cTimerHandleT* hTmr)
{
  NwRcT rc = NW_OK;
  NwGtpv2cNodeTmrT *pTmr;
  struct timeval tv;

  NW_LOG(NW_LOG_LEVEL_DEBG, "Received start timer request from stack with timer type %u, arg %x, for %u sec and %u usec", tmrType, timeoutArg, timeoutSec, timeoutUsec);

  pTmr = (NwGtpv2cNodeTmrT*) malloc(sizeof(NwGtpv2cNodeTmrT));

  /* set the timevalues*/
  timerclear(&tv);
  tv.tv_sec     = timeoutSec;
  tv.tv_usec    = timeoutUsec;

  pTmr->timeoutArg = timeoutArg;
  evtimer_set(&pTmr->ev, nwGtpv2cNodeHandleStackTimerTimeout, pTmr);

  /*add event*/

  event_add(&(pTmr->ev), &tv);

  *hTmr = (NwGtpv2cTimerHandleT)pTmr;

  return rc;
}
Esempio n. 10
0
/*
 * SOCKDGRAM is unreliable, so we must repeat messages if we have
 * not received an acknowledgement within a reasonable amount
 * of time
 */
void
ctl_transact(struct in_addr target, CTL_MSG lmsg, int type, CTL_RESPONSE *rp)
{
	fd_set read_mask, ctl_mask;
	int nready = 0, cc;
	struct timeval wait;

	lmsg.type = type;
	daemon_addr.sin_addr = target;
	daemon_addr.sin_port = daemon_port;
	FD_ZERO(&ctl_mask);
	FD_SET(ctl_sockt, &ctl_mask);

	/*
	 * Keep sending the message until a response of
	 * the proper type is obtained.
	 */
	do {
		wait.tv_sec = CTL_WAIT;
		wait.tv_usec = 0;
		/* resend message until a response is obtained */
		do {
			cc = sendto(ctl_sockt, (char *)&lmsg, sizeof (lmsg), 0,
			    (struct sockaddr *)&daemon_addr,
			    sizeof (daemon_addr));
			if (cc != sizeof (lmsg)) {
				if (errno == EINTR)
					continue;
				p_error("Error on write to talk daemon");
			}
			read_mask = ctl_mask;
			nready = select(32, &read_mask, 0, 0, &wait);
			if (nready < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error waiting for daemon response");
			}
		} while (nready == 0);
		/*
		 * Keep reading while there are queued messages
		 * (this is not necessary, it just saves extra
		 * request/acknowledgements being sent)
		 */
		do {
			cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
			if (cc < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error on read from talk daemon");
			}
			read_mask = ctl_mask;
			/* an immediate poll */
			timerclear(&wait);
			nready = select(32, &read_mask, 0, 0, &wait);
		} while (nready > 0 && (rp->vers != TALK_VERSION ||
		    rp->type != type));
	} while (rp->vers != TALK_VERSION || rp->type != type);
	rp->id_num = ntohl(rp->id_num);
	rp->addr.sa_family = ntohs(rp->addr.sa_family);
}
Esempio n. 11
0
/* Timeout to check for idle senders/members */
UT_STATIC
void rtcp_member_timeout_cb (const vqec_event_t * const evptr,
                             int32_t fd, int16_t event, void *arg) 
{
    struct timeval tv;
    rtp_session_t *p_sess = NULL;
    uint32_t interval = 0;

    if (!arg) {
        rtcp_tmevt_log_err("%s %s", __FUNCTION__, s_arg_is_null);
        /*sa_ignore {nothing to be done if stop fails} IGNORE_RETURN (1) */
        vqec_event_stop(evptr);    
        return;
    }

    p_sess = (rtp_session_t *)arg;

    /* check for idle senders */
    MCALL(p_sess, rtp_session_timeout_slist);
    /* check for idle members */
    MCALL(p_sess, rtp_session_timeout_glist);

    /* restart the timer */
    timerclear(&tv);
    interval = MCALL(p_sess, rtcp_report_interval,
                     p_sess->we_sent, TRUE /* jitter the interval */);
    tv = TIME_GET_R(timeval,TIME_MK_R(usec, (int64_t)interval)) ;
    /*sa_ignore {no recourse if start fails} IGNORE_RETURN (1) */
    vqec_event_start(evptr, &tv);
}
Esempio n. 12
0
static int init_begin(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
  adns_state ads;
  
  ads= malloc(sizeof(*ads)); if (!ads) return errno;

  ads->iflags= flags;
  ads->diagfile= diagfile;
  ads->configerrno= 0;
  LIST_INIT(ads->udpw);
  LIST_INIT(ads->tcpw);
  LIST_INIT(ads->childw);
  LIST_INIT(ads->output);
  ads->forallnext= 0;
  ads->nextid= 0x311f;
  ads->udpsocket= ads->tcpsocket= -1;
  adns__vbuf_init(&ads->tcpsend);
  adns__vbuf_init(&ads->tcprecv);
  ads->tcprecv_skip= 0;
  ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0;
  ads->searchndots= 1;
  ads->tcpstate= server_disconnected;
  timerclear(&ads->tcptimeout);
  ads->searchlist= 0;

  *ads_r= ads;
  return 0;
}
Esempio n. 13
0
void InitConnectTo(Server *pServer) {

    struct sockaddr_in sa;

    u32 ip;
    inet_aton(pServer->host, &ip);
    sa.sin_addr = *((struct in_addr *) & ip);
    sa.sin_family = AF_INET;
    sa.sin_port = htons(pServer->port);
    bzero(&sa.sin_zero, 8);


    gettimeofday(&tv, NULL);
    printf("InitConnectTo()  [time: %d]\n", tv.tv_sec);

    pServer->poll->status = 1;
    timerclear(&tv);
     tv.tv_usec=pServer->timeout*1000*1000;

    pServer->poll->bev = bufferevent_socket_new(pServer->evConfig.ev_base, -1, BEV_OPT_CLOSE_ON_FREE);
    bufferevent_socket_connect(pServer->poll->bev ,(struct sockaddr *)&sa, sizeof(sa));
    bufferevent_setcb(pServer->poll->bev, OnBufferedRead, OnBufferedWrite, OnBufferedError, pServer);
    bufferevent_enable(pServer->poll->bev, EV_READ|EV_WRITE |EV_TIMEOUT);
    bufferevent_set_timeouts(pServer->poll->bev, &tv, &tv);

}
Esempio n. 14
0
/* ARGSUSED */
void
db_tx_timer(int fd, short event, void *arg)
{
	struct nbr *nbr = arg;
	struct timeval tv;

	switch (nbr->state) {
	case NBR_STA_DOWN:
	case NBR_STA_ATTEMPT:
	case NBR_STA_INIT:
	case NBR_STA_2_WAY:
	case NBR_STA_SNAP:
		return ;
	case NBR_STA_XSTRT:
	case NBR_STA_XCHNG:
	case NBR_STA_LOAD:
	case NBR_STA_FULL:
		send_db_description(nbr);
		break;
	default:
		log_debug("db_tx_timer: unknown neighbor state, "
		    "neighbor ID %s", inet_ntoa(nbr->id));
		break;
	}

	/* reschedule db_tx_timer but only in master mode */
	if (nbr->dd_master) {
		timerclear(&tv);
		tv.tv_sec = nbr->iface->rxmt_interval;
		if (evtimer_add(&nbr->db_tx_timer, &tv) == -1)
			fatal("db_tx_timer");
	}
}
Esempio n. 15
0
void
simpleSNMPupdate()
{
    int count;
    int numfds, block;
    fd_set fdset;
    struct timeval timeout, *tvp;

    numfds = 0;
    FD_ZERO(&fdset);
    block = 0;
    tvp = &timeout;
    timerclear(tvp);
    tvp->tv_sec = 0;
    snmp_select_info(&numfds, &fdset, tvp, &block);
	/*        if (block == 1)
		  tvp = NULL; */ /* block without timeout */
    count = select(numfds, &fdset, 0, 0, tvp);
    if (count > 0){
        snmp_read(&fdset);
    } else switch(count){
        case 0:
            snmp_timeout();
	    break;
        case -1:
	    fprintf(stderr, "snmp error on select\n");
	    break;
        default:
            fprintf(stderr, "select returned %d\n", count);
    }
}
Esempio n. 16
0
void
part_cb_done(struct dht_rpc *            rpc,
             struct dht_group_msg_reply *reply,
             void *                      arg)
{
    static int count;
    struct dht_group *group = arg;
    char *channel_name;
    unsigned int error_code;
    char *error_reason;

    CU_ASSERT(reply != NULL);

    EVTAG_GET(reply, channel_name, &channel_name);
    EVTAG_GET(reply, error_code, &error_code);
    EVTAG_GET(reply, error_reason, &error_reason);

    fprintf(stderr, "%s: channel: %s -> %d - %s\n",
            dht_node_id_ascii(dht_myid(group->dht)),
            channel_name, error_code, error_reason);


    if (++count == 2) {
        struct timeval tv;
        /* We have just two parts - so quit shortly after they
         * are done */
        timerclear(&tv);
        tv.tv_sec = 5; /* exit the loop after 5 second */

        event_loopexit(&tv);
    }
}
Esempio n. 17
0
int main(int argc, char **argv) {

    struct timeval tv;
    struct event_base *base;
    base=event_init();
    timerclear(&tv);

    Server *pServer;
    pServer=calloc(1,sizeof(*pServer));
    pServer->poll=calloc(1,sizeof(*pServer->poll));
    pServer->periodReport=1;
    pServer->host=strdup("1.1.1.1");
    pServer->port=80;
    pServer->periodRetrieve=10;
    pServer->periodReport=1;
    pServer->timeout=8;

    tv.tv_sec = pServer->periodReport;
    evtimer_set(&pServer->evReport, timer, pServer);
    evtimer_add(&pServer->evReport, &tv);

    tv.tv_sec = 0;
    evtimer_set(&pServer->evConfig, timerRetrieveTask, pServer);
    evtimer_add(&pServer->evConfig, &tv);


    event_dispatch();
    event_base_free(base);
    return 0;
}
Esempio n. 18
0
/* There is no way to get `EVLIST_INSERTED` event flag outside of libevent, so
 * here are tracking functions. */
static void tracked_event_set(
		struct tracked_event *tev, evutil_socket_t fd, short events,
		void (*callback)(evutil_socket_t, short, void *), void *arg)
{
	event_set(&tev->ev, fd, events, callback, arg);
	timerclear(&tev->inserted);
}
Esempio n. 19
0
static int tracked_event_del(struct tracked_event *tev)
{
	int ret = event_del(&tev->ev);
	if (ret == 0)
		timerclear(&tev->inserted);
	return ret;
}
Esempio n. 20
0
cl_status_t
cl_timer_trim(IN cl_timer_t * const p_timer, IN const uint32_t time_ms)
{
	struct timeval curtime;
	struct timespec newtime;
	cl_status_t status;

	CL_ASSERT(p_timer);
	CL_ASSERT(p_timer->state == CL_INITIALIZED);

	pthread_mutex_lock(&gp_timer_prov->mutex);

	/* Get the current time */
	timerclear(&curtime);
	gettimeofday(&curtime, NULL);

	/* Calculate the timeout. */
	newtime.tv_sec = curtime.tv_sec + (time_ms / 1000);
	newtime.tv_nsec = (curtime.tv_usec + ((time_ms % 1000) * 1000)) * 1000;

	if (p_timer->timer_state == CL_TIMER_QUEUED) {
		/* If the old time is earlier, do not trim it.  Just return. */
		if (__cl_timer_is_earlier(&p_timer->timeout, &newtime)) {
			pthread_mutex_unlock(&gp_timer_prov->mutex);
			return (CL_SUCCESS);
		}
	}

	/* Reset the timer to the new timeout value. */

	pthread_mutex_unlock(&gp_timer_prov->mutex);
	status = cl_timer_start(p_timer, time_ms);

	return (status);
}
Esempio n. 21
0
void
privmsg_done(struct dht_rpc *            rpc,
             struct dht_group_msg_reply *reply,
             void *                      arg)
{
    struct dht_group *group = arg;
    char *channel_name;
    unsigned int error_code;
    char *error_reason;
    struct timeval tv;

    if (reply == NULL)
        return;

    CU_ASSERT(!EVTAG_GET(reply, channel_name, &channel_name));
    CU_ASSERT(!EVTAG_GET(reply, error_code, &error_code));
    CU_ASSERT(!EVTAG_GET(reply, error_reason, &error_reason));

    fprintf(stderr, "%s: channel: %s -> %d - %s\n",
            dht_node_id_ascii(dht_myid(group->dht)),
            channel_name, error_code, error_reason);

    timerclear(&tv);
    tv.tv_usec = 500000L;
    event_once(-1, EV_TIMEOUT, part_cb, arg, &tv);
}
Esempio n. 22
0
void profile_in(glui32 addr, int accel)
{
  frame_t *fra;
  function_t *func;
  struct timeval now;

  /* printf("### IN: %lx%s\n", addr, (accel?" accel":"")); */

  gettimeofday(&now, NULL);

  func = get_function(addr);
  func->call_count += 1;
  if (accel)
    func->accel_count += 1;
  if (!func->entry_depth) {
    func->entry_start_time = now;
    func->entry_start_op = profile_opcount;
  }
  func->entry_depth += 1;

  fra = (frame_t *)glulx_malloc(sizeof(frame_t));
  if (!fra)
    fatal_error("Profiler: cannot malloc frame.");
  memset(fra, 0, sizeof(frame_t));

  fra->parent = current_frame;
  current_frame = fra;

  fra->func = func;
  fra->entry_time = now;
  fra->entry_op = profile_opcount;
  timerclear(&fra->children_time);
  fra->children_ops = 0;
}
Esempio n. 23
0
void
PcapFilesReader::scan() {
  if (nonEmptyFiles == 0) {
#if DEBUG_TIMING
    std::cout << "End of all inputs files" << std::endl;
#endif
    // notifyAllEnd();
    return;
  }

  int earliest_index = -1;
  const struct timeval* earliest_time;

  for (unsigned i=0; i < files.size(); i++) {
    auto file = files.at(i).get();
    if (file->atEOF()) continue;

    std::unique_ptr<PcapPacket> p = file->current();
    if (earliest_index == -1) {
      earliest_index = i;
      earliest_time = p->getTime();
    } else {
      const struct timeval *time = p->getTime();
      if (timercmp(time, earliest_time, <)) {
        earliest_index = i;
        earliest_time = time;
      }
    }
  }

  assert(earliest_index >= 0);
  struct timeval delay;

#if DEBUG_TIMING
  std::cout << "First packet to send "
            << PcapPacket::timevalToString(earliest_time) << std::endl;
#endif

  if (respectTiming) {
    struct timeval delta;
    timersub(earliest_time, &firstPacketTime, &delta);

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

    struct timeval elapsed;
    timersub(&now, &startTime, &elapsed);

    timersub(&delta, &elapsed, &delay);
#if DEBUG_TIMING
    std::cout << "Delta " << PcapPacket::timevalToString(&delta)
              << " elapsed " << PcapPacket::timevalToString(&elapsed)
              << " delay " << PcapPacket::timevalToString(&delay) << std::endl;
#endif
  } else {
    timerclear(&delay);
  }

  schedulePacket((unsigned)earliest_index, &delay);
}
Esempio n. 24
0
		void Clock::setOffset(const struct timeval &tv)
		{
			if (!Clock::shouldModifyClock())
			{
				if (!Clock::_offset_init)
				{
					timerclear(&Clock::_offset);
					Clock::_offset_init = true;
				}

				timeradd(&Clock::_offset, &tv, &Clock::_offset);
				IBRCOMMON_LOGGER_TAG("Clock", info) << "new local offset: " << Clock::toDouble(_offset) << "s" << IBRCOMMON_LOGGER_ENDL;
			}
			else
			{
				struct timezone tz;
				struct timeval now;
				::gettimeofday(&now, &tz);

				// adjust by the offset
				timersub(&now, &tv, &now);

#ifndef __WIN32__
				// set the local clock to the new timestamp
				::settimeofday(&now, &tz);
#endif
			}
		}
  NwRcT                                   nwTimerStart (
  NwGtpv2cTimerMgrHandleT tmrMgrHandle,
  uint32_t timeoutSec,
  uint32_t timeoutUsec,
  uint32_t tmrType,
  void *timeoutArg,
  NwGtpv2cTimerHandleT * hTmr) {
    NwRcT                                   rc = NW_OK;
    NwGtpv2cNodeTmrT                       *pTmr;
    struct timeval                          tv;

    pTmr = (NwGtpv2cNodeTmrT *) malloc (sizeof (NwGtpv2cNodeTmrT));
    /*
     * set the timevalues
     */
    timerclear (&tv);
    tv.tv_sec = timeoutSec;
    tv.tv_usec = timeoutUsec;
    pTmr->timeoutArg = timeoutArg;
    evtimer_set (&pTmr->ev, nwGtpv2cNodeHandleStackTimerTimeout, pTmr);
    /*
     * add event
     */
    event_add (&(pTmr->ev), &tv);
    *hTmr = (NwGtpv2cTimerHandleT) pTmr;
    return rc;
  }
Esempio n. 26
0
const char *trigger_release_event(const char **remote_name, const char **button_name)
{
	int len = 0;

	if (release_remote != NULL) {
		release_remote->release_detected = 1;
		*remote_name = release_remote->name;
		*button_name = release_ncode->name;
		len =
		    write_message(message, PACKET_SIZE + 1, release_remote->name, release_ncode->name, release_suffix,
				  release_code, 0);
		timerclear(&release_time);
		release_remote = NULL;
		release_ncode = NULL;
		release_code = 0;

		if (len >= PACKET_SIZE + 1) {
			logprintf(LOG_ERR, "message buffer overflow");
			return (NULL);
		}
		LOGPRINTF(3, "trigger");
		return message;
	}
	return NULL;
}
Esempio n. 27
0
/* {{{ proto array accelerator_get_scripts()
   Get the scripts which are accelerated by ZendAccelerator */
static int accelerator_get_scripts(zval *return_value)
{
	uint32_t i;
	zval persistent_script_report;
	zend_accel_hash_entry *cache_entry;
	struct tm *ta;
	struct timeval exec_time;
	struct timeval fetch_time;

	if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
		return 0;
	}

	array_init(return_value);
	for (i = 0; i<ZCSG(hash).max_num_entries; i++) {
		for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
			zend_persistent_script *script;
			char *str;
			size_t len;

			if (cache_entry->indirect) continue;

			script = (zend_persistent_script *)cache_entry->data;

			array_init(&persistent_script_report);
			add_assoc_str(&persistent_script_report, "full_path", zend_string_dup(script->script.filename, 0));
			add_assoc_long(&persistent_script_report, "hits", (zend_long)script->dynamic_members.hits);
			add_assoc_long(&persistent_script_report, "memory_consumption", script->dynamic_members.memory_consumption);
			ta = localtime(&script->dynamic_members.last_used);
			str = asctime(ta);
			len = strlen(str);
			if (len > 0 && str[len - 1] == '\n') len--;
			add_assoc_stringl(&persistent_script_report, "last_used", str, len);
			add_assoc_long(&persistent_script_report, "last_used_timestamp", script->dynamic_members.last_used);
			if (ZCG(accel_directives).validate_timestamps) {
				add_assoc_long(&persistent_script_report, "timestamp", (zend_long)script->timestamp);
			}
			timerclear(&exec_time);
			timerclear(&fetch_time);

			zend_hash_str_update(Z_ARRVAL_P(return_value), cache_entry->key, cache_entry->key_length, &persistent_script_report);
		}
	}
	accelerator_shm_read_unlock();

	return 1;
}
Esempio n. 28
0
PcapFilesReader::PcapFilesReader(bool respectTiming,
                                 unsigned wait_time_in_seconds)
  : nonEmptyFiles(0),
    wait_time_in_seconds(wait_time_in_seconds),
    respectTiming(respectTiming),
    started(false) {
  timerclear(&zero);
}
Esempio n. 29
0
void profile_out(glui32 stackuse)
{
  frame_t *fra;
  function_t *func;
  struct timeval now, runtime;
  glui32 runops;

  if (!profiling_active)
    return;

  /* printf("### OUT\n"); */

  if (!current_frame) 
    fatal_error("Profiler: stack underflow.");

  gettimeofday(&now, NULL);

  fra = current_frame;
  func = fra->func;

  timersub(&now, &fra->entry_time, &runtime);
  runops = profile_opcount - fra->entry_op;

  timeradd(&runtime, &func->self_time, &func->self_time);
  timersub(&func->self_time, &fra->children_time, &func->self_time);
  func->self_ops += runops;
  func->self_ops -= fra->children_ops;

  if (func->max_depth < fra->depth)
    func->max_depth = fra->depth;
  if (func->max_stack_use < stackuse)
    func->max_stack_use = stackuse;

  if (fra->parent) {
    timeradd(&runtime, &fra->parent->children_time, &fra->parent->children_time);
    fra->parent->children_ops += runops;
  }

  if (!func->entry_depth) 
    fatal_error("Profiler: function entry underflow.");
  
  func->entry_depth -= 1;
  if (!func->entry_depth) {
    timersub(&now, &func->entry_start_time, &runtime);
    timerclear(&func->entry_start_time);

    runops = profile_opcount - func->entry_start_op;
    func->entry_start_op = 0;

    timeradd(&runtime, &func->total_time, &func->total_time);
    func->total_ops += runops;
  }

  current_frame = fra->parent;
  fra->parent = NULL;

  glulx_free(fra);
}
Esempio n. 30
0
uint32_t cl_get_time_stamp_sec(void)
{
	struct timeval tv;

	timerclear(&tv);
	gettimeofday(&tv, NULL);

	return (tv.tv_sec);
}