|
|
@ -26,19 +26,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
package net.yacy.kelondro.util;
|
|
|
|
package net.yacy.kelondro.util;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import de.anomic.yacy.graphics.ProfilingGraph;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.yacy.kelondro.logging.Log;
|
|
|
|
import net.yacy.kelondro.logging.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MemoryTracker extends Thread {
|
|
|
|
public class MemoryTracker extends Thread {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<String, ArrayList<Event>> historyMaps = new ConcurrentHashMap<String, ArrayList<Event>>();
|
|
|
|
|
|
|
|
private static final Map<String, Long> eventAccess = new ConcurrentHashMap<String, Long>(); // value: last time when this was accessed
|
|
|
|
|
|
|
|
private static MemoryTracker systemProfiler = null;
|
|
|
|
private static MemoryTracker systemProfiler = null;
|
|
|
|
|
|
|
|
|
|
|
|
public static void startSystemProfiling() {
|
|
|
|
public static void startSystemProfiling() {
|
|
|
@ -61,7 +54,7 @@ public class MemoryTracker extends Thread {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
while (running) {
|
|
|
|
while (running) {
|
|
|
|
update("memory", Long.valueOf(MemoryControl.used()), true);
|
|
|
|
EventTracker.update("memory", Long.valueOf(MemoryControl.used()), true, 30000, ProfilingGraph.maxTime);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Thread.sleep(this.delaytime);
|
|
|
|
Thread.sleep(this.delaytime);
|
|
|
|
} catch (final InterruptedException e) {
|
|
|
|
} catch (final InterruptedException e) {
|
|
|
@ -72,75 +65,5 @@ public class MemoryTracker extends Thread {
|
|
|
|
Log.logException(e);
|
|
|
|
Log.logException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void update(final String eventName, final Object eventPayload, boolean useProtection) {
|
|
|
|
|
|
|
|
// get event history container
|
|
|
|
|
|
|
|
Long lastAcc = eventAccess.get(eventName);
|
|
|
|
|
|
|
|
if (lastAcc == null) {
|
|
|
|
|
|
|
|
eventAccess.put(eventName, Long.valueOf(System.currentTimeMillis()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if (!useProtection || time - lastAcc.longValue() > 1000) {
|
|
|
|
|
|
|
|
eventAccess.put(eventName, Long.valueOf(time));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return; // protect against too heavy load
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<Event> history = historyMaps.get(eventName);
|
|
|
|
|
|
|
|
if (history != null) synchronized (history) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update entry
|
|
|
|
|
|
|
|
history.add(new Event(eventPayload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clean up too old entries
|
|
|
|
|
|
|
|
int tp = history.size() - 30000;
|
|
|
|
|
|
|
|
while (tp-- > 0) history.remove(0);
|
|
|
|
|
|
|
|
if (history.size() % 10 == 0) { // reduce number of System.currentTimeMillis() calls
|
|
|
|
|
|
|
|
Event e;
|
|
|
|
|
|
|
|
final long now = System.currentTimeMillis();
|
|
|
|
|
|
|
|
while (!history.isEmpty()) {
|
|
|
|
|
|
|
|
e = history.get(0);
|
|
|
|
|
|
|
|
if (now - e.time < 600000) break;
|
|
|
|
|
|
|
|
history.remove(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
history = new ArrayList<Event>(100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update entry
|
|
|
|
|
|
|
|
history.add(new Event(eventPayload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// store map
|
|
|
|
|
|
|
|
historyMaps.put(eventName, history);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ArrayList<Event> history(final String eventName) {
|
|
|
|
|
|
|
|
return historyMaps.get(eventName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int countEvents(final String eventName, long time) {
|
|
|
|
|
|
|
|
ArrayList<Event> event = history(eventName);
|
|
|
|
|
|
|
|
if (event == null) return 0;
|
|
|
|
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
synchronized (event) {
|
|
|
|
|
|
|
|
Iterator<Event> i = event.iterator();
|
|
|
|
|
|
|
|
while (i.hasNext()) {
|
|
|
|
|
|
|
|
if (now - i.next().time < time) count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class Event {
|
|
|
|
|
|
|
|
public Object payload;
|
|
|
|
|
|
|
|
public long time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Event(final Object payload) {
|
|
|
|
|
|
|
|
this.payload = payload;
|
|
|
|
|
|
|
|
this.time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|