Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
38 changes: 38 additions & 0 deletions engine/services/hardware_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <string>
#include <vector>
#include <stdint.h>

namespace services {




struct CPU {
int cores;
std::string arch;
std::string model;
std::vector<std::string> instructions;
};

struct RAM {
uint64_t total;
uint64_t available;
std::string type;
};

struct RamHelper {

};

struct GPU {

};

struct GPUS {

};
class HardwareService {

};
} // namespace services
73 changes: 73 additions & 0 deletions engine/utils/hardware/ram_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#include <string>
#if defined(__APPLE__) && defined(__MACH__)
#include <sys/sysctl.h>
#elif defined(__linux__)
#include <fstream>
#elif defined(_WIN32)
#include <psapi.h>
#include <windows.h>
#endif

namespace hardware {
struct Memory {
uint64_t total;
uint64_t available;
std::string type;
};

inline Memory GetMemoryInfo() {
#if defined(__APPLE__) && defined(__MACH__)
int64_t total_memory = 0;
int64_t used_memory = 0;

size_t length = sizeof(total_memory);
sysctlbyname("hw.memsize", &total_memory, &length, NULL, 0);

// Get used memory (this is a rough estimate)
vm_size_t page_size;
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;

vm_statistics_data_t vm_stat;
host_page_size(mach_host_self(), &page_size);

if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat,
&count) == KERN_SUCCESS) {
used_memory =
(vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) *
page_size / 1024; // Convert to KB
}
return Memory{.total = total_memory, .available = total_memory - used_memory};
#elif defined(__linux__)
std::ifstream meminfo("/proc/meminfo");
std::string line;
uint64_t total_memory = 0;
uint64_t free_memory = 0;
while (std::getline(meminfo, line)) {
if (line.find("MemTotal:") == 0) {
sscanf(line.c_str(), "MemTotal: %ld kB", &total_memory);
}
if (line.find("MemAvailable:") == 0) {
sscanf(line.c_str(), "MemAvailable: %ld kB", &free_memory);
}
}

return Memory{.total = total_memory, .available = free_memory};
#elif defined(_WIN32)
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
// Get total physical memory
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
return Memory{
.total = statex.ullTotalPhys / 1024,
.available = (statex.ullTotalPhys - pmc.WorkingSetSize) / 1024};
}
return Memory{};
#else
return Memory{};
#endif
}
} // namespace hardware
Loading