2009-09-26 18:44:36 +02:00
|
|
|
// Copyright (c) 2009, Grigori Goronzy <greg@geekmind.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file platform_unix_linux.cpp
|
|
|
|
/// @brief Linux Platform extensions.
|
|
|
|
/// @ingroup unix
|
|
|
|
|
|
|
|
#ifndef R_PRECOMP
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/textfile.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "include/platform.h"
|
|
|
|
#include "platform_unix.h"
|
|
|
|
#include "platform_unix_linux.h"
|
|
|
|
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string PlatformUnixLinux::CPUId() {
|
2009-09-26 18:44:36 +02:00
|
|
|
return getProcValue("/proc/cpuinfo", "model name\t");
|
|
|
|
};
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string PlatformUnixLinux::CPUSpeed() {
|
2009-09-26 18:44:36 +02:00
|
|
|
return getProcValue("/proc/cpuinfo", "cpu MHz\t\t");
|
|
|
|
};
|
|
|
|
|
2009-09-27 03:20:29 +02:00
|
|
|
// Linux doesn't report the number of real CPUs or physical CPU cores,
|
|
|
|
// but instead the number of "logical" CPUs; this also includes logical cores
|
|
|
|
// due to SMT/HyperThreading.
|
|
|
|
// For now report the logical CPU count and no number of cores; this seems
|
|
|
|
// to make the most sense.
|
2011-01-08 16:38:30 +01:00
|
|
|
int PlatformUnixLinux::CPUCores() {
|
|
|
|
return -1;
|
2009-09-26 18:44:36 +02:00
|
|
|
};
|
|
|
|
|
2011-01-08 16:38:30 +01:00
|
|
|
int PlatformUnixLinux::CPUCount() {
|
2009-09-26 18:44:36 +02:00
|
|
|
// This returns the index of the last processor.
|
|
|
|
// Increment and return as string.
|
2011-01-08 16:38:30 +01:00
|
|
|
wxString procIndex = getProcValue("/proc/cpuinfo", "processor\t");
|
2009-09-26 18:44:36 +02:00
|
|
|
if (procIndex.IsNumber()) {
|
2009-09-27 03:20:29 +02:00
|
|
|
long val = 0;
|
2009-09-26 18:44:36 +02:00
|
|
|
procIndex.ToLong(&val);
|
2011-01-08 16:38:30 +01:00
|
|
|
return val + 1;
|
2009-09-26 18:44:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback
|
2011-01-08 16:38:30 +01:00
|
|
|
return 1;
|
2009-09-26 18:44:36 +02:00
|
|
|
};
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string PlatformUnixLinux::CPUFeatures() {
|
2009-09-26 18:44:36 +02:00
|
|
|
return getProcValue("/proc/cpuinfo", "flags\t\t");
|
|
|
|
};
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string PlatformUnixLinux::CPUFeatures2() {
|
2009-09-26 18:44:36 +02:00
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
2011-01-08 16:38:30 +01:00
|
|
|
uint64_t PlatformUnixLinux::Memory() {
|
|
|
|
wxString memKb = getProcValue("/proc/meminfo", "MemTotal");
|
2009-09-27 03:20:29 +02:00
|
|
|
memKb = memKb.BeforeFirst(' ');
|
|
|
|
if (memKb.IsNumber()) {
|
|
|
|
long val = 0;
|
|
|
|
memKb.ToLong(&val);
|
2011-01-08 16:38:30 +01:00
|
|
|
return val * 1024;
|
2009-09-27 03:20:29 +02:00
|
|
|
}
|
|
|
|
|
2011-01-08 16:38:30 +01:00
|
|
|
return -1;
|
2009-09-26 18:44:36 +02:00
|
|
|
};
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string PlatformUnixLinux::UnixLibraries() {
|
2009-09-26 18:44:36 +02:00
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Parse a /proc "key: value" style text file and extract a value.
|
2009-09-26 22:29:25 +02:00
|
|
|
* @return The last valid value
|
2009-09-26 18:44:36 +02:00
|
|
|
*/
|
2011-01-08 16:38:30 +01:00
|
|
|
std::string PlatformUnixLinux::getProcValue(const wxString path, const wxString key) {
|
|
|
|
const wxString prefix = wxString(key) + ":";
|
2009-09-26 18:44:36 +02:00
|
|
|
wxTextFile *file = new wxTextFile(path);
|
2011-01-08 16:38:30 +01:00
|
|
|
wxString val = std::string();
|
2009-09-26 18:44:36 +02:00
|
|
|
|
|
|
|
file->Open();
|
2011-01-08 16:38:30 +01:00
|
|
|
for (wxString str = file->GetFirstLine(); !file->Eof(); str = file->GetNextLine()) {
|
2009-09-26 18:44:36 +02:00
|
|
|
str.Trim(false);
|
|
|
|
if (str.StartsWith(prefix)) {
|
2011-01-08 16:38:30 +01:00
|
|
|
val = wxString(str.Mid(key.Len() + 1));
|
2009-09-26 18:44:36 +02:00
|
|
|
val.Trim(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 03:20:29 +02:00
|
|
|
file->Close();
|
2009-09-26 18:44:36 +02:00
|
|
|
delete file;
|
2011-01-08 16:38:30 +01:00
|
|
|
return std::string(val);
|
2009-09-26 18:44:36 +02:00
|
|
|
};
|
|
|
|
|