예제 #1
0
파일: logger.cpp 프로젝트: benlangfeld/sipp
/* Function to dump all available screens in a file */
void print_screens(void)
{
    int oldScreen = currentScreenToDisplay;
    int oldRepartition = currentRepartitionToDisplay;

    currentScreenToDisplay = DISPLAY_SCENARIO_SCREEN;
    print_header_line(   screenf);
    print_stats_in_file( screenf);
    print_bottom_line(   screenf, NOTLAST);

    currentScreenToDisplay = DISPLAY_STAT_SCREEN;
    print_header_line(   screenf);
    display_scenario->stats->displayStat(screenf);
    print_bottom_line(   screenf, NOTLAST);

    currentScreenToDisplay = DISPLAY_REPARTITION_SCREEN;
    print_header_line(   screenf);
    display_scenario->stats->displayRepartition(screenf);
    print_bottom_line(   screenf, NOTLAST);

    currentScreenToDisplay = DISPLAY_SECONDARY_REPARTITION_SCREEN;
    for (currentRepartitionToDisplay = 2; currentRepartitionToDisplay <= display_scenario->stats->nRtds(); currentRepartitionToDisplay++) {
        print_header_line(   screenf);
        display_scenario->stats->displayRtdRepartition(screenf, currentRepartitionToDisplay);
        print_bottom_line(   screenf, NOTLAST);
    }

    currentScreenToDisplay = oldScreen;
    currentRepartitionToDisplay = oldRepartition;
}
예제 #2
0
int main ( int argc, char *argv[] )
{
     unsigned long int microdelta, interval_length, interval_diff, sample_desired_wait_time;
     int nfds,return_value, delay_microseconds, run_seconds, total_runtime_seconds;
     int fd, opt, quit=0;
     char buffer[128];
     char identifier[IDENTIFIER_SIZE];

     struct pollfd poll_list[256];
     struct itimerspec timeout;     
     struct timespec sample_start_time, sample_end_time, interval_start;
     struct timeval end;

     struct hdr_histogram *interval_histogram, *cumulative_histogram;
     
     // 10 seconds worth of microseconds 
     if (hdr_alloc(10000000, 3, &interval_histogram) == -1) {
	  printf("unable to allocate interval histogram\n");
	  exit (1);
     }
     if (hdr_alloc(10000000, 3, &cumulative_histogram) == -1) {
	  printf("unable to allocate cumulative histogram\n");
	  exit (1);
     }

     memset (buffer, 0, 128);
     memset (identifier, 0, IDENTIFIER_SIZE);
     
     // Timing and names
     // 
     // interval_length 		- this is the length of time between successive histogram line printouts
     // 
     // sample_desired_wait_time 	- this is the amount of time we set the timer to wait for. This should be 
     //               			  less than the jitter we're attempting to measure. Given the nature of this 
     //               			  program, this should always be less than 1 second. If it is not, you'll need to 
     //               			  modify the code below where we set the interval timer.  
     // sample_start_time, 
     // sample_end_time 		- The times associated with a single pass through the timing loop.
     // 
     // delay_microseconds	       	- An arbitrary amount of time we wait before starting anything. This is useful if
     // 				  you want to catch something, and there's a warm up period.
     // 				  For compatibility with jHiccup this is specified on the command line as millis. 
     // 
     // run_seconds			- The time we spend running the timing loops. 
     // 
     
     interval_length = 5;  			// 5 seconds per reporting interval 
     sample_desired_wait_time = 1000000; 	// 1 millisecond in nanoseconds.
     delay_microseconds = 0;
     run_seconds = 100000000;                   // forever, or near enough - 3 years. 
     
     while ( (opt = getopt(argc, argv, "d:l:r:vh"))  != -1) {
	  switch (opt) {
	  case 'd':
	       delay_microseconds = atoi(optarg) * 1000;
	       break;
	  case 'l':
	       strncpy(identifier, optarg, IDENTIFIER_SIZE-1);
	       break;
	  case 'r':
	       run_seconds = atoi(optarg);
	       break;
	  case 'v':
	       verbose_flag = 1;
	       break;
	  case 'h':
	  default:
	       usage();
	       exit(-1);
	  }
     }
     
     total_runtime_seconds = run_seconds + (delay_microseconds/1000000);
     
     open_files(identifier);
     
     if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC)) < 0) {
	  perror("timerfd_create; failed to create timer");
	  return -1;
     }
     
     zero_timeout(&timeout);
     interval_length = interval_length * 1000000000;  // convert to nanoseconds

     // set up the poll list structure. 
     memset (&poll_list, 0, (256*sizeof(struct pollfd)));
 
     poll_list[0].fd=fd;
     poll_list[0].events=POLLIN|POLLPRI|POLLRDHUP;
     poll_list[0].revents=0;
     nfds = 1;

     // get wall clock start time and push out a header 
     gettimeofday(&start,NULL);   
     print_header_line(log_file, &start);
     if (verbose_flag) print_header_line(stdout, &start);
     
     // we wait a set number of seconds before starting the test. 
     usleep(delay_microseconds);
     // get start of our delta interval measurement
     clock_gettime(CLOCK_MONOTONIC, &interval_start);
     
     while (!quit) {
	  timeout.it_value.tv_sec = 0;
	  timeout.it_value.tv_nsec = sample_desired_wait_time;
	  
	  // We arm the timer first (timerfd_settime), then get the time as quickly as possible. 
	  // We don't want to measure the time that timerfd_settime takes, so its a choice between
	  // under or over reporting the time, as clock_gettime is expected to be fast. 
	  timerfd_settime(fd, 0, &timeout, NULL);
	  clock_gettime(CLOCK_MONOTONIC,&sample_start_time);
	  return_value = poll(poll_list,nfds,-1);
	  clock_gettime(CLOCK_MONOTONIC,&sample_end_time);

	  // the the error value is anything other than EINTR we have a real problem. 
	  if ((return_value < 0) && (errno != EINTR))  {
	       perror("poll problem");
	       exit(-1);
	  }
	  
	  // read the timer to clear the event.
	  read(fd,buffer,8);
	  
	  // record the delta for both the interval and cumulative histograms. 
	  microdelta = nano_difftime(sample_start_time, sample_end_time)/1000;
	  
	  hdr_record_value(interval_histogram, microdelta);
	  hdr_record_value(cumulative_histogram, microdelta);

	  // See if we're due to print out an interval update. 
	  interval_diff = nano_difftime(interval_start, sample_end_time);
	  
	  if (interval_diff >= interval_length) {
	       // print progress
	       print_histogram_line(log_file, interval_histogram, cumulative_histogram);
	       if (verbose_flag) print_histogram_line(stdout, interval_histogram, cumulative_histogram);
	       print_full_histogram(histogram_file,cumulative_histogram);
	       // are we done?
	       gettimeofday(&end, NULL);
	       if (end.tv_sec >= (start.tv_sec + total_runtime_seconds)) quit++;
	       // reset the interval histogram.
	       hdr_reset(interval_histogram);
	       // reset the interval start timer. 
	       clock_gettime(CLOCK_MONOTONIC, &interval_start);
	  }
     }
     
     close(fd);
     
     exit (0);
} 
예제 #3
0
파일: logger.cpp 프로젝트: benlangfeld/sipp
void print_statistics(int last)
{
    static int first = 1;
    extern int command_mode;
    extern char *command_buffer;

    if(backgroundMode == false && display_scenario) {
        if(!last) {
            screen_clear();
        }

        if(first) {
            first = 0;
            printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
                   "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
        }
        if (command_mode) {
            printf(SIPP_ENDL);
        }
        print_header_line(stdout);
        switch(currentScreenToDisplay) {
        case DISPLAY_STAT_SCREEN :
            display_scenario->stats->displayStat(stdout);
            break;
        case DISPLAY_REPARTITION_SCREEN :
            display_scenario->stats->displayRepartition(stdout);
            break;
        case DISPLAY_VARIABLE_SCREEN  :
            print_variable_list();
            break;
        case DISPLAY_TDM_MAP_SCREEN  :
            print_tdm_map();
            break;
        case DISPLAY_SECONDARY_REPARTITION_SCREEN :
            display_scenario->stats->displayRtdRepartition(stdout, currentRepartitionToDisplay);
            break;
        case DISPLAY_SCENARIO_SCREEN :
        default:
            print_stats_in_file(stdout);
            break;
        }
        print_bottom_line(stdout,last);
        if (!last && screen_last_error[0]) {
            char *errstart = screen_last_error;
            int colonsleft = 3;/* We want to skip the time. */
            while (*errstart && colonsleft) {
                if (*errstart == ':') {
                    colonsleft--;
                }
                errstart++;
            }
            while (isspace(*errstart)) {
                errstart++;
            }
            if (strlen(errstart) > 60) {
                printf("Last Error: %.60s..." SIPP_ENDL, errstart);
            } else {
                printf("Last Error: %s" SIPP_ENDL, errstart);
            }
            sipp_usleep(100);
            fflush(stdout);
        }
        if (command_mode) {
            printf("Command: %s", command_buffer ? command_buffer : "");
            fflush(stdout);
        }
        if(last) {
            fprintf(stdout,"\n");
        }
    }
}
예제 #4
0
/* Print the stats for one call */
void
print_call (call_data cd)
{
	/* reprint the header every 20 lines */
	if (print_count == 0)
	{
		print_header_line();
	}
	print_count++;
	if (print_count == 20)
	{
		print_count = 0;
	}

	/* convert timeout id to string */
	char * timeout = "yes-NC";
	int i = 0;

	if (cd.c_timeout == 1)
	{
		timeout = "yes-C";
	}
	else if (cd.c_timeout == 2)
	{
		timeout = "yes-NC";
	}
	else if (cd.c_timeout == -1)
	{
		timeout = "NA";
	}
	else
	{
		timeout = "no";
	}

	/* print out a row of stats 
	 * one row = one call */
	if (cd.c_call_id != -1)
	{
		printf(print_info[i].data_frmt, cd.c_call_id);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_conn_id  != -1)
	{
		printf(print_info[i].data_frmt, cd.c_conn_id);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_size != -1)
	{
		printf(print_info[i].data_frmt, cd.c_size);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_bytes_recvd != -1)
	{
		printf(print_info[i].data_frmt, cd.c_bytes_recvd);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
  i++;


	if (cd.c_perc_recvd != -1)
	{
		printf(print_info[i].data_frmt, cd.c_perc_recvd);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
  i++;

	if (cd.c_byte_rate != -1)
	{
		printf(print_info[i].data_frmt, cd.c_byte_rate);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_conn_time != -1)
	{
		printf(print_info[i].data_frmt, cd.c_conn_time);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_resp_time != -1)
	{
		printf(print_info[i].data_frmt, cd.c_resp_time);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_total_time != -1)
	{
		printf(print_info[i].data_frmt, cd.c_total_time);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_status != -1)
	{
		printf(print_info[i].data_frmt, cd.c_status);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	if (cd.c_time_lim != -1)
	{
		printf(print_info[i].data_frmt, cd.c_time_lim);
	}
	else
	{
		printf(print_info[i].hdr_frmt, print_info[i].data_blank);
	}
	i++;

	printf(print_info[i++].data_frmt, timeout);
	printf(print_info[i++].data_frmt, cd.c_name);
	printf("\n");
}