void test_gzip() { std::cout << "- Page Gzip" << std::endl; set_context(true); cache().clear(); TEST(request().getenv("HTTP_ACCEPT_ENCODING") == "gzip, deflate"); cache().fetch_page("test"); response().out() << "gzip"; cache().store_page("test"); TEST(str().substr(0,2)=="\x1f\x8b"); TEST(gzip_); set_context(false); TEST(request().getenv("HTTP_ACCEPT_ENCODING") == ""); TEST(cache_size() == 1); TEST(cache().fetch_page("test") ==false); response().out() << "gzip"; cache().store_page("test"); TEST(str() == "gzip"); TEST(!gzip_); set_context(false); TEST(cache().fetch_page("test")); TEST(str()=="gzip"); TEST(!gzip_); set_context(true); TEST(cache().fetch_page("test")); TEST(str().substr(0,2)=="\x1f\x8b"); TEST(gzip_); set_context(false); TEST(cache_size()==2); cache().clear(); TEST(cache_size()==0); release_context(); }
void SzbaseWrapper::purge_cache() { size_t size_in_bytes, blocks_count; auto cache = base->cache(); cache->cache_size( size_in_bytes , blocks_count ); if( size_in_bytes > base_cache_high_water_mark ) { size_t to_purge = size_in_bytes - base_cache_low_water_mark; sz_log(5, "Purging cache, cache size %zu, purging %zu bytes", size_in_bytes, to_purge); cache->remove( to_purge ); } }
void test_basic() { std::cout << "- Page Basic" << std::endl; set_context(false); TEST(cache().has_cache()); TEST(!cache().fetch_page("test")); response().out() << "test"; cache().add_trigger("x"); cache().store_page("test"); TEST(str()=="test"); set_context(false); TEST(cache_size()==1); TEST(cache().fetch_page("test")); TEST(str()=="test"); set_context(false); cache().rise("x"); TEST(cache_size() == 0); TEST(!cache().fetch_page("test")); cache().add_trigger("x"); response().out() << "test2"; cache().reset(); // reset works cache().store_page("test",2); TEST(str()=="test2"); set_context(false); cache().rise("x"); TEST(cache_size() == 1); TEST(cache().fetch_page("test")); TEST(str() == "test2"); booster::ptime::millisleep(3000); set_context(false); TEST(cache().fetch_page("test")==false); cache().clear(); release_context(); }
void AttributesStor::loadBuiltInAttributes() { // no mutex here! AttributePtr id(new Attribute("id", Attribute::NUMERIC)); m_attributes[id->name()] = id; AttributePtr cache_size(new Attribute(Collection::ATTR_CACHE_SIZE, Attribute::NUMERIC)); m_attributes[cache_size->name()] = cache_size; AttributePtr medium_slots_count(new Attribute(Collection::ATTR_MEDIUM_SLOT_COUNT, Attribute::NUMERIC)); m_attributes[medium_slots_count->name()] = medium_slots_count; AttributePtr medium_file_size(new Attribute(Collection::ATTR_MEDIUM_FILE_SIZE, Attribute::NUMERIC)); m_attributes[medium_file_size->name()] = medium_file_size; }
// Parse the command line a use options to override the MapConfig defaults bool parseCommandLine(MapConfig& config, QString& error) { QCommandLineParser parser; const QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption server(QStringList() << "s" << "server-url", QCoreApplication::translate("main", "Map tile server URL with trailing /"), QCoreApplication::translate("main", "URL")); parser.addOption(server); QCommandLineOption format(QStringList() << "f" << "image-format", QCoreApplication::translate("main", "Map tile image format (e.g. png)"), QCoreApplication::translate("main", "format")); parser.addOption(format); QCommandLineOption min_zoom(QStringList() << "min-zoom", QCoreApplication::translate("main", "Map minimum zoom level"), QCoreApplication::translate("main", "zoom")); parser.addOption(min_zoom); QCommandLineOption max_zoom(QStringList() << "max-zoom", QCoreApplication::translate("main", "Map maximum zoom level"), QCoreApplication::translate("main", "zoom")); parser.addOption(max_zoom); QCommandLineOption tile_size(QStringList() << "t" << "tile-size", QCoreApplication::translate("main", "Map tile size in pixels (e.g. 256)"), QCoreApplication::translate("main", "size")); parser.addOption(tile_size); QCommandLineOption cache_size(QStringList() << "c" << "cache-size", QCoreApplication::translate("main", "Map tile cache size in tiles (e.g. 512)"), QCoreApplication::translate("main", "cache")); parser.addOption(cache_size); if (!parser.parse(QGuiApplication::arguments())) { error = parser.errorText(); return true; } if (parser.isSet(helpOption)) { parser.showHelp(); return false; } if (parser.isSet(server)) { QString s = parser.value(server); QHostInfo info = QHostInfo::fromName(s); if (info.error() == QHostInfo::NoError) { config.server = s; } else { qDebug() << "Invalid map tile server URL: " << s; } } if (parser.isSet(format)) { config.format = parser.value(format); } if (parser.isSet(min_zoom)) { QVariant range(parser.value(min_zoom)); config.min_zoom = range.toInt(); } if (parser.isSet(max_zoom)) { QVariant range(parser.value(max_zoom)); config.max_zoom = range.toInt(); } if (parser.isSet(tile_size)) { QVariant range(parser.value(tile_size)); config.tile_size = range.toInt(); } if (parser.isSet(cache_size)) { QVariant range(parser.value(cache_size)); config.cache_size = size_t(range.toInt()); } return false; }
/** * initializes cpuinfo-struct * @param print detection-summary is written to stdout when !=0 */ void init_cpuinfo(cpu_info_t *cpuinfo,int print) { unsigned int i; char output[_HW_DETECT_MAX_OUTPUT]; /* initialize data structure */ memset(cpuinfo,0,sizeof(cpu_info_t)); strcpy(cpuinfo->architecture,"unknown\0"); strcpy(cpuinfo->vendor,"unknown\0"); strcpy(cpuinfo->model_str,"unknown\0"); cpuinfo->num_cpus = num_cpus(); get_architecture(cpuinfo->architecture, sizeof(cpuinfo->architecture)); get_cpu_vendor(cpuinfo->vendor, sizeof(cpuinfo->vendor)); get_cpu_name(cpuinfo->model_str, sizeof(cpuinfo->model_str)); cpuinfo->family = get_cpu_family(); cpuinfo->model = get_cpu_model(); cpuinfo->stepping = get_cpu_stepping(); cpuinfo->num_cores_per_package = num_cores_per_package(); cpuinfo->num_threads_per_core = num_threads_per_core(); cpuinfo->num_packages = num_packages(); cpuinfo->clockrate = get_cpu_clockrate(1, 0); /* setup supported feature list*/ if(!strcmp(cpuinfo->architecture,"x86_64")) cpuinfo->features |= X86_64; if (feature_available("SMT")) cpuinfo->features |= SMT; if (feature_available("FPU")) cpuinfo->features |= FPU; if (feature_available("MMX")) cpuinfo->features |= MMX; if (feature_available("MMX_EXT")) cpuinfo->features |= MMX_EXT; if (feature_available("SSE")) cpuinfo->features |= SSE; if (feature_available("SSE2")) cpuinfo->features |= SSE2; if (feature_available("SSE3")) cpuinfo->features |= SSE3; if (feature_available("SSSE3")) cpuinfo->features |= SSSE3; if (feature_available("SSE4.1")) cpuinfo->features |= SSE4_1; if (feature_available("SSE4.2")) cpuinfo->features |= SSE4_2; if (feature_available("SSE4A")) cpuinfo->features |= SSE4A; if (feature_available("ABM")) cpuinfo->features |= ABM; if (feature_available("POPCNT")) cpuinfo->features |= POPCNT; if (feature_available("AVX")) cpuinfo->features |= AVX; if (feature_available("AVX2")) cpuinfo->features |= AVX2; if (feature_available("FMA")) cpuinfo->features |= FMA; if (feature_available("FMA4")) cpuinfo->features |= FMA4; if (feature_available("AES")) cpuinfo->features |= AES; if (feature_available("AVX512")) cpuinfo->features |= AVX512; /* determine cache details */ for (i=0; i<(unsigned int)num_caches(0); i++) { cpuinfo->Cache_shared[cache_level(0,i)-1]=cache_shared(0,i); cpuinfo->Cacheline_size[cache_level(0,i)-1]=cacheline_length(0,i); if (cpuinfo->Cachelevels < (unsigned int)cache_level(0,i)) { cpuinfo->Cachelevels = cache_level(0,i); } switch (cache_type(0,i)) { case UNIFIED_CACHE: { cpuinfo->Cache_unified[cache_level(0,i)-1]=1; cpuinfo->U_Cache_Size[cache_level(0,i)-1]=cache_size(0,i); cpuinfo->U_Cache_Sets[cache_level(0,i)-1]=cache_assoc(0,i); break; } case DATA_CACHE: { cpuinfo->Cache_unified[cache_level(0,i)-1]=0; cpuinfo->D_Cache_Size[cache_level(0,i)-1]=cache_size(0,i); cpuinfo->D_Cache_Sets[cache_level(0,i)-1]=cache_assoc(0,i); break; } case INSTRUCTION_CACHE: { cpuinfo->Cache_unified[cache_level(0,i)-1]=0; cpuinfo->I_Cache_Size[cache_level(0,i)-1]=cache_size(0,i); cpuinfo->I_Cache_Sets[cache_level(0,i)-1]=cache_assoc(0,i); break; } default: break; } } /* print a summary */ if (print) { fflush(stdout); printf("\n system summary:\n"); if(cpuinfo->num_packages) printf(" number of processors: %i\n",cpuinfo->num_packages); if(cpuinfo->num_cores_per_package) printf(" number of cores per package: %i\n",cpuinfo->num_cores_per_package); if(cpuinfo->num_threads_per_core) printf(" number of threads per core: %i\n",cpuinfo->num_threads_per_core); if(cpuinfo->num_cpus) printf(" total number of threads: %i\n",cpuinfo->num_cpus); printf("\n processor characteristics:\n"); printf(" architecture: %s\n",cpuinfo->architecture); printf(" vendor: %s\n",cpuinfo->vendor); printf(" processor-name: %s\n",cpuinfo->model_str); printf(" model: Family %i, Model %i, Stepping %i\n",cpuinfo->family,cpuinfo->model,cpuinfo->stepping); printf(" frequency: %llu MHz\n",cpuinfo->clockrate/1000000); fflush(stdout); printf(" supported features:\n -"); if(cpuinfo->features&X86_64) printf(" X86_64"); if(cpuinfo->features&FPU) printf(" FPU"); if(cpuinfo->features&MMX) printf(" MMX"); if(cpuinfo->features&MMX_EXT) printf(" MMX_EXT"); if(cpuinfo->features&SSE) printf(" SSE"); if(cpuinfo->features&SSE2) printf(" SSE2"); if(cpuinfo->features&SSE3) printf(" SSE3"); if(cpuinfo->features&SSSE3) printf(" SSSE3"); if(cpuinfo->features&SSE4_1) printf(" SSE4.1"); if(cpuinfo->features&SSE4_2) printf(" SSE4.2"); if(cpuinfo->features&SSE4A) printf(" SSE4A"); if(cpuinfo->features&POPCNT) printf(" POPCNT"); if(cpuinfo->features&AVX) printf(" AVX"); if(cpuinfo->features&AVX2) printf(" AVX2"); if(cpuinfo->features&AVX512) printf(" AVX512"); if(cpuinfo->features&FMA) printf(" FMA"); if(cpuinfo->features&FMA4) printf(" FMA4"); if(cpuinfo->features&AES) printf(" AES"); if(cpuinfo->features&SMT) printf(" SMT"); printf(" \n"); if(cpuinfo->Cachelevels) { printf(" Caches:\n"); for(i = 0; i < (unsigned int)num_caches(0); i++) { snprintf(output,sizeof(output),"n/a"); if (cache_info(0, i, output, sizeof(output)) != -1) printf(" - %s\n",output); } } } fflush(stdout); }
/** * Parses shtml document for possible script includes. * Accepts includes of the form '%! scriptname'. * * If scriptname starts with ':' it is assumed to be an SSI, * otherwise it will be handled as CGI call. */ static PT_THREAD(handle_scripts(struct httpd_state *s)) { /* Note script includes will attach a leading : to the filename and a trailing zero */ static char scriptname[MAX_SCRIPT_NAME_LENGTH + 1], *pptr; // static uint16_t filelength; static int done, eof, eoc; PT_BEGIN(&s->scriptpt); eoc = eof = done = 0; /* Init cache (null-terminated)*/ load_cache(s); while (!done) { /* Assure we can read at least a '%!' sequence. */ // if (cache_size() < 2) { // reload_cache(s); // } /* Check if we should start executing a script, flagged by %! */ if (file_cache_ptr[0] == ISO_percent && file_cache_ptr[1] == ISO_bang) { /* Test if a whole line is in cache, otherwise reload cache. */ if (strchr(&file_cache_ptr[2], ISO_nl) == NULL) { reload_cache(s); } /* Extract name, if starts with colon include file else call cgi */ s->scriptptr = get_scriptname(scriptname, &file_cache_ptr[2]); // s->scriptlen = files[s->fd].len - (s->scriptptr - file_cache_ptr[0]); PRINTD("httpd: Handle script named %s\n", scriptname); /* Include scripts prefixed with ':' are SSI else CGI scripts */ if (scriptname[0] == ISO_colon) { #if WEBSERVER_CONF_INCLUDE PRINTD("IS SSI\n"); s->scriptfd = httpd_fs_open(&scriptname[1], HTTPD_FS_READ); /* Send script if open succeeded. */ if (s->scriptfd != -1) { s->sendfd = s->scriptfd; PT_WAIT_THREAD(&s->scriptpt, send_file(s)); } else { PRINTD("failed opening %s\n", scriptname); } httpd_fs_close(s->scriptfd); /*TODO dont print anything if file not found */ #endif /* Execute unprefixed scripts. */ } else { PRINTD("IS CGI\n"); #if WEBSERVER_CONF_CGI PT_WAIT_THREAD(&s->scriptpt, httpd_cgi(scriptname)(s, s->scriptptr)); #endif } skip_scriptline(s); file_cache_ptr = s->scriptptr; if (cache_size() < 2) { reload_cache(s); } if (cache_size() == 0) { done = 1; } } else { // no script /* get position of next percent character */ if (file_cache_ptr[0] == ISO_percent) { pptr = (char *) strchr(&file_cache_ptr[1], ISO_percent); } else { pptr = (char *) strchr(&file_cache_ptr[0], ISO_percent); } /* calc new length to send */ if (pptr == NULL) { /* no further percent sign found in cache. */ /* Send to end of cache */ s->sendlen = cache_len - (&file_cache_ptr[0] - &file_cache_array[0]); eoc = 1;// inidcates thate we need new cache } else { s->sendlen = (int) ((int) pptr - (int) &file_cache_ptr[0]); } if (s->sendlen > 0) { PRINTD("httpd: Sending %u bytes from 0x%04x\n", s->sendlen, (unsigned int) pptr); s->sendfd = s->fd; PT_WAIT_THREAD(&s->scriptpt, send_part_of_cache(s)); } /* Reload cache if it was marked as empty. */ if (eoc) { reload_cache(s); } /* If (reloaded) cache empty, stop sending */ if (cache_size() == 0) { done = 1; } } } PT_END(&s->scriptpt); }
bool is_cached(int64_t x, int64_t a) const { return a <= CACHE_A_LIMIT && x < cache_size(a) && cache_[a][x] != 0; }