Skip to content

Commit

Permalink
snapshot multithread test 6
Browse files Browse the repository at this point in the history
  • Loading branch information
pippocao committed Oct 9, 2024
1 parent ad87076 commit bdd2cbb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/bq_common/bq_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@
#include "bq_common/utils/property.h"
#include "bq_common/utils/property_ex.h"
#include "bq_common/utils/file_manager.h"


extern bq::platform::atomic<bool> cccc;
extern bq::platform::atomic<int32_t> cccc1;
extern bq::platform::atomic<int32_t> cccc2;
extern bq::platform::atomic<int32_t> cccc3;
extern bq::platform::atomic<int32_t> cccc4;
extern bq::platform::atomic<int32_t> cccc5;
extern bq::platform::atomic<int32_t> cccc6;
extern bq::platform::atomic<int32_t> cccc7;
9 changes: 9 additions & 0 deletions src/bq_common/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,12 @@ namespace bq {
return result_len;
}
}

bq::platform::atomic<bool> cccc = false;
bq::platform::atomic<int32_t> cccc1 = 0;
bq::platform::atomic<int32_t> cccc2 = 0;
bq::platform::atomic<int32_t> cccc3 = 0;
bq::platform::atomic<int32_t> cccc4 = 0;
bq::platform::atomic<int32_t> cccc5 = 0;
bq::platform::atomic<int32_t> cccc6 = 0;
bq::platform::atomic<int32_t> cccc7 = 0;
12 changes: 12 additions & 0 deletions src/bq_log/log/log_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,23 @@ namespace bq {

void log_snapshot::write_data(const bq::log_entry_handle& log_entry)
{
if (cccc.load()) {
cccc2.fetch_add(1);
}
if (log_level_bitmap_.have_level(log_entry.get_level()) && categories_mask_array_[log_entry.get_category_idx()]) {
if (cccc.load()) {
cccc3.fetch_add(1);
}
bq::platform::scoped_spin_lock scoped_lock(lock_);
if (snapshot_buffer_) {
while (true) {
bq::ring_buffer_write_handle snapshot_write_handle = snapshot_buffer_->alloc_write_chunk(log_entry.data_size());
if (snapshot_write_handle.result == enum_buffer_result_code::success) {
memcpy(snapshot_write_handle.data_addr, log_entry.data(), log_entry.data_size());
snapshot_buffer_->commit_write_chunk(snapshot_write_handle);
if (cccc.load()) {
cccc4.fetch_add(1);
}
break;
} else if (snapshot_write_handle.result == enum_buffer_result_code::err_not_enough_space) {
snapshot_buffer_->begin_read();
Expand Down Expand Up @@ -151,6 +160,9 @@ namespace bq {
if (snapshot_read_handle.result != enum_buffer_result_code::success) {
break;
}
if (cccc.load()) {
cccc5.fetch_add(1);
}
bq::log_entry_handle item(snapshot_read_handle.data_addr, snapshot_read_handle.data_size);
snapshot_layout_.do_layout(item, use_gmt_time, &parent_log_->get_categories_name());
text.insert_batch(text.end(), snapshot_layout_.get_formated_str(), snapshot_layout_.get_formated_str_len());
Expand Down
11 changes: 10 additions & 1 deletion test/test_log_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ namespace bq {
generate_log_str_standard_utf16(std::get<INDICES>(param_tuple)...);
log_inst_ptr->error(log_inst_ptr->cat.ModuleA.SystemA.ClassA, log_str_templates_fmt_utf16[fmt_idx], std::get<INDICES>(param_tuple)...);
}
++cccc1;
*output_str_ptr = output_str_ptr->substr(log_head.size(), output_str_ptr->size() - log_head.size());
test_log_3_all_console_outputs.push_back(*output_str_ptr);
result_ptr->add_result(output_str_ptr->end_with(log_str_standard), "test idx:%zu, %s \n != %s", current_tested_num, output_str_ptr->c_str(), log_str_standard.c_str());
Expand All @@ -889,6 +890,13 @@ namespace bq {
}
snapshot_idx_mode = (snapshot_idx_mode % 1024) + 1;
}
if (cccc1.load() != cccc2.load()
|| cccc1.load() != cccc3.load()
|| cccc1.load() != cccc4.load()
|| cccc1.load() != cccc5.load()
) {
bq::util::log_device_console(bq::log_level::fatal, "%d, %d, %d, %d, %d", cccc1.load(), cccc2.load(), cccc3.load(), cccc4.load(), cccc5.load());
}

size_t new_percent = (size_t)(current_tested_num * 100 / total_test_num);
if (new_percent != current_tested_percent) {
Expand All @@ -914,6 +922,7 @@ namespace bq {

void test_log::test_3(test_result& result, const test_category_log& log_inst)
{
cccc = true;
test_output(bq::log_level::info, "full log test begin, this will take minutes, and need about 50M free disk space.\n");
clear_test_output_folder();
init_fmt_strings<MAX_PARAM>();
Expand All @@ -927,7 +936,7 @@ namespace bq {
log_param_test<MAX_PARAM>();
test_3_phase = test_log_3_phase::do_test;
log_param_test<MAX_PARAM>();

cccc = false;

//decode test
for (size_t i = 0; i < test_log_3_all_console_outputs.size(); ++i) {
Expand Down

0 comments on commit bdd2cbb

Please sign in to comment.