Skip to content
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

[ads] Profile performance using TRACE events #27181

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Jan 9, 2025

Resolves brave/brave-browser#21106

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@tmancey tmancey self-assigned this Jan 9, 2025
@tmancey tmancey force-pushed the issues/21106 branch 5 times, most recently from 5ae4e5d to 4987e7f Compare January 10, 2025 15:29
@tmancey tmancey changed the title [ads] Profile performance with TRACE events [ads] Profile performance using TRACE events Jan 10, 2025
@tmancey tmancey marked this pull request as ready for review January 10, 2025 16:25
@tmancey tmancey requested review from a team as code owners January 10, 2025 16:25
Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

chromium_src++

Copy link
Contributor

[puLL-Merge] - brave/brave-core@27181

Here's a description and analysis of the pull request:

Description

This PR adds tracing and performance monitoring capabilities to the Brave Ads component. It introduces trace events at various points in the ad serving pipeline, allowing for better performance analysis and debugging. The changes primarily involve adding trace events, restructuring some callback flows, and improving error handling.

Changes

Changes

  1. chromium_src/base/trace_event/builtin_categories.h:

    • Added "brave.ads" to the list of builtin tracing categories.
  2. Multiple files:

    • Added #include "base/trace_event/trace_event.h" and #include "base/location.h" to various files.
    • Introduced TRACE_EVENT and TRACE_EVENT_NESTABLE_ASYNC_BEGIN/END macros throughout the codebase to instrument key functions and operations.
  3. components/brave_ads/core/internal/database/database.cc:

    • Added tracing to RunDBTransaction, RunDBActions, MaybeRaze, and MaybeVacuum methods.
  4. components/brave_ads/core/internal/serving/ directory:

    • Added tracing to various ad serving pipelines (inline content, new tab page, notification).
    • Restructured some callback flows to include trace IDs for better tracking.
  5. components/brave_ads/core/internal/targeting/ directory:

    • Added tracing to text classification processor.
  6. components/brave_ads/core/internal/user_engagement/ directory:

    • Added tracing to conversion checking and site visit tracking.
  7. components/brave_ads/core/public/ads_constants.h:

    • Defined a new constant kTraceEventCategory for "brave.ads".
sequenceDiagram
    participant User
    participant BraveAds
    participant Database
    participant AdServing
    participant Targeting
    participant UserEngagement

    User->>BraveAds: Interact with browser
    BraveAds->>Database: RunDBTransaction
    Note over Database: TRACE_EVENT: Database operations
    Database-->>BraveAds: Transaction result

    BraveAds->>AdServing: Serve ad
    Note over AdServing: TRACE_EVENT: Ad serving pipeline
    AdServing->>Targeting: Get user model
    Note over Targeting: TRACE_EVENT: Text classification
    Targeting-->>AdServing: User model
    AdServing->>UserEngagement: Check for conversions
    Note over UserEngagement: TRACE_EVENT: Conversion checking
    UserEngagement-->>AdServing: Conversion result
    AdServing-->>BraveAds: Served ad

    BraveAds->>User: Display ad
Loading

Possible Issues

  • The increased number of trace events may have a small performance impact, especially if tracing is enabled in production builds.
  • Some of the restructured callback flows might introduce subtle timing changes in the ad serving pipeline.

Security Hotspots

No significant security issues are apparent in this change. The tracing additions don't expose sensitive information and are primarily for debugging and performance analysis.

This sequence diagram illustrates the high-level flow of the Brave Ads system with the newly added trace events, showing how various components interact and where tracing has been added for performance monitoring.

@tmancey tmancey force-pushed the issues/21106 branch 3 times, most recently from 8589703 to a81e13d Compare January 10, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ads] Profile performance with TRACE events
2 participants