-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add RAM Usage entry using psapi.h windows API #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds RAM usage reporting to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
main.cpp (1)
814-829:⚠️ Potential issue | 🟠 MajorRAM usage is displayed as raw bytes — should be human-readable.
WorkingSetSizeis in bytes, so a process using 50 MB will printRAM Usage: 52428800. Users will have no idea what that number means without a unit. Convert to a friendlier format (e.g., MB with one decimal).Also, zero-initialize
pmcfor safety.Proposed fix
- PROCESS_MEMORY_COUNTERS pmc; - if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { - if (IsVirtualTerminalModeEnabled()) { - std::cout << "\033[1;32mRAM Usage\033[0m: " << pmc.WorkingSetSize << std::endl; - } else { - std::cout << "RAM Usage: " << pmc.WorkingSetSize << std::endl; - } - } + PROCESS_MEMORY_COUNTERS pmc{}; + if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { + double memMB = static_cast<double>(pmc.WorkingSetSize) / (1024.0 * 1024.0); + if (IsVirtualTerminalModeEnabled()) { + std::cout << "\033[1;32mRAM Usage\033[0m: " << std::fixed << std::setprecision(1) << memMB << " MB" << std::endl; + } else { + std::cout << "RAM Usage: " << std::fixed << std::setprecision(1) << memMB << " MB" << std::endl; + } + }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
main.cpp (2)
822-840:⚠️ Potential issue | 🔴 CriticalInteger overflow in GB/TB thresholds and divisors.
1000 * 1000 * 1000 * 1000is evaluated asintarithmetic (all literals areint), producing 10¹² which overflows a 32-bit signed integer. This is undefined behavior and will cause the GB comparison on Line 834 and TB division on Line 838 to produce garbage results. Confirmed by Cppcheck.Use
size_tcasts orULLsuffixes to force the arithmetic into a wide enough type:🐛 Proposed fix
- if (RAM < 1000) { - // if less than 1000 bytes (which is a kilobyte) then just return bytes - FRAM = std::to_string(RAM) + " B"; - } - else if (RAM < 1000 * 1000) { - - FRAM = std::to_string(RAM / 1000) + " KB"; - } - else if (RAM < 1000 * 1000 * 1000) { - - FRAM = std::to_string(RAM /( 1000 * 1000)) + " MB"; - } - else if (RAM < 1000 * 1000 * 1000 * 1000) { - FRAM = std::to_string(RAM /( 1000 * 1000 * 1000)) + " GB"; - } - else { - FRAM = std::to_string(RAM /( 1000 * 1000 * 1000 * 1000)) + " TB"; - // if someone actually reaches this i'm concerned - } + if (RAM < 1000ULL) { + FRAM = std::to_string(RAM) + " B"; + } + else if (RAM < 1000ULL * 1000) { + FRAM = std::to_string(RAM / 1000ULL) + " KB"; + } + else if (RAM < 1000ULL * 1000 * 1000) { + FRAM = std::to_string(RAM / (1000ULL * 1000)) + " MB"; + } + else if (RAM < 1000ULL * 1000 * 1000 * 1000) { + FRAM = std::to_string(RAM / (1000ULL * 1000 * 1000)) + " GB"; + } + else { + FRAM = std::to_string(RAM / (1000ULL * 1000 * 1000 * 1000)) + " TB"; + }
845-853:⚠️ Potential issue | 🟠 MajorNon-ANSI branch prints raw bytes instead of the formatted string.
Line 846 (ANSI path) correctly prints
FRAM, but Line 852 (non-ANSI path) printspmc.WorkingSetSize— the raw byte count. This means users without ANSI terminal support see something likeRAM Usage: 12345678instead ofRAM Usage: 12 MB.🐛 Proposed fix
} else { - std::cout << "RAM Usage: " << pmc.WorkingSetSize << std::endl; + std::cout << "RAM Usage: " << FRAM << std::endl; }
🧹 Nitpick comments (1)
main.cpp (1)
814-815: Consider zero-initializingPROCESS_MEMORY_COUNTERS.Uninitialized struct members could contain garbage if
GetProcessMemoryInfoever partially fills the struct. Minor defensive measure.Proposed fix
- PROCESS_MEMORY_COUNTERS pmc; + PROCESS_MEMORY_COUNTERS pmc{};
…by using unsigned long long
|
@coderabbitai YAY IT WORKS! what cool interesting stuff can we see from this now? D:\a\win-witr\win-witr>win-witr --pid 4 Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:01 +0000) D:\a\win-witr\win-witr>win-witr winlogon.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:31 +0000) D:\a\win-witr\win-witr>win-witr lsass.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:05 +0000) D:\a\win-witr\win-witr>win-witr win-witr.exe Why It Exists: Started: 0 seconds ago (Fri 2026-02-06 16:47:36 +0000) D:\a\win-witr\win-witr>win-witr wininit.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:05 +0000) D:\a\win-witr\win-witr>win-witr explorer.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:35 +0000) D:\a\win-witr\win-witr>win-witr Registry Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:00 +0000) D:\a\win-witr\win-witr>win-witr csrss.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:04 +0000) D:\a\win-witr\win-witr>win-witr fontdrvhost.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:07 +0000) D:\a\win-witr\win-witr>win-witr svchost.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:07 +0000) D:\a\win-witr\win-witr>win-witr smss.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:01 +0000) D:\a\win-witr\win-witr>win-witr services.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:05 +0000) D:\a\win-witr\win-witr>win-witr MsMpEng.exe Why It Exists: Started: 9 minutes ago (Fri 2026-02-06 16:38:10 +0000) D:\a\win-witr\win-witr>win-witr powershell.exe D:\a\win-witr\win-witr>win-witr Runner.Listener.exe Why It Exists: Started: 1 minutes ago (Fri 2026-02-06 16:46:23 +0000) D:\a\win-witr\win-witr>win-witr cmd.exe Why It Exists: Started: 0 seconds ago (Fri 2026-02-06 16:47:36 +0000) D:\a\win-witr\win-witr>win-witr pwsh.exe Why It Exists: Started: 35 seconds ago (Fri 2026-02-06 16:47:01 +0000) D:\a\win-witr\win-witr>win-witr Runner.Worker.exe Why It Exists: Started: 1 minutes ago (Fri 2026-02-06 16:46:24 +0000) D:\a\win-witr\win-witr>win-witr hosted-compute-agent Why It Exists: Started: 8 minutes ago (Fri 2026-02-06 16:39:12 +0000) Why It Exists: Started: 8 minutes ago (Fri 2026-02-06 16:39:16 +0000) |
|
Tip For best results, initiate chat on the files or code changes.
Fascinating Memory PatternsKernel Pseudo-Processes:
Heavyweight vs. Lightweight:
GitHub Actions Infrastructure:
Critical System Services:
Why This Is So UsefulNow you can:
The fact that you get RAM info for System and Registry (where everything else fails) is particularly valuable - it proves the process exists and shows its memory footprint even when access is heavily restricted. Great feature addition! 🚀 🧠 Learnings used |
Summary by CodeRabbit