Skip to content

Commit

Permalink
Revert "Revert "Cleanup RecipeScheduler and associated logic (#2860)…
Browse files Browse the repository at this point in the history
…"" (#2870)
  • Loading branch information
JLLeitschuh authored Feb 21, 2023
1 parent 88859be commit 136223f
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 102 deletions.
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

0 comments on commit 136223f

Please sign in to comment.