OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 bool CheckMean(size_t mean, int num_samples) { | 351 bool CheckMean(size_t mean, int num_samples) { |
352 tcmalloc::Sampler sampler; | 352 tcmalloc::Sampler sampler; |
353 sampler.Init(1); | 353 sampler.Init(1); |
354 size_t total = 0; | 354 size_t total = 0; |
355 for (int i = 0; i < num_samples; i++) { | 355 for (int i = 0; i < num_samples; i++) { |
356 total += sampler.PickNextSamplingPoint(); | 356 total += sampler.PickNextSamplingPoint(); |
357 } | 357 } |
358 double empirical_mean = total / static_cast<double>(num_samples); | 358 double empirical_mean = total / static_cast<double>(num_samples); |
359 double expected_sd = mean / pow(num_samples * 1.0, 0.5); | 359 double expected_sd = mean / pow(num_samples * 1.0, 0.5); |
360 return(fabs(mean-empirical_mean) < expected_sd * kSigmas); | 360 return(abs(mean-empirical_mean) < expected_sd * kSigmas); |
361 } | 361 } |
362 | 362 |
363 // Prints a sequence so you can look at the distribution | 363 // Prints a sequence so you can look at the distribution |
364 void OutputSequence(int sequence_length) { | 364 void OutputSequence(int sequence_length) { |
365 tcmalloc::Sampler sampler; | 365 tcmalloc::Sampler sampler; |
366 sampler.Init(1); | 366 sampler.Init(1); |
367 size_t next_step; | 367 size_t next_step; |
368 for (int i = 0; i< sequence_length; i++) { | 368 for (int i = 0; i< sequence_length; i++) { |
369 next_step = sampler.PickNextSamplingPoint(); | 369 next_step = sampler.PickNextSamplingPoint(); |
370 LOG(INFO) << next_step; | 370 LOG(INFO) << next_step; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 // Now test that there are the right number of each | 403 // Now test that there are the right number of each |
404 double large_allocs_sds = | 404 double large_allocs_sds = |
405 StandardDeviationsErrorInSample(num_iters, counter_big, | 405 StandardDeviationsErrorInSample(num_iters, counter_big, |
406 size_big, kSamplingInterval); | 406 size_big, kSamplingInterval); |
407 double small_allocs_sds = | 407 double small_allocs_sds = |
408 StandardDeviationsErrorInSample(num_iters*129, counter_small, | 408 StandardDeviationsErrorInSample(num_iters*129, counter_small, |
409 size_small, kSamplingInterval); | 409 size_small, kSamplingInterval); |
410 LOG(INFO) << StringPrintf("large_allocs_sds = %f\n", large_allocs_sds); | 410 LOG(INFO) << StringPrintf("large_allocs_sds = %f\n", large_allocs_sds); |
411 LOG(INFO) << StringPrintf("small_allocs_sds = %f\n", small_allocs_sds); | 411 LOG(INFO) << StringPrintf("small_allocs_sds = %f\n", small_allocs_sds); |
412 CHECK_LE(fabs(large_allocs_sds), kSigmas); | 412 CHECK_LE(abs(large_allocs_sds), kSigmas); |
413 CHECK_LE(fabs(small_allocs_sds), kSigmas); | 413 CHECK_LE(abs(small_allocs_sds), kSigmas); |
414 } | 414 } |
415 | 415 |
416 // Tests whether the mean is about right over 1000 samples | 416 // Tests whether the mean is about right over 1000 samples |
417 TEST(Sampler, IsMeanRight) { | 417 TEST(Sampler, IsMeanRight) { |
418 CHECK(CheckMean(kSamplingInterval, 1000)); | 418 CHECK(CheckMean(kSamplingInterval, 1000)); |
419 } | 419 } |
420 | 420 |
421 // This flag is for the OldSampler class to use | 421 // This flag is for the OldSampler class to use |
422 const int64 FLAGS_mock_tcmalloc_sample_parameter = 1<<19; | 422 const int64 FLAGS_mock_tcmalloc_sample_parameter = 1<<19; |
423 | 423 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 648 } |
649 | 649 |
650 // Make sure sampling is enabled, or the tests won't work right. | 650 // Make sure sampling is enabled, or the tests won't work right. |
651 DECLARE_int64(tcmalloc_sample_parameter); | 651 DECLARE_int64(tcmalloc_sample_parameter); |
652 | 652 |
653 int main(int argc, char **argv) { | 653 int main(int argc, char **argv) { |
654 if (FLAGS_tcmalloc_sample_parameter == 0) | 654 if (FLAGS_tcmalloc_sample_parameter == 0) |
655 FLAGS_tcmalloc_sample_parameter = 524288; | 655 FLAGS_tcmalloc_sample_parameter = 524288; |
656 return RUN_ALL_TESTS(); | 656 return RUN_ALL_TESTS(); |
657 } | 657 } |
OLD | NEW |