int main(int argc, char *argv[]) { (void)argc; (void)argv; std::cout << "Performance benchmark" << std::endl; const std::string storage_path = "testStorage"; { std::cout << "write..." << std::endl; const size_t chunk_per_storage = 1024 * 10; const size_t chunk_size = 1024; const size_t cap_B = 5; const size_t max_mem_chunks = 100; if (dariadb::utils::fs::path_exists(storage_path)) { dariadb::utils::fs::rm(storage_path); } dariadb::Time start_time = dariadb::timeutil::current_time(); dariadb::storage::Capacitor::Params cap_param(cap_B, storage_path); cap_param.max_levels = 11; auto raw_ptr = new dariadb::storage::Engine( dariadb::storage::PageManager::Params(storage_path, chunk_per_storage, chunk_size), cap_param, dariadb::storage::Engine::Limits(max_mem_chunks)); dariadb::storage::MeasStorage_ptr ms{raw_ptr}; dariadb::IdSet all_id_set; append_count = 0; stop_info = false; std::thread info_thread(show_info, raw_ptr); std::vector<std::thread> writers(dariadb_bench::total_threads_count); size_t pos = 0; for (size_t i = 1; i < dariadb_bench::total_threads_count + 1; i++) { all_id_set.insert(pos); std::thread t{dariadb_bench::thread_writer_rnd_stor, dariadb::Id(pos), dariadb::Time(i), &append_count, raw_ptr}; writers[pos++] = std::move(t); } pos = 0; for (size_t i = 1; i < dariadb_bench::total_threads_count + 1; i++) { std::thread t = std::move(writers[pos++]); t.join(); } stop_info = true; info_thread.join(); { std::cout << "full flush..." << std::endl; auto start = clock(); raw_ptr->flush(); auto elapsed = (((float)clock() - start) / CLOCKS_PER_SEC); std::cout << "flush time: " << elapsed << std::endl; } auto queue_sizes = raw_ptr->queue_size(); std::cout << "\r" << " in queue: (p:" << queue_sizes.pages_count << " cap:" << queue_sizes.cola_count << ")" << std::endl; dariadb_bench::readBenchark(all_id_set, ms, 10,start_time, dariadb::timeutil::current_time()); { std::cout << "read all..." << std::endl; std::shared_ptr<BenchCallback> clbk{new BenchCallback()}; auto start = clock(); dariadb::storage::QueryInterval qi{ dariadb::IdArray(all_id_set.begin(), all_id_set.end()), 0, start_time, ms->maxTime() }; ms->readInterval(qi)->readAll(clbk.get()); auto elapsed = (((float)clock() - start) / CLOCKS_PER_SEC); std::cout << "readed: " << clbk->count << std::endl; std::cout << "time: " << elapsed << std::endl; auto expected = (dariadb_bench::iteration_count * dariadb_bench::total_threads_count); if (clbk->count != expected) { std::cout << "expected: " << expected << " get:" << clbk->count << std::endl; throw MAKE_EXCEPTION("(clbk->count!=(iteration_count*total_threads_count))"); } } std::cout << "stoping storage...\n"; ms = nullptr; } std::cout << "cleaning...\n"; if (dariadb::utils::fs::path_exists(storage_path)) { dariadb::utils::fs::rm(storage_path); } }
Val raise_error__may_heapclean ( //========================== // Task* task, const char* altMsg, const char* at, // C sourcefile and line number raising this error: "<foo.c:37>" Roots* extra_roots ) { // Raise the Mythryl exception RUNTIME_EXCEPTION, which is defined as: // // exception RUNTIME_EXCEPTION (String, Null_Or(System_Error) ); // // We normally get invoked via either the // RAISE_SYSERR__MAY_HEAPCLEAN or RAISE_ERROR__MAY_HEAPCLEAN macro from // // src/c/lib/raise-error.h // // For the time being, we use the errno value as the System_Error; eventually that // will be represented by an (Int, String) pair. If alt_msg is non-zero, // then use it as the error string and use NULL for the System_Error. int error_number = errno; // Various calls can trash this value so preserve it early. const char* msg; char buf[32]; Val null_or_errno; if (altMsg != NULL) { // msg = altMsg; null_or_errno = OPTION_NULL; } else if ((msg = strerror(error_number)) != NULL) { null_or_errno = OPTION_THE( task, TAGGED_INT_FROM_C_INT(error_number) ); } else { sprintf(buf, "<unknown error %d>", error_number); msg = buf; null_or_errno = OPTION_THE( task, TAGGED_INT_FROM_C_INT(error_number) ); } #if (defined(DEBUG_OS_INTERFACE) || defined(DEBUG_TRACE_CCALL)) debug_say ("RaiseSysError: errno = %d, msg = \"%s\"\n", (altMsg != NULL) ? -1 : error_number, msg); #endif Roots roots1 = { &null_or_errno, extra_roots }; Val errno_string = make_ascii_string_from_c_string__may_heapclean (task, msg, &roots1 ); Val at_list; // [] or [ "<foo.c:187>" ]. // if (at != NULL) { // Roots roots2 = { &errno_string, &roots1 }; Val at_cstring = make_ascii_string_from_c_string__may_heapclean (task, at, &roots2 ); at_list = LIST_CONS(task, at_cstring, LIST_NIL); } else { at_list = LIST_NIL; } Val arg = make_two_slot_record( task, errno_string, null_or_errno); Val syserr_exception = MAKE_EXCEPTION(task, PTR_CAST( Val, RUNTIME_EXCEPTION__GLOBAL), arg, at_list); // Modify the task state so that 'syserr_exception' // will be raised when Mythryl execution resumes: // raise_mythryl_exception( task, syserr_exception ); // raise_mythryl_exception is from src/c/main/run-mythryl-code-and-runtime-eventloop.c return syserr_exception; } // fun raise_error__may_heapclean
void language::load(const string& Path, const string& Language, int CountNeed) { SCOPED_ACTION(GuardLastError); auto Data = m_Data->create(); const auto LangFileData = OpenLangFile(Path, LangFileMask, Language); const auto& LangFile = std::get<0>(LangFileData); const auto LangFileCodePage = std::get<2>(LangFileData); if (!LangFile) { throw MAKE_EXCEPTION(exception, L"Cannot find language data"sv); } Data->m_FileName = LangFile.GetName(); if (CountNeed != -1) { Data->reserve(CountNeed); } std::unordered_map<string, size_t> id_map; string label, text; for (const auto& i: enum_file_lines(LangFile, LangFileCodePage)) { bool have_text; parse_lng_line(trim(i.Str), label, text, have_text); if (have_text) { auto idx = Data->size(); Data->add(ConvertString(text)); if (!label.empty()) { id_map[label] = idx; label.clear(); } } } // Проведем проверку на количество строк в LNG-файлах if (CountNeed != -1 && CountNeed != static_cast<int>(Data->size())) { throw MAKE_EXCEPTION(exception, Data->m_FileName + L": language data is incorrect or damaged"sv); } // try to load Far<LNG>.lng.custom file(s) // if (!id_map.empty()) { const auto& LoadStrings = [&](const string& FileName) { const os::fs::file CustomFile(FileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING); if (!CustomFile) return; const auto CustomFileCodepage = GetFileCodepage(CustomFile, encoding::codepage::oem(), nullptr, false); label.clear(); for (const auto& i: enum_file_lines(CustomFile, CustomFileCodepage)) { bool have_text; parse_lng_line(trim(i.Str), label, text, have_text); if (have_text && !label.empty()) { const auto found = id_map.find(label); if (found != id_map.end()) { Data->set_at(found->second, ConvertString(text)); } label.clear(); } } }; const auto CustomLngInSameDir = Data->m_FileName + L".custom"sv; const auto CustomLngInProfileDir = concat(Global->Opt->ProfilePath, L'\\', ExtractFileName(CustomLngInSameDir)); LoadStrings(CustomLngInSameDir); LoadStrings(CustomLngInProfileDir); } m_Data = std::move(Data); }