Skip to content

cobalt/metrics: Add interfaces and stubs for granular memory tracking.#10017

Open
Awallky wants to merge 1 commit intoyoutube:mainfrom
Awallky:feature/granular-memory-cl1-stubs
Open

cobalt/metrics: Add interfaces and stubs for granular memory tracking.#10017
Awallky wants to merge 1 commit intoyoutube:mainfrom
Awallky:feature/granular-memory-cl1-stubs

Conversation

@Awallky
Copy link
Copy Markdown
Contributor

@Awallky Awallky commented Apr 14, 2026

This commit introduces the DetailedMetricsDelegate interface and necessary
stubs in OSMetrics to support custom memory categorization in Cobalt.
It also includes a Starboard wrapper for prctl to support VMA naming.

  • Add DetailedMetricsDelegate interface.
  • Add stubs in OSMetrics for delegate interaction.
  • Add Starboard wrapper for prctl (VMA naming).

Bug: 494004530

@Awallky Awallky requested a review from a team as a code owner April 14, 2026 04:55
@Awallky Awallky requested a review from andrewsavage1 April 14, 2026 04:55
@github-actions
Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


cobalt: Add interfaces for granular memory tracking

This change introduces the DetailedMetricsDelegate interface and
associated infrastructure within the memory instrumentation service.
It enables project-specific collection and categorization of detailed
memory metrics, particularly by processing /proc/self/smaps data.

The goal is to provide a mechanism for Cobalt to implement granular
memory tracking for its components, facilitating deeper insights into
memory usage for optimization and debugging.

Bug: 494004530

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the DetailedMetricsDelegate interface and DetailedMetrics structure to enable project-specific memory metrics collection. It updates MemoryInstrumentation and OSMetrics to integrate this delegate and adds conditional Mojo fields for detailed stats. Key feedback includes providing definitions for the DetailedMetrics lifecycle methods to prevent linker errors, removing redundant global state in OSMetrics in favor of explicit parameter passing, and addressing thread-safety concerns regarding raw pointer access to the delegate.

Comment on lines +20 to +23
DetailedMetrics();
~DetailedMetrics();
DetailedMetrics(DetailedMetrics&&);
DetailedMetrics& operator=(DetailedMetrics&&);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The DetailedMetrics struct declares a constructor, destructor, and move operations but does not provide definitions. Since this is a new header and no corresponding .cc file is included in the PR, this will result in linker errors. If these are intended to be default implementations, they should be defined as = default in the header. Additionally, per Chromium style, move operations should be marked noexcept to allow for optimizations when used in containers.

  DetailedMetrics() = default;
  ~DetailedMetrics() = default;
  DetailedMetrics(DetailedMetrics&&) noexcept = default;
  DetailedMetrics& operator=(DetailedMetrics&&) noexcept = default;
References
  1. Adhere to established upstream Chromium style guides for C++ code, including the use of = default and noexcept for move operations. (link)

Comment on lines +79 to +80
static void SetDetailedMetricsDelegate(
class DetailedMetricsDelegate* delegate);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The addition of a static SetDetailedMetricsDelegate method introduces global state into the OSMetrics utility class. Since FillOSMemoryDump has been updated to accept a DetailedMetricsDelegate* as a parameter (line 57), this static setter is redundant and creates ambiguity regarding which delegate is used. It is better to pass the delegate explicitly through the call chain to keep OSMetrics stateless and easier to test, consistent with Chromium's preference for avoiding global state in utility classes.

References
  1. Follow Chromium best practices by avoiding global state in utility classes and preferring explicit dependency injection via parameters. (link)

void SetDetailedMetricsDelegate(class DetailedMetricsDelegate* delegate);

// Get the registered delegate.
class DetailedMetricsDelegate* GetDetailedMetricsDelegate() const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Returning a raw pointer to the delegate from GetDetailedMetricsDelegate() is potentially unsafe, even with the use of detailed_metrics_delegate_lock_. Once the lock is released, the caller holds a pointer that could be nullified or the underlying object destroyed by another thread (e.g., via a call to SetDetailedMetricsDelegate). Consider a safer access pattern, such as passing the delegate directly to the methods that require it, or using a callback/observer pattern if the lifetime cannot be strictly guaranteed.

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.

1 participant