-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The roughest of performance measurements
- Loading branch information
Showing
13 changed files
with
126 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tillerinobot-model/src/main/java/org/tillerino/ppaddict/util/PhaseTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.tillerino.ppaddict.util; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* This is a simple timer to measure the duration of phases of a process. | ||
* Since there is a lot of heap activity, this is meant for rough measurements. | ||
* It is meant to be serialized to be able to trace events through all queues and threads. | ||
*/ | ||
@Getter | ||
@Setter | ||
public class PhaseTimer { | ||
public static final String PREPROCESS = "preprocess"; | ||
public static final String INTERNAL_QUEUE = "eventQueue"; | ||
public static final String THREAD_POOL_QUEUE = "threadPoolQueue"; | ||
public static final String HANDLE = "handle"; | ||
public static final String RESPONSE_QUEUE = "responseQueue"; | ||
public static final String POSTPROCESS = "postprocess"; | ||
|
||
private long endOfLastPhase = System.nanoTime(); | ||
private @Nullable List<Phase> completedPhases; | ||
|
||
public void completePhase(String name) { | ||
long now = System.nanoTime(); | ||
if (completedPhases == null) { | ||
completedPhases = new ArrayList<>(); | ||
} | ||
completedPhases.add(new Phase(name, now - endOfLastPhase)); | ||
endOfLastPhase = now; | ||
} | ||
|
||
public void print() { | ||
if (completedPhases == null) { | ||
return; | ||
} | ||
System.out.println("total:" + leftPad((int) Math.round(completedPhases.stream().mapToLong(p -> p.duration).sum() / 1_000_000D)) + "ms" | ||
+ completedPhases.stream() | ||
.map(p -> ", " + p.name + ":" + leftPad((int) Math.round(p.duration / 1_000_000D)) + "ms") | ||
.collect(Collectors.joining())); | ||
} | ||
|
||
public static String leftPad(int x) { | ||
return StringUtils.leftPad(Integer.toString(x), 5); | ||
} | ||
|
||
record Phase(String name, long duration) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.