Пример #1
0
/*
 ******************************************************************************
 * Function : time_is_reached
 *
 * Abstract : Check if given time is reached (current_time >= given_time)
 *
 * Decisions : None
 *
 * Input  : p_time  The expiry date
 *
 * Output : None
 *
 * Return : True  the date is reached,
 *          False the date is not reached yet.
 *
 * Errors : None
 *
 * History :
 *
 *******************************************************************************
*/
bool time_is_reached (timeout_t *p_time)
{
    timeout_t current_time;

    /* Get current time */
    get_time (&current_time);

    /* reached if time_current >= time */
    return (comp_time (&current_time, p_time) >= 1);
}
Пример #2
0
void timer_malloc() {

	char* mem_list[10000];

    struct timeval time_start, time_end;
    int j,i;

    j = gettimeofday (&time_start, (void *)NULL);
	for (i = 0; i < 10000; i++){
		mem_list[i] = malloc(64);
	}
	for (i = 0; i < 10000; i++){
		free(mem_list[i]);
	}
    j = gettimeofday (&time_end, (void *)NULL);
    fprintf (stderr, "Time taken for mallocs =  %f msec\n",
	     comp_time (time_start, time_end)/1000.0);

}
Пример #3
0
int main (int argc, char **argv)
{
  int j, i;
  struct timeval times, timee;
  void *b[55];
  struct itimerval interval;
  struct itimerval oldinterval;


  j = gettimeofday (&times, (void *)NULL);
  for (i=0; i<how; i++) {
    b[i] = (void*)malloc (i+1);
    free (b[i]);
}
  j = gettimeofday (&timee, (void *)NULL);
  fprintf (stderr, "MALLOC/FREE time took %f msec\n",
          comp_time (times, timee)/1000.0);

}
Пример #4
0
void timer_mm() {

	struct timeval time_start, time_end;
	int j,i;

	j = gettimeofday (&time_start, (void *)NULL);
	mm_t MM;
	if(mm_init (&MM, 10000, 64) == -1){
		perror("failed to initialize mm");
	}
	for (i = 0; i < 10000; i++){
		mm_get (&MM);
	}
	for (i = 0; i < 10000; i++){
		mm_put (&MM, (void*) (MM.blocks + i * MM.size));
	}
	mm_release(&MM);
	j = gettimeofday (&time_end, (void *)NULL);
	fprintf (stderr, "Time taken for MM =  %f msec\n",
		 comp_time (time_start, time_end)/1000.0);
}
Пример #5
0
int main() {
	
	struct timeval time_start, time_end;
    int j;
    void *test[10000];
    /* start timer */
    j = gettimeofday (&time_start, (void *)NULL);

	int i;
	for(i = 0; i<10000; i++)
		test[i] = malloc(40);
	for(i = 0; i<10000; i++)
		free(test[i]);
    
    j = gettimeofday (&time_end, (void *)NULL);

    fprintf (stderr, "Time taken =  %f msec\n",
	    comp_time (time_start, time_end)/1000.0);
	
    return 0;	
}
Пример #6
0
/* Main driver that tests the
 * clock time for our dynamic
 * memory allocator */
