mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-27 06:32:10 +00:00
GP-1727: Cache viewport spans in DBTraceMemorySpace
This commit is contained in:
parent
7e02aa3faa
commit
70ce4ca4cf
@ -43,8 +43,7 @@ import ghidra.trace.database.thread.DBTraceThread;
|
||||
import ghidra.trace.model.*;
|
||||
import ghidra.trace.model.Trace.*;
|
||||
import ghidra.trace.model.memory.*;
|
||||
import ghidra.trace.util.TraceChangeRecord;
|
||||
import ghidra.trace.util.TraceViewportSpanIterator;
|
||||
import ghidra.trace.util.*;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.AddressIteratorAdapter;
|
||||
import ghidra.util.database.*;
|
||||
@ -92,6 +91,8 @@ public class DBTraceMemorySpace implements Unfinished, TraceMemorySpace, DBTrace
|
||||
.build()
|
||||
.asMap();
|
||||
|
||||
protected final DefaultTraceTimeViewport viewport;
|
||||
|
||||
public DBTraceMemorySpace(DBTraceMemoryManager manager, DBHandle dbh, AddressSpace space,
|
||||
DBTraceSpaceEntry ent) throws IOException, VersionException {
|
||||
this.manager = manager;
|
||||
@ -126,6 +127,8 @@ public class DBTraceMemorySpace implements Unfinished, TraceMemorySpace, DBTrace
|
||||
true);
|
||||
this.blocksByOffset =
|
||||
blockStore.getIndex(OffsetSnap.class, DBTraceMemoryBlockEntry.LOCATION_COLUMN);
|
||||
|
||||
this.viewport = new DefaultTraceTimeViewport(trace);
|
||||
}
|
||||
|
||||
private void regionCacheEntryRemoved(
|
||||
@ -387,9 +390,7 @@ public class DBTraceMemorySpace implements Unfinished, TraceMemorySpace, DBTrace
|
||||
|
||||
@Override
|
||||
public Entry<Long, TraceMemoryState> getViewState(long snap, Address address) {
|
||||
TraceViewportSpanIterator spit = new TraceViewportSpanIterator(trace, snap);
|
||||
while (spit.hasNext()) {
|
||||
Range<Long> span = spit.next();
|
||||
for (Range<Long> span : viewport.getOrderedSpans(snap)) {
|
||||
TraceMemoryState state = getState(span.upperEndpoint(), address);
|
||||
switch (state) {
|
||||
case KNOWN:
|
||||
@ -415,9 +416,7 @@ public class DBTraceMemorySpace implements Unfinished, TraceMemorySpace, DBTrace
|
||||
@Override
|
||||
public Entry<TraceAddressSnapRange, TraceMemoryState> getViewMostRecentStateEntry(long snap,
|
||||
Address address) {
|
||||
TraceViewportSpanIterator spit = new TraceViewportSpanIterator(trace, snap);
|
||||
while (spit.hasNext()) {
|
||||
Range<Long> span = spit.next();
|
||||
for (Range<Long> span: viewport.getOrderedSpans(snap)) {
|
||||
Entry<TraceAddressSnapRange, TraceMemoryState> entry =
|
||||
stateMapSpace.reduce(TraceAddressSnapRangeQuery.mostRecent(address, span))
|
||||
.firstEntry();
|
||||
@ -750,9 +749,8 @@ public class DBTraceMemorySpace implements Unfinished, TraceMemorySpace, DBTrace
|
||||
}
|
||||
Map<AddressRange, Long> sources = new TreeMap<>();
|
||||
AddressSet remains = new AddressSet(toRead);
|
||||
TraceViewportSpanIterator spit = new TraceViewportSpanIterator(trace, snap);
|
||||
spans: while (spit.hasNext()) {
|
||||
Range<Long> span = spit.next();
|
||||
|
||||
spans: for (Range<Long> span : viewport.getOrderedSpans(snap)) {
|
||||
Iterator<AddressRange> arit =
|
||||
getAddressesWithState(span, s -> s == TraceMemoryState.KNOWN).iterator(start, true);
|
||||
while (arit.hasNext()) {
|
||||
|
@ -100,22 +100,20 @@ public class DefaultTraceTimeViewport implements TraceTimeViewport {
|
||||
}
|
||||
|
||||
protected final Trace trace;
|
||||
protected final TraceTimeManager timeManager;
|
||||
/**
|
||||
* NB: This is the syncing object for the viewport. If there's even a chance an operation may
|
||||
* need the DB's lock, esp., considering user callbacks, then it must <em>first</em> acquire the
|
||||
* DB lock.
|
||||
* NB: This is also the syncing object for the viewport. If there's even a chance an operation
|
||||
* may need the DB's lock, esp., considering user callbacks, then it must <em>first</em> acquire
|
||||
* the DB lock.
|
||||
*/
|
||||
protected final List<Range<Long>> ordered = new ArrayList<>();
|
||||
protected final List<Range<Long>> ordered = new ArrayList<>(List.of(Range.singleton(0L)));
|
||||
protected final RangeSet<Long> spanSet = TreeRangeSet.create();
|
||||
protected final ForSnapshotsListener listener = new ForSnapshotsListener();
|
||||
protected final ListenerSet<Runnable> changeListeners = new ListenerSet<>(Runnable.class);
|
||||
|
||||
protected long snap;
|
||||
protected long snap = 0;
|
||||
|
||||
public DefaultTraceTimeViewport(Trace trace) {
|
||||
this.trace = trace;
|
||||
this.timeManager = trace.getTimeManager();
|
||||
trace.addCloseListener(listener);
|
||||
trace.addListener(listener);
|
||||
}
|
||||
@ -263,7 +261,7 @@ public class DefaultTraceTimeViewport implements TraceTimeViewport {
|
||||
RangeSet<Long> spanSet = TreeRangeSet.create();
|
||||
List<Range<Long>> ordered = new ArrayList<>();
|
||||
try (LockHold hold = trace.lockRead()) {
|
||||
collectForkRanges(timeManager, snap, spanSet, ordered);
|
||||
collectForkRanges(trace.getTimeManager(), snap, spanSet, ordered);
|
||||
}
|
||||
synchronized (this.ordered) {
|
||||
this.spanSet.clear();
|
||||
@ -276,6 +274,9 @@ public class DefaultTraceTimeViewport implements TraceTimeViewport {
|
||||
}
|
||||
|
||||
public void setSnap(long snap) {
|
||||
if (this.snap == snap) {
|
||||
return;
|
||||
}
|
||||
this.snap = snap;
|
||||
refreshSnapRanges();
|
||||
}
|
||||
@ -326,6 +327,19 @@ public class DefaultTraceTimeViewport implements TraceTimeViewport {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Range<Long>> getOrderedSpans() {
|
||||
synchronized (ordered) {
|
||||
return List.copyOf(ordered);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Range<Long>> getOrderedSpans(long snap) {
|
||||
synchronized (ordered) {
|
||||
setSnap(snap);
|
||||
return getOrderedSpans();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getOrderedSnaps() {
|
||||
synchronized (ordered) {
|
||||
|
Loading…
Reference in New Issue
Block a user