diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 15157d3a..a0e33caa 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -85,6 +85,8 @@ void Application::saveProject(const std::string& projectSettingsFilePath) void Application::handleMessage(MessageFinishedParsing* message) { + m_project->logStats(); + if (message->errorCount > 0) { return; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 0ae78875..c9362a1a 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -120,6 +120,11 @@ void Project::parseCode() )); } +void Project::logStats() const +{ + m_storage->logStats(); +} + void Project::createFileManager() { std::shared_ptr projSettings = ProjectSettings::getInstance(); diff --git a/src/lib/Project.h b/src/lib/Project.h index b9a3b9b5..17bd3ce0 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -26,6 +26,8 @@ public: void clearStorage(); void parseCode(); + void logStats() const; + private: Project(StorageAccessProxy* storageAccessProxy); Project(const Project&); diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 2533124d..9af7566e 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -1,5 +1,7 @@ #include "data/Storage.h" +#include + #include "utility/logging/logging.h" #include "utility/utilityString.h" #include "utility/file/FileSystem.h" @@ -144,6 +146,27 @@ void Storage::logIndex() const LOG_INFO_STREAM(<< '\n' << m_tokenIndex); } +void Storage::logStats() const +{ + std::stringstream ss; + + ss << "\nGraph:\n"; + ss << "\t" << m_graph.getNodeCount() << " Nodes\n"; + ss << "\t" << m_graph.getEdgeCount() << " Edges\n"; + + ss << "\nSearch:\n"; + ss << "\t" << m_tokenIndex.getCharCount() << " Characters\n"; + ss << "\t" << m_tokenIndex.getWordCount() << " Words\n"; + ss << "\t" << m_tokenIndex.getNodeCount() << " SearchNodes\n"; + + ss << "\nCode:\n"; + ss << "\t" << m_locationCollection.getTokenLocationCount() << " Locations\n"; + ss << "\t" << m_locationCollection.getTokenLocationLineCount() << " Lines\n"; + ss << "\t" << m_locationCollection.getTokenLocationFileCount() << " Files\n"; + + LOG_INFO(ss.str()); +} + void Storage::onError(const ParseLocation& location, const std::string& message) { log("ERROR", message, location); diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index e6ced56a..d2639052 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -29,6 +29,7 @@ public: void logGraph() const; void logLocations() const; void logIndex() const; + void logStats() const; // ParserClient implementation virtual void onError(const ParseLocation& location, const std::string& message); diff --git a/src/lib/data/location/TokenLocationCollection.cpp b/src/lib/data/location/TokenLocationCollection.cpp index 022a1479..4bd36b18 100644 --- a/src/lib/data/location/TokenLocationCollection.cpp +++ b/src/lib/data/location/TokenLocationCollection.cpp @@ -27,6 +27,18 @@ size_t TokenLocationCollection::getTokenLocationFileCount() const return m_files.size(); } +size_t TokenLocationCollection::getTokenLocationLineCount() const +{ + size_t count = 0; + + for (const TokenLocationFilePairType& file : m_files) + { + count += file.second->getTokenLocationLineCount(); + } + + return count; +} + const std::map& TokenLocationCollection::getTokenLocations() const { return m_locations; diff --git a/src/lib/data/location/TokenLocationCollection.h b/src/lib/data/location/TokenLocationCollection.h index 3a7505cb..1d141861 100644 --- a/src/lib/data/location/TokenLocationCollection.h +++ b/src/lib/data/location/TokenLocationCollection.h @@ -26,6 +26,8 @@ public: const TokenLocationFileMapType& getTokenLocationFiles() const; size_t getTokenLocationFileCount() const; + size_t getTokenLocationLineCount() const; + const std::map& getTokenLocations() const; size_t getTokenLocationCount() const; diff --git a/src/lib/data/search/SearchIndex.cpp b/src/lib/data/search/SearchIndex.cpp index 84cf0fb4..1162d036 100644 --- a/src/lib/data/search/SearchIndex.cpp +++ b/src/lib/data/search/SearchIndex.cpp @@ -34,6 +34,7 @@ SearchIndex::~SearchIndex() void SearchIndex::clear() { m_root.m_nodes.clear(); + m_dictionary.clear(); } size_t SearchIndex::getNodeCount() const @@ -41,6 +42,16 @@ size_t SearchIndex::getNodeCount() const return m_root.getNodeCount() - 1; } +size_t SearchIndex::getCharCount() const +{ + return m_dictionary.getCharCount(); +} + +size_t SearchIndex::getWordCount() const +{ + return m_dictionary.getWordCount(); +} + Id SearchIndex::getWordId(const std::string& word) { return m_dictionary.getWordId(word); diff --git a/src/lib/data/search/SearchIndex.h b/src/lib/data/search/SearchIndex.h index 5f83ee5b..f4a65282 100644 --- a/src/lib/data/search/SearchIndex.h +++ b/src/lib/data/search/SearchIndex.h @@ -22,6 +22,8 @@ public: void clear(); size_t getNodeCount() const; + size_t getCharCount() const; + size_t getWordCount() const; Id getWordId(const std::string& word); const std::string& getWord(Id wordId) const; diff --git a/src/lib/utility/text/Dictionary.cpp b/src/lib/utility/text/Dictionary.cpp index b189df41..0c5d6bf2 100644 --- a/src/lib/utility/text/Dictionary.cpp +++ b/src/lib/utility/text/Dictionary.cpp @@ -13,6 +13,24 @@ Dictionary::~Dictionary() void Dictionary::clear() { m_words.clear(); + m_ids.clear(); +} + +size_t Dictionary::getCharCount() const +{ + size_t count = 0; + + for (const std::pair& p : m_words) + { + count += p.second.size(); + } + + return count; +} + +size_t Dictionary::getWordCount() const +{ + return m_words.size(); } Id Dictionary::getWordId(const std::string& word) diff --git a/src/lib/utility/text/Dictionary.h b/src/lib/utility/text/Dictionary.h index 1b116976..f3b80c43 100644 --- a/src/lib/utility/text/Dictionary.h +++ b/src/lib/utility/text/Dictionary.h @@ -17,6 +17,9 @@ public: void clear(); + size_t getCharCount() const; + size_t getWordCount() const; + Id getWordId(const std::string& word); Id getWordIdConst(const std::string& word) const;