Пример #1
0
static char* test_reset()
{
    load_histograms();

    // before
    mu_assert("Value at 99% == 0.0", hdr_value_at_percentile(raw_histogram, 99.0) != 0);
    mu_assert("Value at 99% == 0.0", hdr_value_at_percentile(cor_histogram, 99.0) != 0);

    hdr_reset(raw_histogram);
    hdr_reset(cor_histogram);

    //after
    mu_assert("Total raw count != 0",       raw_histogram->total_count == 0);
    mu_assert("Total corrected count != 0", cor_histogram->total_count == 0);

    mu_assert("Value at 99% not 0.0", hdr_value_at_percentile(raw_histogram, 99.0) == 0);
    mu_assert("Value at 99% not 0.0", hdr_value_at_percentile(cor_histogram, 99.0) == 0);

    return 0;
}
Пример #2
0
ERL_NIF_TERM _hh_reset(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    hh_ctx_t* ctx = NULL;

    ErlNifResourceType* ctx_type = get_hh_ctx_type(env);
    if (ctx_type != NULL &&
        !enif_get_resource(env, argv[0], ctx_type, (void **)&ctx))
    {
        return enif_make_badarg(env);
    }

    if (ctx != NULL && ctx->data != NULL)
    {
        hdr_reset(ctx->data);
        return ATOM_OK;
    }

    return make_error(env, "bad_hdr_histogram_nif_impl");
}
Пример #3
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);
} 
Пример #4
0
int main(int argc, char** argv)
{
    struct timespec timestamp;
    struct timespec start_timestamp;
    struct timespec end_timestamp;
    struct hdr_interval_recorder recorder;
    struct hdr_log_writer log_writer;
    struct config_t config;
    pthread_t recording_thread;
    FILE* output = stdout;

    memset(&config, 0, sizeof(struct config_t));
    if (!handle_opts(argc, argv, &config))
    {
        printf("%s", USAGE);
        return 0;
    }

    if (config.filename)
    {
        output = fopen(config.filename, "a+");
        if (!output)
        {
            fprintf(
                stderr, "Failed to open/create file: %s, %s", 
                config.filename, strerror(errno));

            return -1;
        }
    }

    if (0 != hdr_interval_recorder_init(&recorder))
    {
        fprintf(stderr, "%s\n", "Failed to init phaser");
        return -1;
    }

    if (0 != hdr_init(
        1, INT64_C(24) * 60 * 60 * 1000000, 3,
        (struct hdr_histogram**) &recorder.active))
    {
        fprintf(stderr, "%s\n", "Failed to init hdr_histogram");
        return -1;
    }

    if (0 != hdr_init(
        1, INT64_C(24) * 60 * 60 * 1000000, 3,
        (struct hdr_histogram**) &recorder.inactive))
    {
        fprintf(stderr, "%s\n", "Failed to init hdr_histogram");
        return -1;
    }

    if (pthread_create(&recording_thread, NULL, record_hiccups, &recorder))
    {
        fprintf(stderr, "%s\n", "Failed to create thread");
        return -1;
    }

    hdr_gettime(&start_timestamp);
    hdr_log_writer_init(&log_writer);
    hdr_log_write_header(&log_writer, output, "foobar", &timestamp);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true)
    {        
        sleep(config.interval);

        hdr_reset(recorder.inactive);
        struct hdr_histogram* h = hdr_interval_recorder_sample(&recorder);

        hdr_gettime(&end_timestamp);
        timestamp = start_timestamp;

        hdr_gettime(&start_timestamp);

        hdr_log_write(&log_writer, output, &timestamp, &end_timestamp, h);
        fflush(output);
    }
#pragma clang diagnostic pop

    pthread_exit(NULL);
}