logic: Use all available cores when setting indexer threads to 0 (issue #342)
This commit is contained in:
@@ -219,6 +219,7 @@ set_property(
|
||||
"${CMAKE_SOURCE_DIR}/src/lib"
|
||||
"${CMAKE_SOURCE_DIR}/src/external"
|
||||
"${CMAKE_SOURCE_DIR}/src/lib_license"
|
||||
"${CMAKE_SOURCE_DIR}/src/lib_gui"
|
||||
"${CMAKE_BINARY_DIR}/src/lib_license"
|
||||
)
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "utility/scheduling/TaskSetValue.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityApp.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/Version.h"
|
||||
|
||||
@@ -412,7 +413,15 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, bool fullRefres
|
||||
|
||||
if (indexerCommandList->size() > 0)
|
||||
{
|
||||
const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
||||
int indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
||||
if (indexerThreadCount <= 0)
|
||||
{
|
||||
indexerThreadCount = utility::getIdealThreadCount();
|
||||
if (indexerThreadCount <= 0)
|
||||
{
|
||||
indexerThreadCount = 4; // setting to some fallback value
|
||||
}
|
||||
}
|
||||
|
||||
if (indexerThreadCount > 1)
|
||||
{
|
||||
|
||||
@@ -228,7 +228,7 @@ bool ApplicationSettings::setIndexingFilePaths(const std::vector<FilePath>& inde
|
||||
|
||||
int ApplicationSettings::getIndexerThreadCount() const
|
||||
{
|
||||
return getValue<int>("indexing/indexer_thread_count", 4);
|
||||
return getValue<int>("indexing/indexer_thread_count", 0);
|
||||
}
|
||||
|
||||
void ApplicationSettings::setIndexerThreadCount(const int count)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageSwitchColorScheme.h"
|
||||
@@ -92,7 +93,30 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
|
||||
addTitle("INDEXING", layout, row);
|
||||
|
||||
// indexer threads
|
||||
m_threads = addComboBox("Indexer threads", 1, 24, "Number of parallel threads used to index your projects.", layout, row);
|
||||
const int minThreadCount = 0;
|
||||
const int maxThreadCount = 24;
|
||||
|
||||
m_threads = new QComboBox(this);
|
||||
connect(m_threads, SIGNAL(activated(int)), this, SLOT(indexerThreadsChanges(int)));
|
||||
for (int i = minThreadCount; i <= maxThreadCount; i++)
|
||||
{
|
||||
m_threads->insertItem(i, QString::number(i));
|
||||
}
|
||||
|
||||
m_threadsInfoLabel = new QLabel("");
|
||||
utility::setWidgetRetainsSpaceWhenHidden(m_threadsInfoLabel);
|
||||
|
||||
QHBoxLayout* hlayout = new QHBoxLayout();
|
||||
hlayout->setContentsMargins(0, 0, 0, 0);
|
||||
hlayout->addWidget(m_threads);
|
||||
hlayout->addWidget(m_threadsInfoLabel);
|
||||
|
||||
QWidget* threadsWidget = new QWidget();
|
||||
threadsWidget->setLayout(hlayout);
|
||||
|
||||
addLabelAndWidget("Indexer threads", threadsWidget, layout, row, Qt::AlignLeft);
|
||||
addHelpButton("Number of parallel threads used to index your projects.\nWhen setting this to 0 Sourcetrail tries to use the ideal thread count for your computer.", layout, row);
|
||||
row++;
|
||||
|
||||
addGap(layout, row);
|
||||
|
||||
@@ -230,7 +254,8 @@ void QtProjectWizzardContentPreferences::load()
|
||||
m_sourcetrailPort->setText(QString::number(appSettings->getSourcetrailPort()));
|
||||
m_pluginPort->setText(QString::number(appSettings->getPluginPort()));
|
||||
|
||||
m_threads->setCurrentIndex(appSettings->getIndexerThreadCount() - 1);
|
||||
m_threads->setCurrentIndex(appSettings->getIndexerThreadCount()); // index and value are the same
|
||||
indexerThreadsChanges(m_threads->currentIndex());
|
||||
|
||||
if (m_javaPath)
|
||||
{
|
||||
@@ -273,7 +298,7 @@ void QtProjectWizzardContentPreferences::save()
|
||||
int pluginPort = m_pluginPort->text().toInt();
|
||||
if (pluginPort) appSettings->setPluginPort(pluginPort);
|
||||
|
||||
appSettings->setIndexerThreadCount(m_threads->currentIndex() + 1);
|
||||
appSettings->setIndexerThreadCount(m_threads->currentIndex()); // index and value are the same
|
||||
|
||||
if (m_javaPath)
|
||||
{
|
||||
@@ -323,6 +348,19 @@ void QtProjectWizzardContentPreferences::loggingEnabledChanged()
|
||||
m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked());
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPreferences::indexerThreadsChanges(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
m_threadsInfoLabel->setText(("detected " + std::to_string(utility::getIdealThreadCount()) + " threads to be ideal.").c_str());
|
||||
m_threadsInfoLabel->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_threadsInfoLabel->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layout, int& row)
|
||||
{
|
||||
std::vector<std::string> detectorNames = m_javaPathDetector->getWorkingDetectorNames();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "qt/element/QtFontPicker.h"
|
||||
@@ -31,6 +32,7 @@ private slots:
|
||||
void javaPathDetectionClicked();
|
||||
void mavenPathDetectionClicked();
|
||||
void loggingEnabledChanged();
|
||||
void indexerThreadsChanges(int index);
|
||||
|
||||
private:
|
||||
void addJavaPathDetection(QGridLayout* layout, int& row);
|
||||
@@ -65,6 +67,7 @@ private:
|
||||
QLineEdit* m_pluginPort;
|
||||
|
||||
QComboBox* m_threads;
|
||||
QLabel* m_threadsInfoLabel;
|
||||
|
||||
std::shared_ptr<CombinedPathDetector> m_javaPathDetector;
|
||||
std::shared_ptr<CombinedPathDetector> m_mavenPathDetector;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "utility/utilityApp.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <qprocessordetection.h>
|
||||
|
||||
#include "utility/utilityString.h"
|
||||
@@ -35,3 +36,8 @@ ApplicationArchitectureType utility::getApplicationArchitectureType()
|
||||
#endif
|
||||
return APPLICATION_ARCHITECTURE_UNKNOWN;
|
||||
}
|
||||
|
||||
int utility::getIdealThreadCount()
|
||||
{
|
||||
return QThread::idealThreadCount();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace utility
|
||||
std::string executeProcess(const std::string& command, const std::string& workingDirectory = "");
|
||||
|
||||
ApplicationArchitectureType getApplicationArchitectureType();
|
||||
|
||||
int getIdealThreadCount();
|
||||
}
|
||||
|
||||
#endif // UTILITY_APP_H
|
||||
|
||||
Reference in New Issue
Block a user