chunk *TRAFBox::dumpBox(dictionary *inputParams) { uint32_t i, size; box.header.size = (uint64_t)estimateSize(inputParams); chunk *c = new chunk((uint32_t)box.header.size, false); size = htonl((uint32_t)box.header.size); box.header.type = htonl(TRAF_BOX); c->append((uint8_t *) &size, sizeof(size)); c->append((uint8_t *) &box.header.type, sizeof(box.header.type)); for(i = 0; i < boxes.size(); i++) c->append(boxes.at(i)->dumpBox(inputParams)); /* remember that chunk::append(chunk *) will get rid of our provided chunk */ return c; }
/* dump the full box inclusive header and all included boxes */ chunk *MVEXBox::dumpBox(dictionary *inputParams) { uint32_t i, size; /* compute the size of the box */ box.header.size = (uint64_t)estimateSize(inputParams); chunk *c = new chunk((uint32_t)box.header.size, false); size = htonl((uint32_t)box.header.size); box.header.type = htonl(MVEX_BOX); c->append((uint8_t*) &size, sizeof(uint32_t)); c->append((uint8_t*) &box.header.type, sizeof(uint32_t)); for(i=0;i<boxes.size();i++) c->append(boxes.at(i)->dumpBox(inputParams)); return c; }
chunk *STCOBox::dumpBox(dictionary *inputParams) { uint32_t size; box.fullbox.header.type = htonl(STCO_BOX); box.fullbox.version = 0; box.fullbox.flags[0] = 0; box.fullbox.flags[1] = 0; box.fullbox.flags[2] = 0; box.entry_count = htonl(boxes.size()); size = estimateSize(inputParams); chunk *c = new chunk(size, false); size = htonl(size); box.entry_count = 0; c->append((uint8_t *) &size, sizeof(size)); c->append((uint8_t *) &box.fullbox.header.type, sizeof(box.fullbox.header.type)); c->append((uint8_t *) &box.fullbox.version, sizeof(box.fullbox.version)); c->append((uint8_t *) box.fullbox.flags, sizeofarray(box.fullbox.flags) * sizeof(uint8_t)); c->append((uint8_t *) &box.entry_count, sizeof(box.entry_count)); return c; }
/* dump the full box inclusive header and all included boxes */ chunk *URLBox::dumpBox(dictionary *inputParams) { uint32_t n, size; /* compute the size of the box */ box.fullbox.header.size = (uint64_t)estimateSize(inputParams); chunk *c = new chunk((uint32_t)box.fullbox.header.size, false); size = htonl((uint32_t)box.fullbox.header.size); box.fullbox.header.type = htonl(URL_BOX); box.fullbox.version = htonl(0); box.fullbox.flags[0] = box.fullbox.flags[1] = 0; box.fullbox.flags[2] = 1; /* this means that the data is contained in this file */ c->append((uint8_t*) &size, sizeof(uint32_t)); c->append((uint8_t*) &box.fullbox.header.type, sizeof(uint32_t)); c->append((uint8_t*) &box.fullbox.version, sizeof(box.fullbox.version)); c->append((uint8_t*) &box.fullbox.flags[0], sizeof(uint8_t)); c->append((uint8_t*) &box.fullbox.flags[1], sizeof(uint8_t)); c->append((uint8_t*) &box.fullbox.flags[2], sizeof(uint8_t)); return c; }
void MemoryUsage::log() { // std::string footprint is ~ string.capacity() // std::vector footprint is ~ 3 * sizeof(T*) + vector.capacity() * sizeof( T ); // std::set footprint is ~ 3 * sizeof( void* ) + set.size() * ( sizeof(T)+3 * sizeof( void* ) ); // std::map footprint is ~ ( sizeof(K)+sizeof( V ) + ( sizeof(void*) * 3 + 1 ) / 2 ) * map.size(); size_t systemstate_size = Plib::systemstate.estimatedSize(); size_t multibuffer_size = Multi::multidef_buffer.estimateSize(); auto network_size = networkManager.estimateSize(); auto object_sizes = objStorageManager.estimateSize(); auto script_sizes = scriptEngineInternalManager.estimateSize(); size_t settings_size = settingsManager.estimateSize(); size_t state_size = stateManager.estimateSize(); auto config_sizes = configurationbuffer.estimateSize(); auto gamestate_size = gamestate.estimateSize(); auto cprop_profiler_size = CPropProfiler::instance().estimateSize(); std::vector<std::pair<std::string, size_t>> logs; logs.push_back( std::make_pair( "ProcessSize", Clib::getCurrentMemoryUsage() ) ); logs.push_back( std::make_pair( "CPProfilerSize", cprop_profiler_size ) ); logs.push_back( std::make_pair( "GameStateSize", gamestate_size.misc ) ); logs.push_back( std::make_pair( "RealmSize", gamestate_size.realm_size ) ); logs.push_back( std::make_pair( "SystemStateSize", systemstate_size ) ); logs.push_back( std::make_pair( "MultiBufferSize", multibuffer_size ) ); logs.push_back( std::make_pair( "SettingsSize", settings_size ) ); logs.push_back( std::make_pair( "StateSize", state_size ) ); logs.push_back( std::make_pair( "ScriptCount", script_sizes.script_count ) ); logs.push_back( std::make_pair( "ScriptSize", script_sizes.script_size ) ); logs.push_back( std::make_pair( "ScriptStoreCount", script_sizes.scriptstorage_count ) ); logs.push_back( std::make_pair( "ScriptStoreSize", script_sizes.scriptstorage_size ) ); logs.push_back( std::make_pair( "ConfigCount", config_sizes.cfg_count ) ); logs.push_back( std::make_pair( "ConfigSize", config_sizes.cfg_size ) ); logs.push_back( std::make_pair( "DataStoreCount", config_sizes.datastore_count ) ); logs.push_back( std::make_pair( "DataStoreSize", config_sizes.datastore_size ) ); logs.push_back( std::make_pair( "ConfigBufferSize", config_sizes.misc ) ); logs.push_back( std::make_pair( "AccountCount", gamestate_size.account_count ) ); logs.push_back( std::make_pair( "AccountSize", gamestate_size.account_size ) ); logs.push_back( std::make_pair( "ClientCount", network_size.client_count ) ); logs.push_back( std::make_pair( "ClientSize", network_size.client_size ) ); logs.push_back( std::make_pair( "NetworkSize", network_size.misc ) ); logs.push_back( std::make_pair( "ObjectStorage", object_sizes.misc ) ); logs.push_back( std::make_pair( "ObjItemCount", object_sizes.obj_item_count ) ); logs.push_back( std::make_pair( "ObjItemSize", object_sizes.obj_item_size ) ); logs.push_back( std::make_pair( "ObjContCount", object_sizes.obj_cont_count ) ); logs.push_back( std::make_pair( "ObjContSize", object_sizes.obj_cont_size ) ); logs.push_back( std::make_pair( "ObjCharCount", object_sizes.obj_char_count ) ); logs.push_back( std::make_pair( "ObjCharSize", object_sizes.obj_char_size ) ); logs.push_back( std::make_pair( "ObjNpcCount", object_sizes.obj_npc_count ) ); logs.push_back( std::make_pair( "ObjNpcSize", object_sizes.obj_npc_size ) ); logs.push_back( std::make_pair( "ObjWeaponCount", object_sizes.obj_weapon_count ) ); logs.push_back( std::make_pair( "ObjWeaponSize", object_sizes.obj_weapon_size ) ); logs.push_back( std::make_pair( "ObjArmorCount", object_sizes.obj_armor_count ) ); logs.push_back( std::make_pair( "ObjArmorSize", object_sizes.obj_armor_size ) ); logs.push_back( std::make_pair( "ObjMultiCount", object_sizes.obj_multi_count ) ); logs.push_back( std::make_pair( "ObjMultiSize", object_sizes.obj_multi_size ) ); #ifdef DEBUG_FLYWEIGHT for ( size_t i = 0; i < boost_utils::debug_flyweight_queries.size(); ++i ) { auto ptr = boost_utils::debug_flyweight_queries[i]; if (ptr == nullptr) continue; auto str = std::to_string(i); logs.push_back( std::make_pair( "FlyWeightBucket" + str + "Count", ptr->bucket_count() ) ); logs.push_back( std::make_pair( "FlyWeightBucket" + str + "Size", ptr->estimateSize() ) ); } #endif bool needs_header = !Clib::FileExists( "log/memoryusage.log" ); auto log = OPEN_FLEXLOG( "log/memoryusage.log", false ); if ( needs_header ) { fmt::Writer header; header << "Time"; for (const auto& entry : logs) header << " ;" << entry.first; FLEXLOG( log ) << header.str() << "\n"; } fmt::Writer line; line << GET_LOG_FILESTAMP; for (const auto& entry : logs) line << " ;" << entry.second; FLEXLOG( log ) << line.str() << "\n"; CLOSE_FLEXLOG( log ); }
template <typename T> string toStr(const T &t) { string s; s.resize(estimateSize(t)); return toStr(t, s).str(); }