From 4dcadac24cd748ae3fdcb768b9575d595866079f Mon Sep 17 00:00:00 2001 From: "patrick.pdb" Date: Thu, 22 Feb 2024 14:40:52 -0400 Subject: [PATCH] '#1864 Implements on demmand cache creation/loading, i. e., if group was never selected its cache is not created/loaded. --- .../app/timelinegraph/IpedChartsPanel.java | 15 ++---- .../cache/IndexTimeStampCache.java | 15 +++--- .../timelinegraph/cache/TimeStampCache.java | 2 + .../datasets/IpedTimelineDatasetManager.java | 53 +++++++++---------- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java b/iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java index 0122d839b1..e7230e69f3 100644 --- a/iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java +++ b/iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java @@ -193,6 +193,8 @@ public IpedChartsPanel() { } combinedPlot.setDomainPannable(true); + selectedTeGroups.add(TimeEventGroup.BASIC_EVENTS); + toolTipGenerator = new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { @@ -311,7 +313,6 @@ public boolean test(TimeEventGroup t) { } }); tegCombo.setRenderer(cblcRenderer); - tegCombo.addActionListener(this); tegCombo.setMaximumSize(new Dimension(100, 0)); legendListModel = new DefaultListModel(); @@ -618,15 +619,6 @@ public void setDockableContainer(DefaultSingleCDockable dockable) { public void changed(CDockableLocationEvent dockableEvent) { if (!isUpdated && dockableEvent.isShowingChanged()) { refreshChart(); - if (!loadingCacheStarted.getAndSet(true)) { - Runnable r = new Runnable() { - @Override - public void run() { - ipedTimelineDatasetManager.startCacheCreation(); - } - }; - new Thread(r).start(); - } } } }; @@ -1102,11 +1094,14 @@ public void notifyCaseDataChanged() { populateEventNames.run(); this.ipedTimelineDatasetManager = new IpedTimelineDatasetManager(this); + // updates tegCombo with updated time event groups of the case + tegCombo.removeActionListener(this); tegCombo.removeAllItems(); tegCombo.addItem(TimeEventGroup.BASIC_EVENTS); for (TimeEventGroup teGroup : ipedTimelineDatasetManager.getTimeEventGroupsFromMetadataPrefix()) { tegCombo.addItem(teGroup); } + tegCombo.addActionListener(this); this.dataSetUpdated.set(false); } diff --git a/iped-app/src/main/java/iped/app/timelinegraph/cache/IndexTimeStampCache.java b/iped-app/src/main/java/iped/app/timelinegraph/cache/IndexTimeStampCache.java index 1a21a76da5..5257e46756 100644 --- a/iped-app/src/main/java/iped/app/timelinegraph/cache/IndexTimeStampCache.java +++ b/iped-app/src/main/java/iped/app/timelinegraph/cache/IndexTimeStampCache.java @@ -13,6 +13,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.LogManager; @@ -40,6 +41,7 @@ public class IndexTimeStampCache implements TimeStampCache { TimeEventGroup teGroup;// default TimeEventGroup TimeIndexedMap newCache = new TimeIndexedMap(); + AtomicBoolean loading = new AtomicBoolean(false); public IndexTimeStampCache(IpedChartsPanel ipedChartsPanel, IMultiSearchResultProvider resultsProvider) { this.resultsProvider = resultsProvider; @@ -57,6 +59,7 @@ public IndexTimeStampCache(IpedChartsPanel ipedChartsPanel, IMultiSearchResultPr @Override public void run() { + loading.set(true); int oldPriority = Thread.currentThread().getPriority(); Thread.currentThread().setPriority(Thread.MIN_PRIORITY); try { @@ -70,6 +73,7 @@ public void run() { if (periodClassesToCache.size() == 0) { periodClassesToCache.add(ipedChartsPanel.getTimePeriodClass()); } + for (Class periodClasses : periodClassesToCache) { CachePersistence cp = CachePersistence.getInstance(); try { @@ -155,13 +159,6 @@ public void addTimePeriodClassToCache(Class timePeriodClas } public boolean hasTimePeriodClassToCache(Class timePeriodClass) { - try { - timeStampCacheSemaphore.acquire();// pause until cache is populated - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - timeStampCacheSemaphore.release(); - } return periodClassesToCache.contains(timePeriodClass); } @@ -328,4 +325,8 @@ public boolean isFromEventGroup(ArrayList selectedTeGroups) { return false; } + public boolean isLoading() { + return loading.get(); + } + } \ No newline at end of file diff --git a/iped-app/src/main/java/iped/app/timelinegraph/cache/TimeStampCache.java b/iped-app/src/main/java/iped/app/timelinegraph/cache/TimeStampCache.java index fc2bd42c8f..a3cb18f16c 100644 --- a/iped-app/src/main/java/iped/app/timelinegraph/cache/TimeStampCache.java +++ b/iped-app/src/main/java/iped/app/timelinegraph/cache/TimeStampCache.java @@ -31,4 +31,6 @@ public interface TimeStampCache extends Runnable { public TimeEventGroup getTimeEventGroup(); public boolean isFromEventGroup(ArrayList selectedTeGroups); + + public boolean isLoading(); } diff --git a/iped-app/src/main/java/iped/app/timelinegraph/datasets/IpedTimelineDatasetManager.java b/iped-app/src/main/java/iped/app/timelinegraph/datasets/IpedTimelineDatasetManager.java index c208976381..1824ff4ca1 100644 --- a/iped-app/src/main/java/iped/app/timelinegraph/datasets/IpedTimelineDatasetManager.java +++ b/iped-app/src/main/java/iped/app/timelinegraph/datasets/IpedTimelineDatasetManager.java @@ -9,7 +9,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -76,12 +75,18 @@ public AbstractIntervalXYDataset getBestDataset(Class time String splitValue) { selectedTimeStampCaches.clear(); try { + for (TimeEventGroup tGroup : selectedTeGroups) { + createCaches(tGroup);// assures caches of the group are created/loaded + } + for (TimeStampCache timeStampCache : timeStampCaches) { - if (timeStampCache.hasTimePeriodClassToCache(timePeriodClass) - && timeStampCache.isFromEventGroup(selectedTeGroups)) { - selectedTimeStampCaches.add(timeStampCache); + if (timeStampCache.isFromEventGroup(selectedTeGroups)) { + if (timeStampCache.hasTimePeriodClassToCache(timePeriodClass)) { + selectedTimeStampCaches.add(timeStampCache); + } } } + IpedTimelineDataset result = new IpedTimelineDataset(this, ipedChartsPanel.getResultsProvider(), splitValue); return result; @@ -91,43 +96,33 @@ public AbstractIntervalXYDataset getBestDataset(Class time return null; } - /* - * Start the creation of cache for timeline chart - */ - public void startCacheCreation() { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - + public void createCaches(TimeEventGroup teGroup) { int poolSize = 1; + int totalItems = ipedChartsPanel.getResultsProvider().getIPEDSource().getTotalItems(); if (getAvailableMemory() > totalItems * 100) { poolSize = (int) Math.ceil((float) Runtime.getRuntime().availableProcessors() / 2f); - } else { - logger.info("Only {}MB of free memory for {} total items. Timeline index creation will occur sequentially. ", Runtime.getRuntime().freeMemory(), totalItems); } + ExecutorService threadPool = Executors.newFixedThreadPool(poolSize); boolean first = true; for (TimeStampCache timeStampCache : timeStampCaches) { - Future future = threadPool.submit(timeStampCache); - // first loads the Day cache alone to speed up it, then run others in parallel - if (first) { - first = false; - try { - future.get(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + if (!timeStampCache.isLoading()) { + if (timeStampCache.isFromEventGroup(teGroup)) { + Future future = threadPool.submit(timeStampCache); + // first loads the Day cache alone to speed up it, then run others in parallel + if (first) { + first = false; + try { + future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } } } } threadPool.shutdown(); - try { - threadPool.awaitTermination(12, TimeUnit.HOURS); - } catch (InterruptedException e) { - e.printStackTrace(); - } } public Collection getCaches() {