From 4d422b199756588bcc146a5a468bb55e690f2403 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sun, 27 Sep 2009 01:20:29 +0000 Subject: [PATCH] Minor fixes to the reporter Linux support * drop BSD-specific includes * document CPU cores/count vs. logical CPU count * close files properly * return memory size in bytes Originally committed to SVN as r3584. --- aegisub/reporter/platform_unix_linux.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/aegisub/reporter/platform_unix_linux.cpp b/aegisub/reporter/platform_unix_linux.cpp index ba9083963..1877ef55b 100644 --- a/aegisub/reporter/platform_unix_linux.cpp +++ b/aegisub/reporter/platform_unix_linux.cpp @@ -24,12 +24,6 @@ #include #endif -extern "C" { -#include -#include -#include -} - #include "include/platform.h" #include "platform_unix.h" #include "platform_unix_linux.h" @@ -43,6 +37,11 @@ wxString PlatformUnixLinux::CPUSpeed() { return getProcValue("/proc/cpuinfo", "cpu MHz\t\t"); }; +// 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. wxString PlatformUnixLinux::CPUCores() { return ""; }; @@ -52,7 +51,7 @@ wxString PlatformUnixLinux::CPUCount() { // Increment and return as string. wxString procIndex = getProcValue("/proc/cpuinfo", "processor\t"); if (procIndex.IsNumber()) { - long val; + long val = 0; procIndex.ToLong(&val); return wxString::Format("%ld", val + 1); } @@ -70,7 +69,15 @@ wxString PlatformUnixLinux::CPUFeatures2() { }; wxString PlatformUnixLinux::Memory() { - return getProcValue("/proc/meminfo", "MemTotal"); + wxString memKb = getProcValue("/proc/meminfo", "MemTotal"); + memKb = memKb.BeforeFirst(' '); + if (memKb.IsNumber()) { + long val = 0; + memKb.ToLong(&val); + return wxString::Format("%ld", val * 1024); + } + + return ""; }; wxString PlatformUnixLinux::Video() { @@ -99,6 +106,7 @@ wxString PlatformUnixLinux::getProcValue(const wxString path, const wxString key } } + file->Close(); delete file; return val; };