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

Revert "Revert "Cleanup RecipeScheduler and associated logic (#2860)"" #2870

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions rewrite-core/src/main/java/org/openrewrite/RecipeRunStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class RecipeRunStats {
public RecipeRunStats(Recipe recipe) {
this.recipe = recipe;
if (recipe.getRecipeList().isEmpty()) {
this.called = new ArrayList<>();
called = new ArrayList<>();
} else {
this.called = new ArrayList<>(recipe.getRecipeList().size());
called = new ArrayList<>(recipe.getRecipeList().size());
for (Recipe callee : recipe.getRecipeList()) {
called.add(new RecipeRunStats(callee));
addCalledRecipe(callee);
}
}
}
Expand All @@ -54,7 +54,17 @@ public RecipeRunStats(Recipe recipe) {
@Getter
List<RecipeRunStats> called;

AtomicInteger calls = new AtomicInteger();
RecipeRunStats addCalledRecipe(Recipe recipe) {
RecipeRunStats stats = new RecipeRunStats(recipe);
called.add(stats);
return stats;
}

private AtomicInteger calls = new AtomicInteger();

void markCall() {
calls.incrementAndGet();
}

/**
* The number of times the recipe ran over all cycles.
Expand All @@ -63,7 +73,7 @@ public int getCalls() {
return calls.get();
}

final AtomicLong cumulative = new AtomicLong();
private final AtomicLong cumulative = new AtomicLong();

/**
* The total time spent across all executions of this recipe.
Expand All @@ -72,7 +82,7 @@ public Duration getCumulative() {
return Duration.ofNanos(cumulative.get());
}

final AtomicLong max = new AtomicLong();
private final AtomicLong max = new AtomicLong();

/**
* The max time spent in any one execution of this recipe.
Expand All @@ -81,7 +91,16 @@ public Duration getMax() {
return Duration.ofNanos(max.get());
}

AtomicLong ownGetVisitor = new AtomicLong();
/**
* Called when the recipe being visited is completed.
*/
void recipeVisitCompleted(long startTime) {
long totalTime = System.nanoTime() - startTime;
max.compareAndSet(Math.min(max.get(), totalTime), totalTime);
cumulative.addAndGet(totalTime);
}

private AtomicLong ownGetVisitor = new AtomicLong();

/**
* The total time spent in running the visitor returned by {@link Recipe#getVisitor()}
Expand All @@ -91,7 +110,11 @@ public Duration getOwnGetVisitor() {
return Duration.ofNanos(ownGetVisitor.get());
}

AtomicLong ownVisit = new AtomicLong();
void ownGetVisitorCompleted(long ownGetVisitorStartTime) {
ownGetVisitor.addAndGet(System.nanoTime() - ownGetVisitorStartTime);
}

private AtomicLong ownVisit = new AtomicLong();

/**
* The total time spent in running the visitor returned by {@link Recipe#visit(List, ExecutionContext)}()}
Expand All @@ -101,6 +124,10 @@ public Duration getOwnVisit() {
return Duration.ofNanos(ownVisit.get());
}

void ownVisitCompleted(long ownVisitStartTime) {
ownVisit.addAndGet(System.nanoTime() - ownVisitStartTime);
}

@Incubating(since = "7.29.0")
public String printAsMermaidGantt(double scale) {
StringBuilder gantt = new StringBuilder("gantt\n");
Expand Down
Loading