ClangCodeModel: Check system for clangd suitability on first run

Turn off clangd by default if we think the system does not have enough
memory. Inform the user and let them override our decision.

Task-number: QTCREATORBUG-19297
Change-Id: Ib9715c2f089c10d7a2a559a25180e9a943c118b1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2022-06-17 11:58:14 +02:00
parent 05a7f93f96
commit ea868c8b46
5 changed files with 95 additions and 4 deletions

View File

@@ -31,6 +31,10 @@
#include <QOpenGLContext>
#endif
#ifdef Q_OS_LINUX
#include <sys/sysinfo.h>
#endif
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
@@ -111,3 +115,27 @@ bool HostOsInfo::canCreateOpenGLContext(QString *errorMessage)
return canCreate;
#endif
}
optional<quint64> HostOsInfo::totalMemoryInstalledInBytes()
{
#ifdef Q_OS_LINUX
struct sysinfo info;
if (sysinfo(&info) == -1)
return {};
return info.totalram;
#elif defined(Q_OS_WIN)
MEMORYSTATUSEX statex;
statex.dwLength = sizeof statex;
if (!GlobalMemoryStatusEx(&statex))
return {};
return statex.ullTotalPhys;
#elif defined(Q_OS_MACOS)
int mib[] = {CTL_HW, HW_MEMSIZE};
int64_t ram;
size_t length = sizeof(int64_t);
if (sysctl(mib, 2, &ram, &length, nullptr, 0) == -1)
return {};
return ram;
#endif
return {};
}