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

Add -Zerror-metrics=PATH to save diagnostic metadata to disk #119355

Closed
wants to merge 1 commit into from

Conversation

estebank
Copy link
Contributor

Add nightly only flag to store information about encountered errors to disk. The information being tracked is:

  • Error code
  • Path to error being emitted
  • Number of subdiagnostics
  • Number of structured suggestions

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2023
@estebank estebank marked this pull request as ready for review December 27, 2023 18:23
@rust-log-analyzer

This comment has been minimized.

Add nightly only flag to store information about encountered errors
to disk. The information being tracked is:

 - Error code
 - Path to error being emitted
 - Number of subdiagnostics
 - Number of structured suggestions
if let Some(ref mut file) = &mut self.metrics {
let _ = writeln!(
file,
"{:?},{:?},{},{}",
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using this custom format when we already have JSON diagnostic output?

Even if we shouldn't be emitting as much info as JSON-formatted diagnostics, we should perhaps make it easier for arbitrary programs to consume by formatting it like JSON.

Copy link
Member

Choose a reason for hiding this comment

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

There's no particular reason; I think the goal here was just to get something in initially so that the flag wasn't just sitting around as dead code. After some discussion, we've decided to go more in the direction that Mark suggested and lean on downstream consumers of the JSON (specifically cargo) for the specific metrics included in this PR. For now, we're going to focus on the ICE reporting mechanism as the initial metric to coexist with the flag since that's actually the one we care about the most.

let metrics = sopts.unstable_opts.error_metrics.as_ref().and_then(|path| {
let mut path = path.clone();
std::fs::create_dir_all(&path).ok()?;
path.push(format!("error_metrics_{}", std::process::id()));
Copy link
Member

Choose a reason for hiding this comment

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

Why PID? Can we use something more ordered such as YYYY-MM-DD-HH-SS-PID?

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure of the precise reasoning behind using PID, but I have no objections to switching to datetime-pid. We can definitely use that instead.

@Mark-Simulacrum
Copy link
Member

Does this need to be in rustc? What is the intended consumption workflow (is there intent to stabilize this)? I would expect that ~all of this information is already available to programs running rustc with errors emitted as JSON (e.g., Cargo) and they could handle aggregating and propagating that information.

@bors
Copy link
Contributor

bors commented Jan 5, 2024

☔ The latest upstream changes (presumably #119621) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2024
@Dylan-DPC
Copy link
Member

@estebank any updates on this? thanks

@yaahc
Copy link
Member

yaahc commented Jul 31, 2024

Hey y'all. I'm going to be picking up some of this work and wanted to give a quick update on the next steps I'm planning and respond to the questions in the thread.

Does this need to be in rustc? ... I would expect that ~all of this information is already available to programs running rustc with errors emitted as JSON (e.g., Cargo) and they could handle aggregating and propagating that information.

@Mark-Simulacrum, the specific metrics included in this PR, such as the counts of specific error codes and subdiagnostics, definitely don't need to live in rustc, and we have no objection to moving those downstream to the consumers of the JSON output. There will still need to be some machinery in rustc for metrics we care about that don't make sense to emit to cargo or other consumers, such as saving ICE reports or logging for events that we might turn into assertions in the future (e.g. incremental compilation and situations like https://blog.rust-lang.org/2021/05/10/Rust-1.52.1.html.

What is the intended consumption workflow

The plans for consumption workflows are mostly forming at the moment; we've thrown around ideas like having cargo plugins to summarize information, asking users to grep metrics for specific events on nightly, building support within crater/perf to search for issues in the metrics output, or having rust-analyzer look for issues and notify users when they've encountered a problem we'd like reported. I imagine the direction we go will depend heavily on the issues that we first start leveraging the metrics to track.

(is there intent to stabilize this)?

The only part we anticipate wanting to stabilize is the flag itself, as per the MCP, which configures the directory where metrics should be stored.

Plan going forward

I will close this PR and open a new one that adds the flag and uses it as the default location for saving ICE reports, assuming the RUST_ICE environment variable isn't set.

@Dylan-DPC
Copy link
Member

Closing this as per #119355 (comment)

@Dylan-DPC Dylan-DPC closed this Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants