/** * Returns elapsed wall clock */ struct timeval logger_get_wallclock(logger_t logger) { struct timeval end, diff; gettimeofday(&end, NULL); _timeval_subtract(&diff, &end, &logger->wallclock_start); return diff; }
/** * Returns elapsed usertime */ struct timeval logger_get_usertime(logger_t logger) { struct rusage resource_usage; struct timeval diff; getrusage(RUSAGE_SELF, &resource_usage); _timeval_subtract(&diff, &resource_usage.ru_utime, &logger->usertime_start); return diff; }
static int udpm_self_test (lcm_udpm_t *lcm) { int success = 0; int status; // register a handler for the self test message lcm_subscription_t *h = lcm_subscribe (lcm->lcm, "LCM_SELF_TEST", self_test_handler, &success); // transmit a message char *msg = "lcm self test"; lcm_udpm_publish (lcm, "LCM_SELF_TEST", (uint8_t*)msg, strlen (msg)); // wait one second for message to be received GTimeVal now, endtime; g_get_current_time(&now); endtime.tv_sec = now.tv_sec + 10; endtime.tv_usec = now.tv_usec; // periodically retransmit, just in case GTimeVal retransmit_interval = { 0, 100000 }; GTimeVal next_retransmit; _timeval_add (&now, &retransmit_interval, &next_retransmit); int recvfd = lcm_udpm_get_fileno (lcm); do { GTimeVal selectto; _timeval_subtract (&next_retransmit, &now, &selectto); fd_set readfds; FD_ZERO (&readfds); FD_SET (recvfd,&readfds); g_get_current_time(&now); if (_timeval_compare (&now, &next_retransmit) > 0) { status = lcm_udpm_publish (lcm, "LCM_SELF_TEST", (uint8_t*)msg, strlen (msg)); _timeval_add (&now, &retransmit_interval, &next_retransmit); } status=select (recvfd + 1,&readfds,0,0, (struct timeval*) &selectto); if (status > 0 && FD_ISSET (recvfd,&readfds)) { lcm_udpm_handle (lcm); } g_get_current_time(&now); } while (! success && _timeval_compare (&now, &endtime) < 0); lcm_unsubscribe (lcm->lcm, h); dbg (DBG_LCM, "LCM: self test complete\n"); // if the self test message was received, then the handler modified the // value of success to be 1 return (success == 1)?0:-1; }