/* * Stellarium * Copyright (C) 2009 Fabien Chereau * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. */ #include "StelLogger.hpp" #include "StelUtils.hpp" #include #include #ifdef Q_OS_WIN #include #endif // Init statics variables. QFile StelLogger::logFile; QString StelLogger::log; void StelLogger::init(const QString& logFilePath) { logFile.setFileName(logFilePath); if (logFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text | QIODevice::Unbuffered)) qInstallMessageHandler(StelLogger::debugLogHandler); // write timestamp writeLog(QString("%1").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); // write info about operating system writeLog(StelUtils::getOperatingSystemInfo()); // write compiler version #if defined __GNUC__ && !defined __clang__ #ifdef __MINGW32__ #define COMPILER "MinGW GCC" #else #define COMPILER "GCC" #endif writeLog(QString("Compiled using %1 %2.%3.%4").arg(COMPILER).arg(__GNUC__).arg(__GNUC_MINOR__).arg(__GNUC_PATCHLEVEL__)); #elif defined __clang__ writeLog(QString("Compiled using %1 %2.%3.%4").arg("Clang").arg(__clang_major__).arg(__clang_minor__).arg(__clang_patchlevel__)); #elif defined _MSC_VER writeLog(QString("Compiled using %1").arg(getMsvcVersionString(_MSC_VER))); #else writeLog("Unknown compiler"); #endif // write Qt version writeLog(QString("Qt runtime version: %1").arg(qVersion())); writeLog(QString("Qt compilation version: %1").arg(QT_VERSION_STR)); // write addressing mode #if defined(__LP64__) || defined(_WIN64) writeLog("Addressing mode: 64-bit"); #else writeLog("Addressing mode: 32-bit"); #endif // write memory and CPU info #ifdef Q_OS_LINUX #ifndef BUILD_FOR_MAEMO QFile infoFile("/proc/meminfo"); if(!infoFile.open(QIODevice::ReadOnly | QIODevice::Text)) writeLog("Could not get memory info."); else { while(!infoFile.peek(1).isEmpty()) { QString line = infoFile.readLine(); line.chop(1); if (line.startsWith("Mem") || line.startsWith("SwapTotal")) writeLog(line); } infoFile.close(); } infoFile.setFileName("/proc/cpuinfo"); if (!infoFile.open(QIODevice::ReadOnly | QIODevice::Text)) writeLog("Could not get CPU info."); else { while(!infoFile.peek(1).isEmpty()) { QString line = infoFile.readLine(); line.chop(1); if(line.startsWith("model name") || line.startsWith("cpu MHz")) writeLog(line); } infoFile.close(); } QProcess lspci; lspci.start("lspci -v", QIODevice::ReadOnly); lspci.waitForFinished(300); const QString pciData(lspci.readAll()); QStringList pciLines = pciData.split('\n', QString::SkipEmptyParts); for (int i = 0; i= QSysInfo::WV_2000) { #ifdef __LP64__ MEMORYSTATUSEX statex; GlobalMemoryStatusEx(&statex); writeLog(QString("Total physical memory: %1 MB (unreliable)").arg(statex.ullTotalPhys/(1024<<10))); writeLog(QString("Total virtual memory: %1 MB (unreliable)").arg(statex.ullTotalVirtual/(1024<<10))); writeLog(QString("Physical memory in use: %1%").arg(statex.dwMemoryLoad)); #else MEMORYSTATUS statex; GlobalMemoryStatus(&statex); writeLog(QString("Total memory: %1 MB (unreliable)").arg(statex.dwTotalPhys/(1024<<10))); writeLog(QString("Total virtual memory: %1 MB (unreliable)").arg(statex.dwTotalVirtual/(1024<<10))); writeLog(QString("Physical memory in use: %1%").arg(statex.dwMemoryLoad)); #endif } else writeLog("Windows version too old to get memory info."); HKEY hKey = NULL; DWORD dwType = REG_DWORD; DWORD numVal = 0; DWORD dwSize = sizeof(numVal); // iterate over the processors listed in the registry QString procKey = "Hardware\\Description\\System\\CentralProcessor"; LONG lRet = ERROR_SUCCESS; int i; for(i = 0; lRet == ERROR_SUCCESS; i++) { lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, qPrintable(QString("%1\\%2").arg(procKey).arg(i)), 0, KEY_QUERY_VALUE, &hKey); if(lRet == ERROR_SUCCESS) { if(RegQueryValueExA(hKey, "~MHz", NULL, &dwType, (LPBYTE)&numVal, &dwSize) == ERROR_SUCCESS) writeLog(QString("Processor speed: %1 MHz").arg(numVal)); else writeLog("Could not get processor speed."); } // can you believe this trash? dwType = REG_SZ; char nameStr[512]; DWORD nameSize = sizeof(nameStr); if (lRet == ERROR_SUCCESS) { if (RegQueryValueExA(hKey, "ProcessorNameString", NULL, &dwType, (LPBYTE)&nameStr, &nameSize) == ERROR_SUCCESS) writeLog(QString("Processor name: %1").arg(nameStr)); else writeLog("Could not get processor name."); } RegCloseKey(hKey); } if(i == 0) writeLog("Could not get processor info."); #elif defined Q_OS_MAC QProcess systemProfiler; systemProfiler.start("/usr/sbin/system_profiler -detailLevel mini SPHardwareDataType SPDisplaysDataType"); systemProfiler.waitForStarted(); systemProfiler.waitForFinished(); const QString systemData(systemProfiler.readAllStandardOutput()); QStringList systemLines = systemData.split('\n', QString::SkipEmptyParts); for (int i = 0; i