Add a AutoProfiler helper allowing a custom receiver.
Add a new AutoProfiler helper which logs for operations exceeding provided
latency threshold and always calls a provided custom receiver.
@@ -64,6 +64,17 @@ public class GoogleAutoProfilerUtils {
new SequencedElapsedTimeReceiver(profilingReceiver, createSimpleLogger(taskDescription)));
}
+ /**
+ * Returns an {@link AutoProfiler} that, when closed, will log if the operation exceeds provided
+ * threshold and call the custom {@link ElapsedTimeReceiver} for any duration.
+ */
+ public static AutoProfiler loggedAndCustomReceiver(
+ String taskDescription, Duration minTimeForLogging, ElapsedTimeReceiver customReceiver) {
+ return AutoProfiler.create(
+ new SequencedElapsedTimeReceiver(
+ makeReceiver(taskDescription, selfLogger, minTimeForLogging), customReceiver));
+ }
+
private static ElapsedTimeReceiver makeReceiver(
String description, GoogleLogger logger, Duration minTimeForLogging) {
return new FloggerElapsedTimeReceiver(description, logger, minTimeForLogging);