int main (int argc, char **argv)
{
	int i, j;
	struct timeval times, timee;
	mm_t MM;
	void *chunk = NULL;

	
	
	if (mm_init(&MM,NUM_CHUNKS, CHUNK_SIZE) < 0)
		fprintf(stderr, "Error in mm_init\n");
	j = gettimeofday (&times, (void *)NULL);
	for (i=0; i< ITERS; i++) { 
		chunk = mm_get(&MM);
		mm_put(&MM,chunk);
	}
	
	
	
	j = gettimeofday (&timee, (void *)NULL);
	mm_release(&MM);			/* release stuff on heap*/
	fprintf (stderr, "MM time took %f msec\n",comp_time (times, timee)/1000.0);
	return 0;
}
Пример #7
0
int main()
{
	mm_t mm;
	if(mm_init(&mm, 1000000, 64) == 0)
	{
		printf("success\n");
	}
  	gettimeofday (&time_s, NULL);
	mm_t *mmArray[1000000];
	int i;
	for (i = 0; i < 1000000; i++){
		if ((mmArray[i] = mm_get(&mm)) == NULL){
			printf("Failed to allocate i = %d\n", i);
		}
	}
	while (i > 0){
		i--;
		mm_put(&mm, mmArray[i]);
	}
  	gettimeofday(&time_e, NULL);
	mm_release(&mm);
  	fprintf(stderr, "main_mm duration = %f msec\n", comp_time(time_s, time_e) / 1000.0);
	return 0;
}
Пример #8
0
int main (int argc, char *argv[]) {

  timeout_t timeout;
  int timeout_ms;
  int accuracy_ms;
  soc_token soc = init_soc;
  soc_port port_no;
  char lan_name[80];
  synchro_msg_t synchro_msg;
  soc_length length;
  int cr, fd;
  boolean read;
  unsigned int travel_ms;

  timeout_t request_time, reply_time, travel_delta;
  timeout_t accuracy_timeout, wait_timeout;


  if ( (argc != 2) && (argc != 3) && (argc != 4) ) {
    fprintf (stderr, "SYNTAX error : Wrong number of arguments\n");
    USAGE();
    exit (1);
  }

  if (argc >= 3) {
    timeout_ms = atoi(argv[2]);
    if (timeout_ms <= 0) {
      fprintf (stderr, "SYNTAX error : Wrong timeout value\n");
      USAGE();
      exit (1);
    }
  } else {
    timeout_ms = DEFAULT_TIMEOUT_MS;
  }
  wait_timeout.tv_sec = timeout_ms / 1000; 
  wait_timeout.tv_usec = (timeout_ms % 1000) * 1000;

  if (argc == 4) {
    accuracy_ms = atoi(argv[3]);
    if (accuracy_ms <= 0) {
      fprintf (stderr, "SYNTAX error : Wrong accuracy value\n");
      USAGE();
      exit (1);
    }
  } else {
    accuracy_ms = DEFAULT_ACCURACY_MS;
  }
  accuracy_timeout.tv_sec = accuracy_ms / 1000;
  accuracy_timeout.tv_usec = (accuracy_ms % 1000) * 1000;


  if (soc_get_local_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) {
    perror ("getting lan name");
    exit (1);
  }

  if (soc_open(&soc, udp_socket) != SOC_OK) {
    perror ("opening socket");
    exit (1);
  }

  port_no = atoi(argv[1]);
  if (port_no <= 0) {
    if (soc_set_dest_name_service(soc, lan_name, true, argv[1]) != SOC_OK) {
      perror ("setting destination service");
      exit (1);
    }
  } else {
    if (soc_set_dest_name_port(soc, lan_name, true, port_no) != SOC_OK) {
      perror ("setting destination port");
      exit (1);
    }
  }

  if (soc_get_dest_port(soc, &port_no) != SOC_OK) {
    perror ("getting destination port no");
    exit (1);
  }

  if (soc_link_port(soc, port_no) != SOC_OK) {
    perror ("linking socket");
    exit (1);
  }

  /* List for wait */
  if (soc_get_id(soc, &fd) != SOC_OK) {
    perror ("getting socket id");
    exit (1);
  }
  if (evt_add_fd(fd, TRUE) != WAIT_OK) {
    perror("Adding fd");
    exit (1);
  }

  for (;;) {
    synchro_msg.magic_number = magic_request_value;
    get_time (&(synchro_msg.request_time));

    cr = soc_send (soc, (soc_message) &synchro_msg, sizeof(synchro_msg));
    if (cr != SOC_OK) {
      perror ("sending request");
      exit (1);
    }

    request_time = synchro_msg.request_time;

    for (;;) {

      timeout = wait_timeout;
      if (evt_wait (&fd, &read, &timeout) != WAIT_OK) {
        perror ("waiting for event");
        exit (1);
      }

      if (fd == NO_EVENT) {
        printf ("Timeout expired. Giving up.\n");
        exit (2);
      } else if (fd <= 0) {
        /* Other non fd event */
        continue;
      }

      length = sizeof (synchro_msg);
      cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE);
      get_time (&reply_time);

      if ( cr == sizeof (synchro_msg) ) {
        if (synchro_msg.magic_number == magic_request_value) {
          ;
        } else if ( (synchro_msg.magic_number == magic_reply_value)
                 && (synchro_msg.request_time.tv_sec == request_time.tv_sec)
                 && (synchro_msg.request_time.tv_usec == request_time.tv_usec) ) {

          travel_delta = reply_time;
          (void) sub_time (&travel_delta, &request_time);
          if (comp_time(&travel_delta, &accuracy_timeout) > 0) {
              printf ("Insuficient accuracy. Skipping...\n");
              break;
          }

          /* Compute time (reply + travel/2) and settimofday */
          travel_ms = travel_delta.tv_sec * 1000;
          travel_ms += travel_delta.tv_usec / 1000;
          incr_time (&synchro_msg.server_time, travel_ms / 2);

          (void) sub_time (&reply_time, &synchro_msg.server_time);
          printf ("Synchro %ld.%06d s\n", reply_time.tv_sec,
                                         (int)reply_time.tv_usec);

          if (settimeofday (&synchro_msg.server_time, NULL) < 0) {
             perror ("settimeofday");
             exit (1);
          }
          exit (0);
        } else {
          fprintf (stderr, "Error : wrong reply received");
        }

      } else if (cr != SOC_OK) {
        perror ("receiving reply");
      } else {
        fprintf (stderr, "Error : wrong reply received");
      }
    }

    /* Reset dest */
    if (soc_set_dest_name_port(soc, lan_name, true, port_no) != SOC_OK) {
      perror ("linking socket");
      exit (1);
    }
  }
}
Пример #9
0
//---------------------------------------------------------
SG_Char *CSG_Formula::i_trans(SG_Char *function, SG_Char *begin, SG_Char *end)
{
	int pars;     
	SG_Char *scan;
	SG_Char *tempu, *temp3;
	SG_Char *temps	= NULL;
	SG_Char tempch;
	double tempd;
	SG_Char *endf;     
	
	int n_function;
	int space;
	int i;
	
	SG_Char *paramstr[MAX_PARMS];
	SG_Char *par_buf;
	
	if (begin >= end)
	{
		_Set_Error(LNG("missing operand"));
		i_error = begin;
		return NULL;
	}
	
	for (pars = 0, scan = begin; scan < end && pars >= 0; scan++)
	{
		if (*scan == SG_T('(')) pars++;
		else if (*scan == SG_T(')'))
			pars--;
	}
	if (pars < 0 || pars > 0)
	{
		_Set_Error(LNG("unmatched parentheses"));
		i_error = scan - 1;
		return NULL;
	}
	
	for (pars = 0, scan = end - 1; scan >= begin; scan--)
	{
		if (*scan == SG_T('(')) pars++;
		else if (*scan == SG_T(')'))
			pars--;
		else if (!pars &&(*scan == SG_T('+') ||((*scan == SG_T('-')) && scan != begin))
			&&(scan == begin || *(scan - 1) != SG_T('E')))
			break;
	}
	
	if (scan >= begin)
	{                                 
		if ((tempu = i_trans(function, begin, scan)) &&      
			(temp3 = i_trans(tempu, scan + 1, end)))
		{
			*temp3++ = *scan; 
			temp3 = comp_time(function, temp3, 2); 
			if( m_bError )
				return NULL;   
			else 
				return temp3;  
		}
		else 
			return NULL;  
	}
	
	for (pars = 0, scan = end - 1; scan >= begin; scan--)
	{
		if (*scan == SG_T('(')) pars++;
		else if (*scan == SG_T(')'))
			pars--;
		else if (!pars &&(*scan == SG_T('*') || *scan == SG_T('/')))
			break;
	}
	if (scan >= begin)
	{                                 
		if ((tempu = i_trans(function, begin, scan)) &&      
			(temp3 = i_trans(tempu, scan + 1, end)))
		{
			*temp3++ = *scan; 
			temp3 = comp_time(function, temp3, 2); 
			if (m_bError)
				return NULL;   
			else 
				return temp3;  
		}
		else 
			return NULL;  
	}
	
	/* unary minus */
	if (*begin == SG_T('-'))
	{
		tempu = i_trans(function, begin + 1, end);
		if (tempu)
		{
			*tempu++ = SG_T('M');
			tempu = comp_time(function, tempu, 1); 
			if (m_bError)
				return NULL; 
			else 
				return tempu;
		}
		else 
			return NULL;
	}
	
	for (pars = 0, scan = end - 1; scan >= begin; scan--)
	{
		if (*scan == SG_T('(')) pars++;
		else if (*scan == SG_T(')'))
			pars--;
		else if (!pars &&(*scan == SG_T('^')))
			break;
		else if (!pars &&(*scan == SG_T('=')))
			break;
		else if (!pars &&(*scan == SG_T('>')))
			break;
		else if (!pars &&(*scan == SG_T('<')))
			break;
		else if (!pars &&(*scan == SG_T('&')))
			break;
		else if (!pars &&(*scan == SG_T('|')))
			break;
	}

	if (scan >= begin)
	{                                 
		if ((tempu = i_trans(function, begin, scan)) &&      
			(temp3 = i_trans(tempu, scan + 1, end)))
		{
			*temp3++ = *scan; 
			temp3 = comp_time(function, temp3, 2); 
			if (m_bError)
				return NULL;   
			else 
				return temp3;  
		}
		else 
			return NULL;  
	}
	
	/* erase white space */
	while (isspace(*begin))
		begin++;
	while (isspace(*(end - 1)))
		end--;
	
	if (*begin == SG_T('(') && *(end - 1) == SG_T(')'))
		return i_trans(function, begin + 1, end - 1);
	
	if (end == begin + 1 && islower(*begin))
	{
		*function++ = SG_T('V');
		*function++ = *begin;
		return function;
	}
	
	tempch = *end;
	*end = SG_T('\0');
	tempd = SG_STR_TOD(begin, (SG_Char**) &tempu);
	*end = tempch;
	if ((SG_Char*) tempu == end)
	{
		*function++ = SG_T('D');
		if (i_pctable < MAX_CTABLE)
		{
			i_ctable[i_pctable] = tempd;
			*function++ =(SG_Char) i_pctable++;
		}
		else
		{
			_Set_Error(LNG("too many constants"));
			i_error = begin;
			return NULL;
		}
		return function;
	}
	
				/*function*/
	if (!isalpha(*begin) && *begin != SG_T('_'))
	{
		_Set_Error(LNG("syntax error"));
		i_error = begin;
		return NULL;
	}
	for (endf = begin + 1; endf < end &&(isalnum(*endf) || *endf == SG_T('_'));
	endf++)
		;
	tempch = *endf;
	*endf = SG_T('\0');
	if ((n_function = _Get_Function(begin)) == -1)
	{
		*endf = tempch;
		i_error = begin;
		return NULL;
	}
	*endf = tempch;
	if (*endf != SG_T('(') || *(end - 1) != SG_T(')'))
	{
		_Set_Error(LNG("improper function syntax"));
		i_error = endf;
		return NULL;
	}
	if (gSG_Functions[n_function].n_pars == 0)
	{
		/*function without parameters(e.g. pi()) */
		space = 1;
		for (scan = endf + 1; scan <(end - 1); scan++)
			if (!isspace(*scan))
				space = 0;
			if (space)
			{
				*function++ = SG_T('F');
				*function++ = n_function;
				function = comp_time(function - 2, function, 0);
				if (m_bError)
					return NULL; /* internal error in comp_time */
				else 
					return function;
			}
			else 
			{
				i_error = endf + 1;
				_Set_Error(LNG("too many parameters"));
				return NULL;
			}
	}
	else 
	{	/*function with parameters*/
		tempch = *(end - 1);
		*(end - 1) = SG_T('\0');
		par_buf =(SG_Char *) SG_Malloc(sizeof(SG_Char) * (SG_STR_LEN(endf + 1) + 1));

		if (!par_buf)
		{    
			_Set_Error(LNG("no memory")); 
			i_error = NULL;  
			return NULL;   
		}
		
		SG_STR_CPY(par_buf, endf + 1);
		*(end - 1) = tempch;
		
		for (i = 0; i < gSG_Functions[n_function].n_pars; i++)
		{
			if ((temps = my_strtok((i == 0) ? par_buf : NULL)) == NULL)
				break; 
			paramstr[i] = temps;
		}

		if (temps == NULL)
		{
			SG_Free(par_buf);
			i_error = end - 2;
			_Set_Error(LNG("too few parameters"));
			return NULL;
		}

		if ((temps = my_strtok(NULL)) != NULL)
		{
			SG_Free(par_buf);
			i_error =(temps - par_buf) +(endf + 1); 
			_Set_Error(LNG("too many parameters"));
			return NULL;
		}
		
		tempu = function;
		for (i = 0; i < gSG_Functions[n_function].n_pars; i++)
			if( !(tempu = i_trans(tempu, paramstr[i], paramstr[i] + SG_STR_LEN(paramstr[i]))) )
			{
				i_error =(i_error - par_buf) +(endf + 1); 
				SG_Free(par_buf);
				
				return NULL; 
			}

		/* OK */
		SG_Free(par_buf);
		*tempu++ = SG_T('F');
		*tempu++ = n_function;
		tempu = comp_time(function, tempu, gSG_Functions[n_function].n_pars);
		if (m_bError)
			return NULL; /* internal error in comp_time */
		else 
			return tempu;
	}
}