more cleanup
This commit is contained in:
parent
47a88fac4a
commit
ec23bbd64c
3 changed files with 26 additions and 12 deletions
|
|
@ -15,10 +15,17 @@ import java.util.List;
|
|||
|
||||
public class Agent {
|
||||
|
||||
public static final String MESSAGE = "Perfix agent active";
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation inst) {
|
||||
System.out.println("Perfix agent active");
|
||||
System.out.println(MESSAGE);
|
||||
|
||||
startListeningOnSocket();
|
||||
|
||||
instrumentCode(inst);
|
||||
}
|
||||
|
||||
private static void instrumentCode(Instrumentation inst) {
|
||||
List<String> includes = determineIncludes();
|
||||
|
||||
inst.addTransformer((classLoader, resource, aClass, protectionDomain, uninstrumentedByteCode) -> {
|
||||
|
|
@ -30,7 +37,6 @@ public class Agent {
|
|||
}
|
||||
} catch (Exception ex) {
|
||||
//suppress
|
||||
|
||||
}
|
||||
}
|
||||
return uninstrumentedByteCode;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ public class Method {
|
|||
private final String name;
|
||||
private long t1;
|
||||
|
||||
public Method(String name) {
|
||||
private Method(String name) {
|
||||
t0 = System.nanoTime();
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,27 +8,35 @@ import java.util.concurrent.atomic.LongAdder;
|
|||
|
||||
public class Registry {
|
||||
|
||||
static final Map<String, List<Method>> methods = new ConcurrentHashMap<>();
|
||||
private static final Map<String, List<Method>> methods = new ConcurrentHashMap<>();
|
||||
private static final double NANO_2_MILLI = 1000000D;
|
||||
private static final String HEADER1 = "Invoked methods, by duration desc:";
|
||||
private static final String HEADER2 = "Method name;#Invocations;Total duration;Average Duration";
|
||||
private static final String FOOTER = "----------------------------------------";
|
||||
|
||||
static void add(Method method) {
|
||||
methods.computeIfAbsent(method.getName(), key -> new ArrayList<>()).add(method);
|
||||
}
|
||||
|
||||
public static void report(PrintStream out) {
|
||||
out.println("Invoked methods, by duration desc:");
|
||||
out.println("Method name;#Invocations;Total duration;Average Duration");
|
||||
sortedMethodsByDuration().forEach((k, report) -> {
|
||||
out.println(report.name + ";" + report.invocations + ";" + (long)(report.totalDuration / NANO_2_MILLI) + ";" + (long)(report.average() / NANO_2_MILLI));
|
||||
});
|
||||
out.println("----------------------------------------");
|
||||
out.println(HEADER1);
|
||||
out.println(HEADER2);
|
||||
sortedMethodsByDuration().entrySet().stream()
|
||||
.map(entry -> createReportLine(entry.getValue()))
|
||||
.forEach(out::println);
|
||||
out.println(FOOTER);
|
||||
}
|
||||
|
||||
private static String createReportLine(Report report) {
|
||||
return report.name + ";"
|
||||
+ report.invocations + ";"
|
||||
+ (long) (report.totalDuration / NANO_2_MILLI) + ";"
|
||||
+ (long) (report.average() / NANO_2_MILLI);
|
||||
}
|
||||
|
||||
private static SortedMap<Long, Report> sortedMethodsByDuration() {
|
||||
SortedMap<Long, Report> sortedByTotal = new ConcurrentSkipListMap<>(Comparator.reverseOrder());
|
||||
methods.forEach((name, measurements) -> {
|
||||
|
||||
// long totalDuration = measurements.stream().mapToLong(Method::getDuration).sum();
|
||||
LongAdder totalDuration = new LongAdder();
|
||||
measurements.stream()
|
||||
.filter(Objects::nonNull)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue