logic: Use sizeof(SharedMemory::String) in shared memory size estimation instead of std::string (issue #471)

This commit is contained in:
Eberhard Graether
2017-10-13 12:26:45 +02:00
parent 1d9b322e3e
commit a7363b329b
15 changed files with 38 additions and 37 deletions
+4 -4
View File
@@ -13,18 +13,18 @@ IndexerCommand::~IndexerCommand()
{
}
size_t IndexerCommand::getByteSize() const
size_t IndexerCommand::getByteSize(size_t stringSize) const
{
size_t size = sizeof(std::string) + m_sourceFilePath.str().size();
size_t size = m_sourceFilePath.str().size();
for (const FilePath& path: m_indexedPaths)
{
size += sizeof(std::string) + path.str().size();
size += stringSize + path.str().size();
}
for (const FilePath& path : m_excludedPaths)
{
size += sizeof(std::string) + path.str().size();
size += stringSize + path.str().size();
}
return size;
+1 -1
View File
@@ -15,7 +15,7 @@ public:
virtual IndexerCommandType getIndexerCommandType() const = 0;
virtual size_t getByteSize() const;
virtual size_t getByteSize(size_t stringSize) const;
const FilePath& getSourceFilePath() const;
const std::set<FilePath>& getIndexedPaths() const;
@@ -19,12 +19,12 @@ InterprocessIndexerCommandManager::~InterprocessIndexerCommandManager()
void InterprocessIndexerCommandManager::setIndexerCommands(
const std::vector<std::shared_ptr<IndexerCommand>>& indexerCommands)
{
const unsigned int overestimationMultiplier = 3;
const size_t overestimationMultiplier = 2;
size_t estimatedSize = 1048576; /* 1 MB */
for (auto& command : indexerCommands)
{
estimatedSize += command->getByteSize() + sizeof(SharedIndexerCommand);
estimatedSize += command->getByteSize(sizeof(SharedMemory::String)) + sizeof(SharedIndexerCommand);
}
estimatedSize *= overestimationMultiplier;
@@ -39,10 +39,10 @@ void InterprocessIndexingStatusManager::startIndexingSourceFile(const FilePath&
SharedMemory::Map<Id, SharedMemory::String>::iterator it = currentFilesPtr->find(getProcessId());
if (it != currentFilesPtr->end())
{
const int overestimationMultiplier = 3;
const size_t overestimationMultiplier = 3;
const std::string crashedFilePath = it->second.c_str();
size_t estimatedSize = 262144 + sizeof(std::string) + crashedFilePath.size();
size_t estimatedSize = 262144 + sizeof(SharedMemory::String) + crashedFilePath.size();
estimatedSize *= overestimationMultiplier;
while (access.getFreeMemorySize() < estimatedSize)
@@ -215,7 +215,7 @@ void InterprocessIndexingStatusManager::addIndexedFiles(std::set<FilePath> fileP
size_t estimatedSize = 262144;
for (auto& newFile : newFiles)
{
estimatedSize += sizeof(std::string) + newFile.size();
estimatedSize += sizeof(SharedMemory::String) + newFile.size();
}
estimatedSize *= overestimationMultiplier;
@@ -27,8 +27,9 @@ InterprocessIntermediateStorageManager::~InterprocessIntermediateStorageManager(
void InterprocessIntermediateStorageManager::pushIntermediateStorage(
const std::shared_ptr<IntermediateStorage>& intermediateStorage)
{
const unsigned int overestimationMultiplier = 3;
size_t size = (intermediateStorage->getByteSize() + sizeof(SharedIntermediateStorage)) * overestimationMultiplier + 1048576/* 1 MB */;
const size_t overestimationMultiplier = 2;
size_t size = (intermediateStorage->getByteSize(sizeof(SharedMemory::String)) +
sizeof(SharedIntermediateStorage)) * overestimationMultiplier + 1048576/* 1 MB */;
SharedMemory::ScopedAccess access(&m_sharedMemory);
+8 -8
View File
@@ -28,35 +28,35 @@ void IntermediateStorage::clear()
m_nextId = 1;
}
size_t IntermediateStorage::getByteSize() const
size_t IntermediateStorage::getByteSize(size_t stringSize) const
{
unsigned int byteSize = 0;
for (const StorageFile& storageFile: getStorageFiles())
{
byteSize += sizeof(StorageFile);
byteSize += storageFile.filePath.size();
byteSize += storageFile.modificationTime.size();
byteSize += stringSize + storageFile.filePath.size();
byteSize += stringSize + storageFile.modificationTime.size();
}
for (const StorageError& storageError: getErrors())
{
byteSize += sizeof(StorageError);
byteSize += storageError.filePath.str().size();
byteSize += storageError.message.size();
byteSize += storageError.commandline.size();
byteSize += stringSize + storageError.filePath.str().size();
byteSize += stringSize + storageError.message.size();
byteSize += stringSize + storageError.commandline.size();
}
for (const StorageNode& storageNode: getStorageNodes())
{
byteSize += sizeof(StorageNode);
byteSize += storageNode.serializedName.size();
byteSize += stringSize + storageNode.serializedName.size();
}
for (const StorageLocalSymbol& storageLocalSymbol: getStorageLocalSymbols())
{
byteSize += sizeof(StorageLocalSymbol);
byteSize += storageLocalSymbol.name.size();
byteSize += stringSize + storageLocalSymbol.name.size();
}
byteSize += sizeof(StorageEdge) * getStorageEdges().size();
+1 -1
View File
@@ -17,7 +17,7 @@ public:
void clear();
size_t getByteSize() const;
size_t getByteSize(size_t stringSize) const;
size_t getSourceLocationCount() const;
void setAllFilesIncomplete();
@@ -21,23 +21,23 @@ IndexerCommandCxx::~IndexerCommandCxx()
{
}
size_t IndexerCommandCxx::getByteSize() const
size_t IndexerCommandCxx::getByteSize(size_t stringSize) const
{
size_t size = IndexerCommand::getByteSize();
size_t size = IndexerCommand::getByteSize(stringSize);
for (auto& i : m_systemHeaderSearchPaths)
{
size += sizeof(std::string) + i.str().size();
size += stringSize + i.str().size();
}
for (auto& i : m_frameworkSearchPaths)
{
size += sizeof(std::string) + i.str().size();
size += stringSize + i.str().size();
}
for (auto& i : m_compilerFlags)
{
size += sizeof(std::string) + i.size();
size += stringSize + i.size();
}
return size;
+1 -1
View File
@@ -22,7 +22,7 @@ public:
const bool shouldApplyAnonymousTypedefTransformation);
virtual ~IndexerCommandCxx();
virtual size_t getByteSize() const override;
virtual size_t getByteSize(size_t stringSize) const override;
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
@@ -63,9 +63,9 @@ IndexerCommandType IndexerCommandCxxCdb::getIndexerCommandType() const
return getStaticIndexerCommandType();
}
size_t IndexerCommandCxxCdb::getByteSize() const
size_t IndexerCommandCxxCdb::getByteSize(size_t stringSize) const
{
return IndexerCommandCxx::getByteSize() + sizeof(std::string) + m_workingDirectory.str().size();
return IndexerCommandCxx::getByteSize(stringSize) + m_workingDirectory.str().size();
}
FilePath IndexerCommandCxxCdb::getWorkingDirectory() const
@@ -33,7 +33,7 @@ public:
virtual ~IndexerCommandCxxCdb();
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize() const override;
virtual size_t getByteSize(size_t stringSize) const override;
FilePath getWorkingDirectory() const;
@@ -29,9 +29,9 @@ IndexerCommandType IndexerCommandCxxManual::getIndexerCommandType() const
return getStaticIndexerCommandType();
}
size_t IndexerCommandCxxManual::getByteSize() const
size_t IndexerCommandCxxManual::getByteSize(size_t stringSize) const
{
return IndexerCommandCxx::getByteSize() + sizeof(std::string) + m_languageStandard.size();
return IndexerCommandCxx::getByteSize(stringSize) + m_languageStandard.size();
}
std::string IndexerCommandCxxManual::getLanguageStandard() const
@@ -24,7 +24,7 @@ public:
virtual ~IndexerCommandCxxManual();
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize() const override;
virtual size_t getByteSize(size_t stringSize) const override;
std::string getLanguageStandard() const;
@@ -25,13 +25,13 @@ IndexerCommandType IndexerCommandJava::getIndexerCommandType() const
return getStaticIndexerCommandType();
}
size_t IndexerCommandJava::getByteSize() const
size_t IndexerCommandJava::getByteSize(size_t stringSize) const
{
size_t size = IndexerCommand::getByteSize();
size_t size = IndexerCommand::getByteSize(stringSize);
for (auto& i : m_classPath)
{
size += sizeof(std::string) + i.str().size();
size += stringSize + i.str().size();
}
return size;
@@ -21,7 +21,7 @@ public:
virtual ~IndexerCommandJava();
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize() const override;
virtual size_t getByteSize(size_t stringSize) const override;
std::vector<FilePath> getClassPath() const;