Skip to content

Commit

Permalink
'#1864 Implements on demmand cache creation/loading, i. e., if group was
Browse files Browse the repository at this point in the history
never selected its cache is not created/loaded.
  • Loading branch information
patrickdalla committed Feb 22, 2024
1 parent 4926400 commit 4dcadac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
15 changes: 5 additions & 10 deletions iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -311,7 +313,6 @@ public boolean test(TimeEventGroup t) {
}
});
tegCombo.setRenderer(cblcRenderer);
tegCombo.addActionListener(this);
tegCombo.setMaximumSize(new Dimension(100, 0));

legendListModel = new DefaultListModel<LegendItemBlockContainer>();
Expand Down Expand Up @@ -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();
}
}
}
};
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -70,6 +73,7 @@ public void run() {
if (periodClassesToCache.size() == 0) {
periodClassesToCache.add(ipedChartsPanel.getTimePeriodClass());
}

for (Class periodClasses : periodClassesToCache) {
CachePersistence cp = CachePersistence.getInstance();
try {
Expand Down Expand Up @@ -155,13 +159,6 @@ public void addTimePeriodClassToCache(Class<? extends TimePeriod> timePeriodClas
}

public boolean hasTimePeriodClassToCache(Class<? extends TimePeriod> timePeriodClass) {
try {
timeStampCacheSemaphore.acquire();// pause until cache is populated
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
timeStampCacheSemaphore.release();
}
return periodClassesToCache.contains(timePeriodClass);
}

Expand Down Expand Up @@ -328,4 +325,8 @@ public boolean isFromEventGroup(ArrayList<TimeEventGroup> selectedTeGroups) {
return false;
}

public boolean isLoading() {
return loading.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface TimeStampCache extends Runnable {
public TimeEventGroup getTimeEventGroup();

public boolean isFromEventGroup(ArrayList<TimeEventGroup> selectedTeGroups);

public boolean isLoading();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,12 +75,18 @@ public AbstractIntervalXYDataset getBestDataset(Class<? extends TimePeriod> 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;
Expand All @@ -91,43 +96,33 @@ public AbstractIntervalXYDataset getBestDataset(Class<? extends TimePeriod> 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<TimeStampCache> getCaches() {
Expand Down

0 comments on commit 4dcadac

Please sign in to comment.