mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 11:43:16 +02:00
Add processor information to launch user activity event
This commit is contained in:
parent
f84f98f804
commit
dafb5c5bab
3 changed files with 165 additions and 5 deletions
|
@ -815,7 +815,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
|||
{ "gl_version", glContextData["version"] },
|
||||
{ "gl_vender", glContextData["vendor"] },
|
||||
{ "gl_sl_version", glContextData["slVersion"] },
|
||||
{ "gl_renderer", glContextData["renderer"] }
|
||||
{ "gl_renderer", glContextData["renderer"] },
|
||||
{ "ideal_thread_count", QThread::idealThreadCount() }
|
||||
};
|
||||
auto macVersion = QSysInfo::macVersion();
|
||||
if (macVersion != QSysInfo::MV_None) {
|
||||
|
@ -825,6 +826,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
|||
if (windowsVersion != QSysInfo::WV_None) {
|
||||
properties["os_win_version"] = QSysInfo::windowsVersion();
|
||||
}
|
||||
|
||||
ProcessorInfo procInfo;
|
||||
if (getProcessorInfo(procInfo)) {
|
||||
properties["processor_core_count"] = procInfo.numProcessorCores;
|
||||
properties["logical_processor_count"] = procInfo.numLogicalProcessors;
|
||||
properties["processor_l1_cache_count"] = procInfo.numProcessorCachesL1;
|
||||
properties["processor_l2_cache_count"] = procInfo.numProcessorCachesL2;
|
||||
properties["processor_l3_cache_count"] = procInfo.numProcessorCachesL3;
|
||||
}
|
||||
|
||||
UserActivityLogger::getInstance().logAction("launch", properties);
|
||||
|
||||
_connectionMonitor.init();
|
||||
|
|
|
@ -22,11 +22,8 @@
|
|||
#include <glm/glm.hpp>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#include "CPUIdent.h"
|
||||
#include <Psapi.h>
|
||||
#endif
|
||||
|
@ -877,3 +874,144 @@ bool getMemoryInfo(MemoryInfo& info) {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Largely taken from: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683194(v=vs.85).aspx
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
using LPFN_GLPI = BOOL(WINAPI*)(
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION,
|
||||
PDWORD);
|
||||
|
||||
DWORD CountSetBits(ULONG_PTR bitMask)
|
||||
{
|
||||
DWORD LSHIFT = sizeof(ULONG_PTR) * 8 - 1;
|
||||
DWORD bitSetCount = 0;
|
||||
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
|
||||
DWORD i;
|
||||
|
||||
for (i = 0; i <= LSHIFT; ++i)
|
||||
{
|
||||
bitSetCount += ((bitMask & bitTest) ? 1 : 0);
|
||||
bitTest /= 2;
|
||||
}
|
||||
|
||||
return bitSetCount;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool getProcessorInfo(ProcessorInfo& info) {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
LPFN_GLPI glpi;
|
||||
bool done = false;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL;
|
||||
DWORD returnLength = 0;
|
||||
DWORD logicalProcessorCount = 0;
|
||||
DWORD numaNodeCount = 0;
|
||||
DWORD processorCoreCount = 0;
|
||||
DWORD processorL1CacheCount = 0;
|
||||
DWORD processorL2CacheCount = 0;
|
||||
DWORD processorL3CacheCount = 0;
|
||||
DWORD processorPackageCount = 0;
|
||||
DWORD byteOffset = 0;
|
||||
PCACHE_DESCRIPTOR Cache;
|
||||
|
||||
glpi = (LPFN_GLPI)GetProcAddress(
|
||||
GetModuleHandle(TEXT("kernel32")),
|
||||
"GetLogicalProcessorInformation");
|
||||
if (nullptr == glpi) {
|
||||
qDebug() << "GetLogicalProcessorInformation is not supported.";
|
||||
return false;
|
||||
}
|
||||
|
||||
while (!done) {
|
||||
DWORD rc = glpi(buffer, &returnLength);
|
||||
|
||||
if (FALSE == rc) {
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(
|
||||
returnLength);
|
||||
|
||||
if (NULL == buffer) {
|
||||
qDebug() << "Error: Allocation failure";
|
||||
return (2);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Error " << GetLastError();
|
||||
return (3);
|
||||
}
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
ptr = buffer;
|
||||
|
||||
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) {
|
||||
switch (ptr->Relationship) {
|
||||
case RelationNumaNode:
|
||||
// Non-NUMA systems report a single record of this type.
|
||||
numaNodeCount++;
|
||||
break;
|
||||
|
||||
case RelationProcessorCore:
|
||||
processorCoreCount++;
|
||||
|
||||
// A hyperthreaded core supplies more than one logical processor.
|
||||
logicalProcessorCount += CountSetBits(ptr->ProcessorMask);
|
||||
break;
|
||||
|
||||
case RelationCache:
|
||||
// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
|
||||
Cache = &ptr->Cache;
|
||||
if (Cache->Level == 1) {
|
||||
processorL1CacheCount++;
|
||||
} else if (Cache->Level == 2) {
|
||||
processorL2CacheCount++;
|
||||
} else if (Cache->Level == 3) {
|
||||
processorL3CacheCount++;
|
||||
}
|
||||
break;
|
||||
|
||||
case RelationProcessorPackage:
|
||||
// Logical processors share a physical package.
|
||||
processorPackageCount++;
|
||||
break;
|
||||
|
||||
default:
|
||||
qDebug() << "\nError: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\n";
|
||||
break;
|
||||
}
|
||||
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
qDebug() << "GetLogicalProcessorInformation results:";
|
||||
qDebug() << "Number of NUMA nodes:" << numaNodeCount;
|
||||
qDebug() << "Number of physical processor packages:" << processorPackageCount;
|
||||
qDebug() << "Number of processor cores:" << processorCoreCount;
|
||||
qDebug() << "Number of logical processors:" << logicalProcessorCount;
|
||||
qDebug() << "Number of processor L1/L2/L3 caches:"
|
||||
<< processorL1CacheCount
|
||||
<< "/" << processorL2CacheCount
|
||||
<< "/" << processorL3CacheCount;
|
||||
|
||||
info.numPhysicalProcessorPackages = processorPackageCount;
|
||||
info.numProcessorCores = processorCoreCount;
|
||||
info.numLogicalProcessors = logicalProcessorCount;
|
||||
info.numProcessorCachesL1 = processorL1CacheCount;
|
||||
info.numProcessorCachesL2 = processorL2CacheCount;
|
||||
info.numProcessorCachesL3 = processorL3CacheCount;
|
||||
|
||||
free(buffer);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
|
@ -214,4 +214,15 @@ struct MemoryInfo {
|
|||
|
||||
bool getMemoryInfo(MemoryInfo& info);
|
||||
|
||||
struct ProcessorInfo {
|
||||
int32_t numPhysicalProcessorPackages;
|
||||
int32_t numProcessorCores;
|
||||
int32_t numLogicalProcessors;
|
||||
int32_t numProcessorCachesL1;
|
||||
int32_t numProcessorCachesL2;
|
||||
int32_t numProcessorCachesL3;
|
||||
};
|
||||
|
||||
bool getProcessorInfo(ProcessorInfo& info);
|
||||
|
||||
#endif // hifi_SharedUtil_h
|
||||
|
|
Loading…
Reference in a new issue