Microbenchmark for our new/delete hooks which track process-wide memory consumption.
| 36 | // Microbenchmark for our new/delete hooks which track process-wide |
| 37 | // memory consumption. |
| 38 | TEST(ProcessMemory, BenchmarkConsumptionTracking) { |
| 39 | const int kNumThreads = 200; |
| 40 | vector<thread> threads; |
| 41 | atomic<bool> done(false); |
| 42 | atomic<int64_t> total_count(0); |
| 43 | |
| 44 | // We start many threads, each of which performs 10:1 ratio of |
| 45 | // new/delete pairs to consumption lookups. The high number |
| 46 | // of threads highlights when there is contention on central |
| 47 | // tcmalloc locks. |
| 48 | for (int i = 0; i < kNumThreads; i++) { |
| 49 | threads.emplace_back([&]() { |
| 50 | int64_t local_count = 0; |
| 51 | while (!done) { |
| 52 | for (int a = 0; a < 10; a++) { |
| 53 | // Mark 'x' volatile so that the compiler does not optimize out the |
| 54 | // allocation. |
| 55 | char* volatile x = new char[8000]; |
| 56 | delete[] x; |
| 57 | } |
| 58 | process_memory::CurrentConsumption(); |
| 59 | local_count++; |
| 60 | } |
| 61 | total_count += local_count; |
| 62 | }); |
| 63 | } |
| 64 | double secs = 3; |
| 65 | SleepFor(MonoDelta::FromSeconds(secs)); |
| 66 | done = true; |
| 67 | |
| 68 | for (auto& t : threads) { |
| 69 | t.join(); |
| 70 | } |
| 71 | |
| 72 | LOG(INFO) << "Performed " << total_count / secs << " iters/sec"; |
| 73 | } |
| 74 | |
| 75 | } // namespace kudu |
nothing calls this directly
no test coverage detected