Ejemplo n.º 1
0
static char* test_scaling_equivalence()
{
    load_histograms();

    mu_assert(
            "Averages should be equivalent",
            compare_values(
                    hdr_mean(cor_histogram) * 512,
                    hdr_mean(scaled_cor_histogram),
                    0.000001));

    mu_assert(
            "Total count should be equivalent",
            compare_int64(
                    cor_histogram->total_count,
                    scaled_cor_histogram->total_count));

    int64_t expected_99th = hdr_value_at_percentile(cor_histogram, 99.0) * 512;
    int64_t scaled_99th = hdr_value_at_percentile(scaled_cor_histogram, 99.0);
    mu_assert(
            "99%'iles should be equivalent",
            compare_int64(
                    hdr_lowest_equivalent_value(cor_histogram, expected_99th),
                    hdr_lowest_equivalent_value(scaled_cor_histogram, scaled_99th)));

    mu_assert(
            "Max should be equivalent",
            compare_int64(hdr_max(cor_histogram) * 512, hdr_max(scaled_cor_histogram)));

    return 0;
}
char* test_get_total_count()
{
    load_histograms();
    mu_assert("Total count is 10,001", compare_int64(10001, raw_histogram->values.total_count));
    mu_assert("Total count is 20,000", compare_int64(20000, histogram->values.total_count));

    return 0;
}
char *test_scaling_equivalence() {
    load_histograms();

    mu_assert("total count should be the same",
              compare_int64(histogram->values.total_count, scaled_histogram->values.total_count));

    mu_assert("averages should be equivalent",
              compare_double(
                  hdr_dbl_mean(histogram) * 512,
                  hdr_dbl_mean(scaled_histogram),
                  hdr_dbl_mean(scaled_histogram) * 0.000001));

    mu_assert("99%'iles should be equivalent",
              compare_double(
                  hdr_dbl_highest_equivalent_value(scaled_histogram, hdr_dbl_value_at_percentile(histogram, 99.0)) * 512.0,
                  hdr_dbl_highest_equivalent_value(scaled_histogram, hdr_dbl_value_at_percentile(scaled_histogram, 99.0)),
                  hdr_dbl_highest_equivalent_value(
                      scaled_histogram, hdr_dbl_value_at_percentile(scaled_histogram, 99.0)) * 0.000001));

    mu_assert("Max should be equivalent",
              compare_double(
                  hdr_dbl_highest_equivalent_value(scaled_histogram, hdr_dbl_max(histogram) * 512),
                  hdr_dbl_max(scaled_histogram),
                  hdr_dbl_max(scaled_histogram) * 0.000001));

    mu_assert("total count should be the same",
              compare_int64(
                  post_corrected_histogram->values.total_count,
                  post_corrected_scaled_histogram->values.total_count));

    mu_assert("99%'iles should be equivalent",
              compare_double(
                  hdr_dbl_lowest_equivalent_value(
                      post_corrected_histogram, hdr_dbl_value_at_percentile(post_corrected_histogram, 99.0)) * 512.0,
                  hdr_dbl_lowest_equivalent_value(
                      post_corrected_scaled_histogram, hdr_dbl_value_at_percentile(post_corrected_scaled_histogram, 99.0)),
                  hdr_dbl_lowest_equivalent_value(
                      post_corrected_scaled_histogram,
                      hdr_dbl_value_at_percentile(post_corrected_scaled_histogram, 99.0)) * 0.000001));

    mu_assert("Max should be equivalent",
              compare_double(
                  hdr_dbl_highest_equivalent_value(
                      post_corrected_scaled_histogram, hdr_dbl_max(post_corrected_histogram)) * 512,
                  hdr_dbl_max(post_corrected_scaled_histogram),
                  hdr_dbl_max(post_corrected_scaled_histogram)));

    return 0;
}
Ejemplo n.º 4
0
static char* test_create()
{
    struct hdr_histogram* h = NULL;
    int r = hdr_init(1, 3600000000, 3, &h);
    size_t s = hdr_get_memory_size(h);

    mu_assert("Failed to allocate hdr_histogram", r == 0);
    mu_assert("Failed to allocate hdr_histogram", h != NULL);
    mu_assert("Incorrect array length", compare_int64(h->counts_len, 23552));
    mu_assert("Size is incorrect", compare_int64(s, 188520));

    free(h);

    return 0;
}
static char* test_bounds_check_on_decode()
{
    load_histograms();

    uint8_t* buffer = NULL;
    size_t len = 0;
    int rc = 0;
    struct hdr_histogram* actual = NULL;
    struct hdr_histogram* expected = cor_histogram;

    rc = hdr_encode_compressed(expected, &buffer, &len);
    mu_assert("Did not encode", validate_return_code(rc));

    rc = hdr_decode_compressed(buffer, len - 1, &actual);
    mu_assert("Should have be invalid", compare_int64(EINVAL, rc));
    mu_assert("Should not have built histogram", NULL == actual);

    return 0;
}
static char* decode_v0_log()
{
    const char* v1_log = "jHiccup-2.0.1.logV0.hlog";

    FILE* f = fopen(v1_log, "r");
    mu_assert("Can not open v1 log file", f != NULL);

    struct hdr_histogram* accum;
    hdr_init(1, INT64_C(3600000000000), 3, &accum);

    struct hdr_histogram* h = NULL;
    struct hdr_log_reader reader;
    hdr_timespec timestamp;
    hdr_timespec interval;

    hdr_log_reader_init(&reader);

    int rc = hdr_log_read_header(&reader, f);
    mu_assert("Failed to read header", rc == 0);

    int histogram_count = 0;
    int64_t total_count = 0;
    while ((rc = hdr_log_read(&reader, f, &h, &timestamp, &interval)) != EOF)
    {
        mu_assert("Failed to read histogram", rc == 0);
        histogram_count++;
        total_count += h->total_count;
        int64_t dropped = hdr_add(accum, h);
        mu_assert("Dropped events", compare_int64(dropped, 0));

        free(h);
        h = NULL;
    }

    mu_assert("Wrong number of histograms", compare_int(histogram_count, 81));
    mu_assert("Wrong total count", compare_int64(total_count, 61256));
    mu_assert("99.9 percentile wrong", compare_int64(1510998015, hdr_value_at_percentile(accum, 99.9)));
    mu_assert("max value wrong", compare_int64(1569718271, hdr_max(accum)));
    mu_assert("Seconds wrong", compare_int64(1438869961, reader.start_timestamp.tv_sec));
    mu_assert("Nanoseconds wrong", compare_int64(225000000, reader.start_timestamp.tv_nsec));

    return 0;
}
static char* decode_v3_log()
{
    const char* v3_log = "jHiccup-2.0.7S.logV3.hlog";

    FILE* f = fopen(v3_log, "r");
    mu_assert("Can not open v3 log file", f != NULL);

    struct hdr_histogram* accum;
    hdr_init(1, INT64_C(3600000000000), 3, &accum);

    struct hdr_histogram* h = NULL;
    struct hdr_log_reader reader;
    hdr_timespec timestamp;
    hdr_timespec interval;

    hdr_log_reader_init(&reader);

    int rc = hdr_log_read_header(&reader, f);
    mu_assert("Failed to read header", validate_return_code(rc));

    int histogram_count = 0;
    int64_t total_count = 0;
    while ((rc = hdr_log_read(&reader, f, &h, &timestamp, &interval)) != EOF)
    {
        mu_assert("Failed to read histogram", validate_return_code(rc));
        histogram_count++;
        total_count += h->total_count;
        int64_t dropped = hdr_add(accum, h);
        mu_assert("Dropped events", compare_int64(dropped, 0));

        free(h);
        h = NULL;
    }

    mu_assert("Wrong number of histograms", compare_int(histogram_count, 62));
    mu_assert("Wrong total count", compare_int64(total_count, 48761));
    mu_assert("99.9 percentile wrong", compare_int64(1745879039, hdr_value_at_percentile(accum, 99.9)));
    mu_assert("max value wrong", compare_int64(1796210687, hdr_max(accum)));
    mu_assert("Seconds wrong", compare_int64(1441812279, reader.start_timestamp.tv_sec));
    mu_assert("Nanoseconds wrong", compare_int64(474000000, reader.start_timestamp.tv_nsec));

    return 0;
}
static char* log_reader_aggregates_into_single_histogram()
{
    const char* file_name = "histogram.log";
    hdr_timespec timestamp;
    hdr_timespec interval;

    hdr_gettime(&timestamp);
    interval.tv_sec = 5;
    interval.tv_nsec = 2000000;

    struct hdr_log_writer writer;
    struct hdr_log_reader reader;
    hdr_log_writer_init(&writer);
    hdr_log_reader_init(&reader);
    int rc = 0;

    FILE* log_file = fopen(file_name, "w+");

    hdr_log_write_header(&writer, log_file, "Test log", &timestamp);
    hdr_log_write(&writer, log_file, &timestamp, &interval, cor_histogram);
    hdr_log_write(&writer, log_file, &timestamp, &interval, raw_histogram);
    fflush(log_file);
    fclose(log_file);

    log_file = fopen(file_name, "r");

    struct hdr_histogram* histogram;
    hdr_alloc(INT64_C(3600) * 1000 * 1000, 3, &histogram);

    rc = hdr_log_read_header(&reader, log_file);
    mu_assert("Failed header read", validate_return_code(rc));
    rc = hdr_log_read(&reader, log_file, &histogram, NULL, NULL);
    mu_assert("Failed corrected read", validate_return_code(rc));
    rc = hdr_log_read(&reader, log_file, &histogram, NULL, NULL);
    mu_assert("Failed raw read", validate_return_code(rc));

    struct hdr_iter iter;
    hdr_iter_recorded_init(&iter, histogram);
    int64_t expected_total_count =
        raw_histogram->total_count + cor_histogram->total_count;

    mu_assert(
        "Total counts incorrect",
        compare_int64(histogram->total_count, expected_total_count));

    while (hdr_iter_next(&iter))
    {
        int64_t count = iter.count;
        int64_t value = iter.value;

        int64_t expected_count =
            hdr_count_at_value(raw_histogram, value) +
            hdr_count_at_value(cor_histogram, value);

        mu_assert("Incorrect count", compare_int64(count, expected_count));
    }

    fclose(log_file);
    remove(file_name);
    free(histogram);

    return 0;
}
Ejemplo n.º 9
0
/**	Fetches the property requested and uses the appropriate op on the value.
	@return boolean value
**/
static int compare_property_alt(OBJECT *obj, char *propname, FINDOP op, void *value){
	complex *complex_target = NULL;
	char *char_target = NULL;
	int16 *int16_target = NULL;
	int32 *int32_target = NULL;
	int64 *int64_target = NULL;
	PROPERTY *prop = object_get_property(obj, propname);

	if(prop == NULL){
		/* property not found in object ~ normal operation */
		return 0;
	}

	switch(prop->ptype){
		case PT_void:
			return 0;	/* no comparsion to be made */
		case PT_double:
			break;
		case PT_complex:
			complex_target = object_get_complex(obj, prop);
			if(complex_target == NULL)
				return 0; /* error value */
			break;
		case PT_enumeration:
		case PT_set:
			break;		/* not 100% sure how to make these cooperate yet */
		case PT_int16:
			int16_target = (int16 *)object_get_int16(obj, prop);
			if(int16_target == NULL)
				return 0;
			return compare_int16(*int16_target, op, *(int64 *)value);
		case PT_int32:
			int32_target = (int32 *)object_get_int32(obj, prop);
			return compare_int32(*int32_target, op, *(int64 *)value);
			break;
		case PT_int64:
			int64_target = (int64 *)object_get_int64(obj, prop);
			return compare_int64(*int64_target, op, *(int64 *)value);
			break;
		case PT_char8:
		case PT_char32:
		case PT_char256:
		case PT_char1024:
			char_target = (char *)object_get_string(obj, prop);
			if(char_target == NULL)
				return 0;
			return compare_string(char_target, op, value);
			break;
		case PT_object:

			break;
		case PT_bool:
			break;
		case PT_timestamp:
		case PT_double_array:
		case PT_complex_array:
			break;
#ifdef USE_TRIPLETS
		case PT_triple:
		case PT_triplex:
			break;
#endif
		default:
			output_error("comparison operators not supported for property type %s", class_get_property_typename(prop->ptype));
			/* TROUBLESHOOT
				This error is caused when an object find procedure uses a comparison operator
			that isn't allowed on a that type of property.  Make sure the property type
			and the comparison operator are compatible and try again.  If your GLM file
			isn't the cause of the problem, try reducing the complexity of the GLM file 
			you are using to isolate which module is causing the error and file a report 
			with the GLM file attached.
			 */
			return 0;
	}
}