-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (92 loc) · 3.68 KB
/
Copy pathmain.cpp
File metadata and controls
118 lines (92 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// #include <iostream>
// #include <thread>
// #include <chrono>
// // Platform-specific headers
// #if defined(_WIN32)
// #include <windows.h>
// #elif defined(__APPLE__)
// #include <mach/mach.h>
// #include <sys/types.h>
// #include <sys/sysctl.h>
// #elif defined(__linux__)
// #include <fstream>
// #include <string>
// #endif
// struct SystemStats {
// double ramUsagePercent = 0.0;
// size_t usedRamMB = 0;
// size_t totalRamMB = 0;
// };
// SystemStats getMemoryStats() {
// SystemStats stats;
// #if defined(_WIN32)
// MEMORYSTATUSEX memInfo;
// memInfo.dwLength = sizeof(MEMORYSTATUSEX);
// if (GlobalMemoryStatusEx(&memInfo)) {
// stats.totalRamMB = memInfo.ullTotalPhys / (1024 * 1024);
// stats.usedRamMB = (memInfo.ullTotalPhys - memInfo.ullAvailPhys) / (1024 * 1024);
// stats.ramUsagePercent = memInfo.dwMemoryLoad;
// }
// #elif defined(__APPLE__)
// int mib[2] = {CTL_HW, HW_MEMSIZE};
// int64_t totalRam = 0;
// size_t len = sizeof(totalRam);
// sysctl(mib, 2, &totalRam, &len, NULL, 0);
// stats.totalRamMB = totalRam / (1024 * 1024);
// // 1. DYNAMICALLY fetch the correct page size (Crucial for Apple Silicon!)
// vm_size_t pageSize;
// host_page_size(mach_host_self(), &pageSize);
// vm_statistics64_data_t vmStats;
// mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
// if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)&vmStats, &count) == KERN_SUCCESS) {
// // 2. App Memory (Internal - Purgeable)
// uint64_t appMemoryPages = (vmStats.internal_page_count > vmStats.purgeable_count)
// ? (vmStats.internal_page_count - vmStats.purgeable_count)
// : vmStats.internal_page_count;
// // 3. Wired + Compressed
// uint64_t wiredPages = vmStats.wire_count;
// uint64_t compressedPages = vmStats.compressor_page_count;
// // Total Used Bytes = (App + Wired + Compressed) * Real Hardware Page Size
// uint64_t usedBytes = (appMemoryPages + wiredPages + compressedPages) * pageSize;
// stats.usedRamMB = usedBytes / (1024 * 1024);
// stats.ramUsagePercent = ((double)stats.usedRamMB / stats.totalRamMB) * 100.0;
// }
// #elif defined(__linux__)
// std::ifstream memFile("/proc/meminfo");
// std::string key;
// size_t value;
// std::string unit;
// size_t totalMem = 0, freeMem = 0, buffers = 0, cached = 0;
// while (memFile >> key >> value >> unit) {
// if (key == "MemTotal:") totalMem = value;
// else if (key == "MemFree:") freeMem = value;
// else if (key == "Buffers:") buffers = value;
// else if (key == "Cached:") cached = value;
// }
// if (totalMem > 0) {
// size_t usedMem = totalMem - (freeMem + buffers + cached);
// stats.totalRamMB = totalMem / 1024;
// stats.usedRamMB = usedMem / 1024;
// stats.ramUsagePercent = ((double)usedMem / totalMem) * 100.0;
// }
// #endif
// return stats;
// }
// int main() {
// std::cout << "--- Low-Level System Monitor CLI (Step 1) ---\n\n";
// for (int i = 0; i < 5; ++i) {
// SystemStats stats = getMemoryStats();
// std::cout << "RAM Usage: " << stats.ramUsagePercent << "% ("
// << stats.usedRamMB << " MB / " << stats.totalRamMB << " MB)\n";
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// }
// return 0;
// }
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char* argv[]){
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}