Skip to content

Conversation

@itssimon
Copy link
Member

@itssimon itssimon commented Nov 29, 2025

Summary by CodeRabbit

  • New Features

    • System now captures and includes CPU and memory metrics with sync reports, giving enhanced visibility into resource usage over time and improving performance monitoring and diagnostics.
  • Chores

    • Payload structure extended to carry optional resource metrics alongside existing telemetry.

✏️ Tip: You can customize this high-level summary in your review settings.

@itssimon itssimon self-assigned this Nov 29, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Walkthrough

Adds CPU and memory reporting to sync payloads: a new getCpuMemoryUsage() utility computes CPU percent and memory RSS between calls, SyncPayload gains an optional resources field, and sendSyncData() in the client now includes the utility's result in the payload.

Changes

Cohort / File(s) Summary
Resource Monitoring Utilities
src/common/resources.ts
New function getCpuMemoryUsage() that keeps internal state to compute CPU usage delta and elapsed time, returning { cpu_percent: number; memory_rss: number } or null on first call.
Type Definition Updates
src/common/types.ts
Extended SyncPayload with an optional resources field typed as { cpu_percent: number; memory_rss: number } | null.
Client Integration
src/common/client.ts
Imports getCpuMemoryUsage() and adds its return value into the resources field of the SyncPayload within sendSyncData() (first-call may be null).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Review CPU percentage calculation and time-unit consistency in src/common/resources.ts.
  • Confirm resources typing in src/common/types.ts matches the function's return signature and is optional/null-safe.
  • Validate src/common/client.ts correctly handles null from the first getCpuMemoryUsage() call when building the payload.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Capture CPU and memory metrics' directly and clearly describes the main change: adding CPU and memory usage tracking to the sync payload.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cpu-memory-metrics

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9962191 and 676770a.

📒 Files selected for processing (1)
  • src/common/resources.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/common/resources.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: wait-for-triggered-checks

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/common/resources.ts (1)

13-22: Consider edge case: division by zero.

If getCpuMemoryUsage() is called twice within the same millisecond, elapsedTime would be 0, resulting in Infinity for cpuPercent. While extremely unlikely given the sync intervals (10-60 seconds), consider adding a guard:

 // Calculate elapsed time in microseconds
 const elapsedTime = (currentTime - lastCpuTime) * 1000;

+// Guard against division by zero
+if (elapsedTime === 0) {
+  lastCpuUsage = currentCpuUsage;
+  lastCpuTime = currentTime;
+  return null;
+}
+
 // Calculate CPU time used (user + system) in microseconds
 const cpuTime =
   currentCpuUsage.user -
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69cf0cd and 9962191.

📒 Files selected for processing (3)
  • src/common/client.ts (2 hunks)
  • src/common/resources.ts (1 hunks)
  • src/common/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/common/client.ts (1)
src/common/resources.ts (1)
  • getCpuMemoryUsage (4-35)
🔇 Additional comments (2)
src/common/types.ts (1)

97-100: LGTM! Clean type definition.

The resources field is properly typed to handle both the metric data and null case for the initial measurement.

src/common/client.ts (1)

9-9: LGTM! Clean integration of CPU/memory metrics.

The function is correctly imported and integrated into the sync payload. The periodic sync intervals (10-60 seconds) are appropriate for measuring CPU usage deltas.

Also applies to: 229-229

@codecov
Copy link

codecov bot commented Nov 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.37%. Comparing base (69cf0cd) to head (676770a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #188      +/-   ##
==========================================
+ Coverage   88.28%   88.37%   +0.09%     
==========================================
  Files          44       45       +1     
  Lines        3755     3785      +30     
  Branches      533      536       +3     
==========================================
+ Hits         3315     3345      +30     
  Misses        419      419              
  Partials       21       21              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@itssimon itssimon merged commit c4fd6f9 into main Nov 30, 2025
76 checks passed
@itssimon itssimon deleted the cpu-memory-metrics branch November 30, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants