From 959b38b61bf40d35c47c489ae36c61c330bc027d Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 14 Dec 2009 20:23:11 +0000 Subject: [PATCH] fix for memory tracker git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6526 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../net/yacy/kelondro/util/MemoryTracker.java | 81 +------------------ 1 file changed, 2 insertions(+), 79 deletions(-) diff --git a/source/net/yacy/kelondro/util/MemoryTracker.java b/source/net/yacy/kelondro/util/MemoryTracker.java index 8a0808eab..0dc95e250 100644 --- a/source/net/yacy/kelondro/util/MemoryTracker.java +++ b/source/net/yacy/kelondro/util/MemoryTracker.java @@ -26,19 +26,12 @@ package net.yacy.kelondro.util; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import de.anomic.yacy.graphics.ProfilingGraph; import net.yacy.kelondro.logging.Log; - - public class MemoryTracker extends Thread { - private static final Map> historyMaps = new ConcurrentHashMap>(); - private static final Map eventAccess = new ConcurrentHashMap(); // value: last time when this was accessed private static MemoryTracker systemProfiler = null; public static void startSystemProfiling() { @@ -61,7 +54,7 @@ public class MemoryTracker extends Thread { public void run() { try { while (running) { - update("memory", Long.valueOf(MemoryControl.used()), true); + EventTracker.update("memory", Long.valueOf(MemoryControl.used()), true, 30000, ProfilingGraph.maxTime); try { Thread.sleep(this.delaytime); } catch (final InterruptedException e) { @@ -72,75 +65,5 @@ public class MemoryTracker extends Thread { 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 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(100); - - // update entry - history.add(new Event(eventPayload)); - - // store map - historyMaps.put(eventName, history); - } - } - - public static ArrayList history(final String eventName) { - return historyMaps.get(eventName); - } - - public static int countEvents(final String eventName, long time) { - ArrayList event = history(eventName); - if (event == null) return 0; - long now = System.currentTimeMillis(); - int count = 0; - synchronized (event) { - Iterator 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(); - } - } }