Skip to content

RecipeRunStats source file count exceeds number of files in project #4876

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

Closed
Bananeweizen opened this issue Jan 9, 2025 · 7 comments · Fixed by #5408
Closed

RecipeRunStats source file count exceeds number of files in project #4876

Bananeweizen opened this issue Jan 9, 2025 · 7 comments · Fixed by #5408
Assignees
Labels
bug Something isn't working

Comments

@Bananeweizen
Copy link
Contributor

What is the smallest, simplest way to reproduce the problem?

Enable datatables on a small project, open RecipeRunStats.csv and sort by first column (edited source files).

What did you see instead?

image

That's from a project with 2600 files in the repo (Java, Maven, adoc, ....), therefore I would expect none of the numbers to be larger than 2600.

If you agree to that assumption, then

seems to be wrong. This is called unconditionally inside 2 nested loops for recipes and files, thereby incrementing the counter by files*recipes or something like that.
It might need to be moved inside the if visitor.isAcceptable() condition.

This bug does not create any wrong code with rewrite recipes. It just makes it harder to use the numbers in the data tables to look for "extreme" recipes or similar oddities.

Are you interested in contributing a fix to OpenRewrite?

@Bananeweizen Bananeweizen added the bug Something isn't working label Jan 9, 2025
@timtebeek
Copy link
Member

Thanks for the analysis with examples here @Bananeweizen ! Agree that it looks off, and would be better if we ensure these numbers line up with the number of files, as opposed to number of files * number of recipes (?). I'll raise this to the team!

@arodionov arodionov self-assigned this May 6, 2025
@arodionov arodionov moved this to In Progress in OpenRewrite May 6, 2025
@arodionov
Copy link
Contributor

I see that only particular recipes produce the wrong sourceFiles stats

In the test repo are 12056 files.
For org.openrewrite.staticanalysis.CommonStaticAnalysis, the stats were correct.
For org.openrewrite.java.migrate.UpgradeToJava17 it doesn't:

Image

@timtebeek
Copy link
Member

At a quick glance those all seem to be multiples of the number of files, where AddJaxwsRuntime likely only runs once, whereas the others are configurable and may thus be included more than once.

What are you proposing in terms of a fix?

@arodionov
Copy link
Contributor

Yes, it seems that if a recipe is run with different parameters, the number of files visited is summed up.

In terms of fix:

  • trying to create a unit test to fail (because initial unit tests passed successfully)
  • trying to find the place where the multiplication happens

@arodionov
Copy link
Contributor

The counter issue is related to recordEdit method:

public @Nullable SourceFile recordEdit(Recipe recipe, Callable<SourceFile> edit) throws Exception {
return Timer.builder("rewrite.recipe.edit")
.tag("name", recipe.getName())
.publishPercentiles(0.99)
.register(registry)
.recordCallable(edit);
}

When the same recipe is executed several times with different parameters, the tag("name", recipe.getName()) will be the same.
The recordEdit triggers CumulativeTimer#recordNonNegative method, which automatically increments the counter for the same recipe:

Image

Image

So, we can't simply change the CumulativeTimer#recordNonNegative behaviour.
If we skip recordEdit for the same recipe, I assume, this will also impact the time statistics.

Perhaps, there is some other suitable Timer (or we can implement it).
Another option is to create different tags for the same recipes with different parameters, but before flushing Rows, we should collapse and aggregate statistics for the same recipe.

// @timtebeek

@arodionov
Copy link
Contributor

Unit test with the reproducer https://github.com/openrewrite/rewrite/compare/stats-issue-4876

@timtebeek
Copy link
Member

Thanks again for pointing out this mismatch @Bananeweizen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants