Add support for SLF4J logging in :api
This commit is contained in:
@@ -11,4 +11,5 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.joml:joml:${jomlVersion}"
|
||||
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.bartlomiejpluta.base.api.util.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,6 +13,8 @@ import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
public class FPSProfiler {
|
||||
private static final Logger log = LoggerFactory.getLogger(FPSProfiler.class);
|
||||
|
||||
private static final int MOD = 30;
|
||||
private final List<Double> values = new LinkedList<>();
|
||||
private float fpsAccumulator = 0;
|
||||
@@ -29,7 +34,7 @@ public class FPSProfiler {
|
||||
}
|
||||
|
||||
public void printResult() {
|
||||
System.out.format("Min FPS: %f, max FPS: %f, avg FPS: %f",
|
||||
log.info("Min FPS: {}, max FPS: {}, avg FPS: {}",
|
||||
values.stream().min(Double::compareTo).orElse(-1.0),
|
||||
values.stream().max(Double::compareTo).orElse(-1.0),
|
||||
totalAverage()
|
||||
@@ -51,6 +56,6 @@ public class FPSProfiler {
|
||||
.entrySet()
|
||||
.stream()
|
||||
.sorted(comparingInt(Map.Entry::getKey))
|
||||
.forEach(e -> System.out.printf("%s FPS: %f%% (%d occurrences)", e.getKey(), e.getValue() * 100.0f / values.size(), e.getValue()));
|
||||
.forEach(e -> log.info("{} FPS: {}% ({} occurrences)", e.getKey(), e.getValue() * 100.0f / values.size(), e.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.bartlomiejpluta.base.api.util.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class TimeProfiler {
|
||||
private static final Logger log = LoggerFactory.getLogger(TimeProfiler.class);
|
||||
|
||||
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||
private final Map<String, Double> averages = new HashMap<>();
|
||||
|
||||
@@ -24,7 +29,7 @@ public class TimeProfiler {
|
||||
public void printResult() {
|
||||
averages.entrySet().stream()
|
||||
.sorted(Entry.<String, Double>comparingByValue().reversed())
|
||||
.forEachOrdered(entry -> System.out.format("[%s]: [%sms] [%sus] [%sns]",
|
||||
.forEachOrdered(entry -> log.info("[{}]: [{}sms] [{}sus] [{}ns]",
|
||||
entry.getKey(),
|
||||
DF.format(entry.getValue() / 1_000_000),
|
||||
DF.format(entry.getValue() / 1_000),
|
||||
|
||||
Reference in New Issue
Block a user