| 577 | } |
| 578 | |
| 579 | void PerfTest(int thread_num, const std::string& log, bool async) { |
| 580 | FLAGS_async_log = async; |
| 581 | |
| 582 | g_started = false; |
| 583 | g_stopped = false; |
| 584 | pthread_t threads[thread_num]; |
| 585 | std::vector<PerfArgs> args(thread_num); |
| 586 | for (int i = 0; i < thread_num; ++i) { |
| 587 | args[i].log = &log; |
| 588 | ASSERT_EQ(0, pthread_create(&threads[i], NULL, test_log, &args[i])); |
| 589 | } |
| 590 | while (true) { |
| 591 | bool all_ready = true; |
| 592 | for (int i = 0; i < thread_num; ++i) { |
| 593 | if (!args[i].ready) { |
| 594 | all_ready = false; |
| 595 | break; |
| 596 | } |
| 597 | } |
| 598 | if (all_ready) { |
| 599 | break; |
| 600 | } |
| 601 | usleep(1000); |
| 602 | } |
| 603 | int sleep_s = 2; |
| 604 | g_started = true; |
| 605 | char prof_name[32]; |
| 606 | snprintf(prof_name, sizeof(prof_name), "logging_%d.prof", ++g_prof_name_counter); |
| 607 | ProfilerStart(prof_name); |
| 608 | sleep(sleep_s); |
| 609 | ProfilerStop(); |
| 610 | g_stopped = true; |
| 611 | int64_t wait_time = 0; |
| 612 | int64_t count = 0; |
| 613 | for (int i = 0; i < thread_num; ++i) { |
| 614 | pthread_join(threads[i], NULL); |
| 615 | wait_time += args[i].elapse_ns; |
| 616 | count += args[i].counter; |
| 617 | } |
| 618 | std::cout << " thread_num=" << thread_num |
| 619 | << " log_type=" << (async ? "async" : "sync") |
| 620 | << " log_size=" << log.size() |
| 621 | << " count=" << count |
| 622 | << " duration=" << sleep_s << "s" |
| 623 | << " qps=" << (int)(count / (double)sleep_s) |
| 624 | << " average_time=" << wait_time / (double)count << "us" |
| 625 | << std::endl; |
| 626 | } |
| 627 | |
| 628 | TEST_F(LoggingTest, performance) { |
| 629 | bool saved_async_log = FLAGS_async_log; |
no test coverage detected