collect decompilation performance statistic data

This commit is contained in:
honfika@gmail.com
2015-10-04 18:48:19 +02:00
parent 63f87da9c1
commit bfe3a7bb60
6 changed files with 193 additions and 27 deletions

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.helpers.stat;
import com.jpexs.helpers.Stopwatch;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class Statistics implements AutoCloseable {
private static final Map<String, StatisticData> map = new HashMap<>();
private final String name;
private final Stopwatch sw;
public static synchronized void addTime(String name, long duration) {
StatisticData s = map.get(name);
if (s == null) {
s = new StatisticData();
map.put(name, s);
}
s.value += duration;
if (duration > s.max) {
s.max = duration;
}
if (duration < s.min) {
s.min = duration;
}
s.count++;
}
public static synchronized void addToMap(Map<String, StatisticData> targetMap) {
for (Map.Entry<String, StatisticData> e : map.entrySet()) {
String name = e.getKey();
StatisticData d = e.getValue();
StatisticData d2 = targetMap.get(name);
if (d2 == null) {
d2 = new StatisticData();
targetMap.put(name, d2);
}
d2.value += d.value;
d2.count += d.count;
if (d.max > d2.max) {
d2.max = d.max;
}
if (d.min < d2.min) {
d2.min = d.min;
}
}
}
public static synchronized void print() {
print(map);
}
public static synchronized void print(Map<String, StatisticData> map) {
for (Map.Entry<String, StatisticData> e : map.entrySet()) {
String name = e.getKey();
StatisticData d = e.getValue();
System.out.println(name + ": count: " + d.count + " / total: " + (d.value / 1000000)
+ "ms / min: " + (d.min / 1000)
+ "us / max: " + (d.max / 1000)
+ "us / avg: " + (d.value / d.count / 1000) + "us");
}
}
public static synchronized void clear() {
map.clear();
}
public Statistics(String name) {
this.name = name;
sw = Stopwatch.startNew();
}
@Override
public void close() {
sw.stop();
addTime(name, sw.getElapsedNanoseconds());
}
}