bool sctpServer::start(const QString &config) { parseConfig(config); if (!listen(QHostAddress::Any, mPort)) { qCritical() << QObject::tr("Unable to start the server: %1").arg(errorString()); return false; } QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); QString message = QObject::tr("The server is running on\nIP: %1\tport: %2\n") .arg(ipAddress).arg(serverPort()); qDebug() << message.toUtf8().constData(); // initialize sc-memory qDebug() << "Initialize sc-memory\n"; sc_memory_params params; sc_memory_params_clear(¶ms); std::string config_path = config.toStdString(); std::string repo_path = mRepoPath.toStdString(); std::string ext_path = mExtPath.toStdString(); params.clear = SC_FALSE; params.config_file = config_path.c_str(); params.repo_path = repo_path.c_str(); params.ext_path = ext_path.c_str(); mContext = sc_memory_initialize(¶ms); if (mContext == 0) return false; mEventManager = new sctpEventManager(); mEventManager->initialize(); if (mStatUpdatePeriod > 0) { mStatistic = new sctpStatistic(this); mStatistic->initialize(mStatPath, mStatUpdatePeriod, mContext); } QTimer::singleShot(mSavePeriod * 1000, this, SLOT(onSave())); return true; }
bool ScMemory::initialize(sc_memory_params const & params) { gContextGounter = 0; g_log_set_default_handler(_logPrintHandler, nullptr); msGlobalContext = sc_memory_initialize(¶ms); return msGlobalContext != null_ptr; }
void test_combined_creation() { int thread_count = g_thread_count; int test_count = (g_task_count) / thread_count; g_message("Threads count: %d, Test per thread: %d", thread_count, test_count); tGThreadVector threads; threads.reserve(thread_count); s_default_ctx = sc_memory_initialize(¶ms); print_storage_statistics(); g_test_timer_start(); for (size_t i = 0; i < thread_count; ++i) { GThreadFunc f = create_node_thread; switch(g_random_int() % 3) { case 0: f = create_link_thread; break; case 1: f = create_arc_thread; break; default: break; } GThread * thread = g_thread_try_new(0, f, GINT_TO_POINTER(test_count), 0); if (thread == 0) continue; threads.push_back(thread); } for (size_t i = 0; i < thread_count; ++i) g_assert(GPOINTER_TO_INT(g_thread_join(threads[i])) == test_count); printf("Time: %lf\n", g_test_timer_elapsed()); print_storage_statistics(); sc_memory_shutdown(SC_FALSE); }
void test_save() { // create nodes s_default_ctx = sc_memory_initialize(¶ms); sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8)); int const count = 1000000; for (int i = 0; i < count; ++i) { g_assert(SC_ADDR_IS_NOT_EMPTY(sc_memory_node_new(ctx, 0))); } sc_memory_context_free(ctx); GThread * thread = g_thread_try_new(0, start_save_threaded, 0, 0); test_creation(create_arc_thread, g_task_count, g_thread_count); g_thread_join(thread); sc_memory_shutdown(SC_FALSE); }
bool Builder::run(const BuilderParams ¶ms) { mParams = params; collectFiles(); // initialize sc-memory sc_memory_params p; sc_memory_params_clear(&p); p.clear = mParams.clearOutput ? SC_TRUE : SC_FALSE; p.config_file = mParams.configFile.empty() ? 0 : mParams.configFile.c_str(); p.repo_path = mParams.outputPath.c_str(); p.ext_path = mParams.extensionsPath.size() > 0 ? mParams.extensionsPath.c_str() : 0; sc_memory_initialize(&p); mContext = sc_memory_context_new(sc_access_lvl_make_min); std::cout << "Build knowledge base from sources... " << std::endl; // process founded files uint32 done = 0, last_progress = -1; tFileSet::iterator it, itEnd = mFileSet.end(); for (it = mFileSet.begin(); it != itEnd; ++it) { uint32 progress = (uint32)(((float)++done / (float)mFileSet.size()) * 100); if (mParams.showFileNames) { std::cout << "[ " << progress << "% ] " << *it << std::endl; } else { if (last_progress != progress) { if (progress % 10 == 0) { std::cout << "[" << progress << "%]"; std::cout.flush(); } else { std::cout << "."; std::cout.flush(); } last_progress = progress; } } try { processFile(*it); } catch(const Exception &e) { StringStream ss; ss << e.getDescription() << " in " << e.getFileName() << " at line " << e.getLineNumber(); mErrors.push_back(ss.str()); } } std::cout << std::endl << "done" << std::endl; // print errors std::cout << std::endl << "-------" << std::endl << "Errors:" << std::endl; int idx = 1; tStringList::iterator itErr, itErrEnd = mErrors.end(); for (itErr = mErrors.begin(); itErr != itErrEnd; ++itErr) std::cout << "[" << idx++ << "]\t" << *itErr << std::endl; // print statistics sc_stat stat; sc_memory_stat(mContext, &stat); unsigned int all_count = stat.arc_count + stat.node_count + stat.link_count; std::cout << std::endl << "Statistics" << std::endl; std::cout << "Nodes: " << stat.node_count << "(" << ((float)stat.node_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Arcs: " << stat.arc_count << "(" << ((float)stat.arc_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Links: " << stat.link_count << "(" << ((float)stat.link_count / (float)all_count) * 100 << "%)" << std::endl; std::cout << "Total: " << all_count << std::endl; sc_memory_context_free(mContext); sc_memory_shutdown(SC_TRUE); return true; }
int main(int argc, char *argv[]) { sc_uint item = -1; fflush(stdout); timer = g_timer_new(); g_timer_start(timer); printf("MD5: %d\n", g_checksum_type_get_length(G_CHECKSUM_MD5) ); printf("SHA1: %d\n", g_checksum_type_get_length(G_CHECKSUM_SHA1) ); printf("SHA256: %d\n", g_checksum_type_get_length(G_CHECKSUM_SHA256) ); printf("Element size: %d\n", sizeof(sc_element)); sc_memory_initialize("repo", 0); g_timer_stop(timer); printf("Segment loading speed: %f seg/sec\n", sc_storage_get_segments_count() / g_timer_elapsed(timer, 0)); //test1(); //test5(); //test6(); //test7(); //test8(); test3(); item = 0; while (item != 0) { printf("Commands:\n" "0 - exit\n" "1 - test allocation\n" "2 - test sc-addr utilities\n" "3 - test arc deletion\n" "4 - test iterators\n" "5 - test contents\n" "6 - test content finding\n" "7 - test events\n" "8 - test garbage deletion\n" "9 - run grabage collection\n" "\nCommand: "); scanf("%d", &item); printf("\n----- Test %d -----\n", item); switch(item) { case 1: test1(); break; case 2: test2(); break; case 3: test3(); break; case 4: test4(); break; case 5: test5(); break; case 6: test6(); break; case 7: test7(); break; case 8: test8(); break; case 9: test9(); break; }; printf("\n----- Finished -----\n"); } timer = g_timer_new(); item = sc_storage_get_segments_count(); g_timer_reset(timer); // crash when uncomment //sc_memory_shutdown(); g_timer_stop(timer); printf("Segments save speed: %f seg/sec\n", item / g_timer_elapsed(timer, 0)); g_timer_destroy(timer); return 0; }
void test_link_creation() { s_default_ctx = sc_memory_initialize(¶ms); test_creation(create_link_thread, g_task_count, g_thread_count); sc_memory_shutdown(SC_FALSE); }