| name | histogram-cleanup |
| description | Identify and safely remove expired Chromium histograms (dead metrics/technical debt). Use this skill when a contributor asks to clean up metrics, fix code health issues related to histograms, remove obsolete code, or work on a histogram cleanup task. |
Code Health: Histogram Cleanup
Identify and safely remove "dead code" associated with expired histograms. This
includes removing the recording calls in C++/Java, cleaning up the metadata in
histograms.xml, and addressing any dependent tests.
Overview
Expired histograms that are not intentionally kept for diagnostics represent
technical debt. Act as an expert Chromium contributor specializing in Metrics to
clean up these resources while ensuring no test regressions occur.
Goal: Remove expired Chromium histograms (dead metrics) from XML files and
all code recording sites.
Relevant Resources & Style Guides
Scope & Proactivity
- Primary Scope: Focus exclusively on the identified histogram by default.
Do NOT suggest removing random additional histograms across the file or
component just because they are expired.
- Exception for Coupled/Shared Recording Code: If other histograms share the
exact same recording logic, helper methods, or calculated variables (e.g.,
co-located in the same helper function or branching from the same condition)
as the target histogram, their removal MAY be bundled into the same cleanup
plan IF AND ONLY IF:
- Expiry Verification: Confirm in
histograms.xml that the co-located
histograms are also expired and lack the <expired_intentionally> tag.
- Safety Verification: Perform the same safety checks (no test
dependencies, no external repo references) for each bundled histogram.
- Atomic Benefit: Removing them together cleanly eliminates shared
boilerplate (e.g., timer calculations, string building, parameter passing)
that would otherwise be left as dead or awkward code.
- Related Dead Code: If dead code is found (e.g., constants, enums, or
helper methods, or calculated variables like timers) that is directly related
to the histogram(s) being removed, include its removal in the cleanup plan.
Present these as part of the primary task, not as separate "proactive
suggestions."
Workflow
[!IMPORTANT] Execution Protocol: Execute all steps sequentially one by
one. Do not skip any step. Do not use edit-code or grep. Use rg
(ripgrep) for searches.
Step 1: Workspace Preparation
Follow the workspace preparation steps in
workspace_preparation.md to ensure
a clean and updated environment.
Step 2: Discovery & Batch Selection
Follow the
Discovery & Batch Selection
workflow.
Step 3: Deep Dive & Safety Analysis
-
Comprehensive Analysis: Delegate the entire deep dive to the
generalist sub-agent with this exact prompt:
"Read references/analysis_guidelines.md and follow the 'Generalist Deep
Dive Prompt' instructions for the histogram <HistogramName>. ALL
read-only discovery (including rg and cs) is pre-authorized; DO NOT ask
for permission. Assume rg is available in the environment."
-
Present Findings & Evaluate Confidence: Evaluate the Confidence Score
returned by the generalist.
- If Confidence >= 9: Inform the user: "Confidence is high ([X]/10).
Proceeding with cleanup based on this plan: [Removal Plan Summary]." Output
this message, then proceed directly to the Refactoring & Implementation
phase. Do NOT ask for permission.
- If Confidence is between 1 and 8: Present the findings and prompt the
user using
ask_user (type='choice'):
header: "Confidence Check"
question: "This histogram is safe to remove from [Files] and [Tests].
My confidence for this cleanup is [X]/10 because [Justification]. Shall I
proceed with the cleanup diff?"
options:
label: "Proceed with Diff", description: "Generate and apply the
cleanup changes"
label: "Discard", description: "Discard this candidate and stop."
- Action based on selection:
- If "Proceed with Diff": Proceed to the Refactoring & Implementation
phase.
- If "Discard": Stop the workflow.
- If Confidence is 0: Inform the user: "Confidence is zero (0/10) because
[Justification]. An alternate expired histogram will be found." Immediately
restart the workflow from the Discovery & Batch Selection phase to
identify a different candidate. Ensure the same histogram is not selected
again in this session.
Step 4: Refactoring & Implementation
Process the changes file by file, and apply modifications inside each file
one recording call at a time (rather than refactoring all files or recording
calls at once). This ensures stability and allows for precise verification.
- Apply Changes: Make the changes directly. Apply the code modifications
for the candidate histogram. When removing recording calls, carefully check
if the string literal spans multiple lines and ensure the entire multi-line
statement is cleanly removed. Search for dot-less versions of the name to
ensure related constants are also removed. Check for and update any
references to the histogram in code comments as well. For each removal,
ensure no orphaned references (e.g., unused variables or methods) remain in
the codebase. Each individual change must have a corresponding 'What & Why'
explanation provided to the user.
Step 5: Validation
- Linting & Formatting:
- XML Linting: Execute
python3 tools/metrics/histograms/validate_format.py to validate all
metadata changes. Address any errors that are reported.
- Code Formatting: Execute
git cl format to format the modified source
code. Address any errors that are reported.
- Mandatory Final Review: Follow the
Automated Review Protocol to delegate a
final review of the patch to the
generalist sub-agent. Proceed to the
Verification phase only after the review returns PASS.
Step 6: Verification
Follow the Verification workflow.
Step 7: Submission
-
Bug Tracking:
- Execute the Bug Discovery and Triage workflow in
references/bug_discovery.md using the <HistogramName> and
<ExpiryDate> from the candidate.
- Interactive Pause: Do NOT proceed until the bug handling is resolved
and a Bug ID is resolved (or the user has chosen to skip).
-
Upload Pipeline:
- Invoke the Submission workflow. Pass the
following context variables to the workflow:
- Skill Name:
histogram-cleanup
- Branch Name:
cleanup-<HistogramName>
- Commit Hashtag:
histogram-cleanup
- Cleanup Title:
Remove expired histogram: <HistogramName>
- Cleanup Description:
Remove expired histogram <HistogramName> which expired on <ExpiryDate> and has no recording sites.
- Parent Bug:
499059525
- Bug ID: The resolved
<Bug ID> from the Bug Tracking step.
- Cleaned Component:
histograms.xml
- File Count: Number of files modified during this cleanup.