|
|
|
@ -26,6 +26,15 @@
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_FREEBSD
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -224,47 +233,32 @@ System::targetEnvOutput( const QString& command,
|
|
|
|
|
qint64
|
|
|
|
|
System::getPhysicalMemoryB()
|
|
|
|
|
{
|
|
|
|
|
QProcess p;
|
|
|
|
|
p.start( "dmidecode", { "-t", "17" } );
|
|
|
|
|
p.waitForFinished();
|
|
|
|
|
QStringList lines = QString::fromLocal8Bit( p.readAllStandardOutput() ).split( '\n' );
|
|
|
|
|
lines = lines.filter( QRegularExpression( "^\\W*Size:\\W\\d*\\WMB" ) );
|
|
|
|
|
if ( !lines.isEmpty() )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
qint64 availableRamMb = 0;
|
|
|
|
|
foreach( const QString& line, lines )
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
availableRamMb += line.simplified()
|
|
|
|
|
.split( ' ' )
|
|
|
|
|
.value( 1 )
|
|
|
|
|
.toInt( &ok );
|
|
|
|
|
if ( !ok )
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
qint64 availableRam = availableRamMb * 1024 * 1024;
|
|
|
|
|
return availableRam;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qint64
|
|
|
|
|
System::getTotalMemoryB()
|
|
|
|
|
{
|
|
|
|
|
// A line in meminfo looks like this, with {print $2} we grab the second column.
|
|
|
|
|
// MemTotal: 8133432 kB
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
struct sysinfo i;
|
|
|
|
|
int r = sysinfo( &i );
|
|
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
QProcess p;
|
|
|
|
|
p.start( "awk", { "/MemTotal/ {print $2}", "/proc/meminfo" } );
|
|
|
|
|
p.waitForFinished();
|
|
|
|
|
QString memoryLine = p.readAllStandardOutput().simplified();
|
|
|
|
|
return qint64( i.mem_unit ) * i.totalram;
|
|
|
|
|
#elif defined( Q_OS_FREEBSD )
|
|
|
|
|
unsigned long memsize;
|
|
|
|
|
size_t s = sizeof(memsize);
|
|
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
qint64 availableRam = memoryLine.toLongLong( &ok ) * 1024;
|
|
|
|
|
if ( !ok )
|
|
|
|
|
int r = sysctlbyname("vm.kmem_size", &memsize, &s, NULL, 0);
|
|
|
|
|
if (r)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return availableRam;
|
|
|
|
|
return memsize;
|
|
|
|
|
#endif
|
|
|
|
|
return 0; // Unsupported
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|