Skip to content

Commit

Permalink
Add zooming.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://truffle/home/andrew/repo/memview@95 6d4121a9-3ab8-48c6-8db9-97dca464e206
  • Loading branch information
ajclinto committed Dec 15, 2012
1 parent 7d8ef07 commit 11ab9b4
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 62 deletions.
79 changes: 68 additions & 11 deletions DisplayLayout.C
Expand Up @@ -123,7 +123,7 @@ placeBlock(int &c, int &r, int bwidth, int bheight,
}

void
DisplayLayout::update(MemoryState &state, int width)
DisplayLayout::update(MemoryState &state)
{
//StopWatch timer;
myBlocks.clear();
Expand All @@ -145,6 +145,63 @@ DisplayLayout::update(MemoryState &state, int width)
}
}

// Initialize block sizes for non-linear display
if (myVisualization != LINEAR)
{
myHeight = 0;
myWidth = 0;
for (auto it = myBlocks.begin(); it != myBlocks.end(); ++it)
{
BlockSizer sizer;
blockTraverse(0, 0, 0, sizer, it->mySize,
15 - state.getIgnoreBits()/2,
myVisualization == HILBERT, 0, false);

int nc = sizer.myWidth;
int nr = sizer.myHeight;

it->myBox.initBounds(0, 0, nc, nr);

myWidth = SYSmax(myWidth, nc);
myHeight = SYSmax(myHeight, nc);
}
}
}

static void
adjustZoom(int &val, int zoom)
{
int a = (1 << zoom) - 1;
val = (val + a) >> zoom;
}

void
DisplayLayout::layout(int width, int zoom)
{
//StopWatch timer;

if (zoom > 0)
{
for (auto it = myBlocks.begin(); it != myBlocks.end(); ++it)
{
int zoom2 = 2*zoom;
// Update the address range
int a = (1 << zoom2) - 1;
uint64 end = it->myAddr + it->mySize;
end += a;
end >>= zoom2;
it->myAddr >>= zoom2;
it->mySize = end - it->myAddr;

// Update the block size
adjustZoom(it->myBox.h[0], zoom);
adjustZoom(it->myBox.h[1], zoom);
}

adjustZoom(myWidth, zoom);
adjustZoom(myHeight, zoom);
}

// Initialize global offsets
if (myVisualization == LINEAR)
{
Expand All @@ -167,17 +224,12 @@ DisplayLayout::update(MemoryState &state, int width)
int r = 0;
int c = 0;
int maxheight = 0;
myWidth = 0;
for (auto it = myBlocks.begin(); it != myBlocks.end(); ++it)
{
BlockSizer sizer;
blockTraverse(0, 0, 0, sizer, it->mySize, 15,
myVisualization == HILBERT, 0, false);
int nc = it->myBox.xmax();
int nr = it->myBox.ymax();

int nc = sizer.myWidth;
int nr = sizer.myHeight;

placeBlock(c, r, nc, nr, maxheight, width);
placeBlock(c, r, nc, nr, maxheight, myWidth);

it->myBox.initBounds(c, r, c+nc, r+nr);

Expand Down Expand Up @@ -364,7 +416,11 @@ public:
return false;

int size = bsize*bsize;
assert(off + size <= page.size());

// This can happen when zoomed out, since the addresses no
// longer align perfectly with the display blocks.
if (off + size > page.size())
return true;

page.resetDirty();

Expand Down Expand Up @@ -461,7 +517,8 @@ DisplayLayout::fillImage(
it->myBox.ymin()-roff,
it->myBox.xmin()-coff);

blockTraverse(0, 0, 0, plot, it->mySize, 15,
blockTraverse(0, 0, 0, plot, it->mySize,
15 - state.getIgnoreBits()/2,
myVisualization == HILBERT, 0, false);
}
}
Expand Down
4 changes: 3 additions & 1 deletion DisplayLayout.h
Expand Up @@ -24,7 +24,9 @@ class DisplayLayout {
{ myVisualization = vis; }

// Build the block display layout from state
void update(MemoryState &state, int width);
void update(MemoryState &state);
// Layout blocks after update
void layout(int width, int zoom);

// Get the resolution of the full layout
int width() const { return myWidth; }
Expand Down
126 changes: 83 additions & 43 deletions Loader.C
Expand Up @@ -9,6 +9,9 @@
Loader::Loader(MemoryState *state)
: QThread(0)
, myState(state)
, myZoomState(0)
, myPendingState(0)
, myPendingClear(false)
, myChild(-1)
, myPipeFD(0)
, myPipe(0)
Expand Down Expand Up @@ -170,6 +173,30 @@ Loader::run()
while (!myAbort)
{
bool rval = false;

if (myPendingClear)
{
delete myZoomState;
myZoomState = 0;
myPendingClear = false;
}
if (myPendingState)
{
MemoryState *zoom = myZoomState;

myZoomState = myPendingState;
myPendingState = 0;

// This could take a while
if (zoom && zoom->getIgnoreBits() <
myZoomState->getIgnoreBits())
myZoomState->downsample(*zoom);
else
myZoomState->downsample(*myState);

delete zoom;
}

switch (mySource)
{
case TEST:
Expand Down Expand Up @@ -266,27 +293,10 @@ Loader::loadFromPipe()

if (read(myPipeFD, &block, sizeof(TraceBlock)))
{
// Basic semantic checking to ensure we received valid data
if (block.myEntries)
{
int type = (block.myAddr[0] & theTypeMask) >> theTypeShift;
if (type > 7)
{
fprintf(stderr, "received invalid block (size %d)\n",
block.myEntries);
if (!loadBlock(block))
return false;
}

for (int j = 0; j < block.myEntries; j++)
{
unsigned long long addr = block.myAddr[j];
myState->updateAddress(
addr & theAddrMask,
addr >> theSizeShift,
(addr & theTypeMask) >> theTypeShift);
}

myState->incrementTime();
}

return block.myEntries == theBlockSize;
Expand All @@ -306,27 +316,10 @@ Loader::loadFromSharedMemory()
;
block.myRSem = 0;

int count = block.myEntries;
if (count)
if (block.myEntries)
{
// Basic semantic checking to ensure we received valid data
int type = (block.myAddr[0] & theTypeMask) >> theTypeShift;
if (type > 7)
{
fprintf(stderr, "received invalid block (size %d)\n", count);
if (!loadBlock(block))
return false;
}

for (int i = 0; i < count; i++)
{
unsigned long long addr = block.myAddr[i];
myState->updateAddress(
addr & theAddrMask,
addr >> theSizeShift,
(addr & theTypeMask) >> theTypeShift);
}

myState->incrementTime();
}

block.myWSem = 1;
Expand All @@ -335,7 +328,7 @@ Loader::loadFromSharedMemory()
myIdx = 0;

// If it wasn't a full block, we're at the end of the stream.
return count == theBlockSize;
return block.myEntries == theBlockSize;
}

bool
Expand All @@ -344,13 +337,60 @@ Loader::loadFromTest()
static const uint64 theSize = 16*1024;
static uint64 theCount = 0;

for (uint64 j = 0; j < 1024; j++)
//myState->updateAddress(theCount*16*1024 + j, 4, theTypeRead);
myState->updateAddress(theCount*1024 + j, 4, theTypeRead);
TraceBlock block;
block.myEntries = 1024;
for (uint64 j = 0; j < block.myEntries; j++)
{
block.myAddr[j] = 10*theCount*1024 + j;
block.myAddr[j] |= (uint64)theTypeRead << theTypeShift;
block.myAddr[j] |= (uint64)4 << theSizeShift;
}
loadBlock(block);

myState->incrementTime();
theCount++;
if (theCount >= theSize)
theCount = 0;

return true;
}

bool
Loader::loadBlock(const TraceBlock &block)
{
// Basic semantic checking to ensure we received valid data
int type = (block.myAddr[0] & theTypeMask) >> theTypeShift;
if (type > 7)
{
fprintf(stderr, "received invalid block (size %d)\n",
block.myEntries);
return false;
}

int count = block.myEntries;
for (int i = 0; i < count; i++)
{
unsigned long long addr = block.myAddr[i];
myState->updateAddress(
addr & theAddrMask,
addr >> theSizeShift,
(addr & theTypeMask) >> theTypeShift);
}

myState->incrementTime();

if (myZoomState)
{
for (int i = 0; i < count; i++)
{
unsigned long long addr = block.myAddr[i];
myZoomState->updateAddress(
addr & theAddrMask,
addr >> theSizeShift,
(addr & theTypeMask) >> theTypeShift);
}
myZoomState->incrementTime();
}

return theCount < theSize;
return true;
}

12 changes: 12 additions & 0 deletions Loader.h
Expand Up @@ -16,6 +16,13 @@ class Loader : public QThread {

bool openPipe(int argc, char *argv[]);

void setZoomState(MemoryState *state)
{ myPendingState = state; }
void clearZoomState()
{ myPendingClear = true; }

MemoryState *getBaseState() const { return myState; }

protected:
void run();

Expand All @@ -25,8 +32,13 @@ class Loader : public QThread {
bool loadFromSharedMemory();
bool loadFromTest();

bool loadBlock(const TraceBlock &block);

private:
MemoryState *myState;
MemoryState *myZoomState;
MemoryState *myPendingState;
bool myPendingClear;

// Child process
pid_t myChild;
Expand Down
33 changes: 33 additions & 0 deletions MemoryState.C
Expand Up @@ -95,3 +95,36 @@ MemoryState::printStatusInfo(QString &message, uint64 addr)
message.append(" (freed)");
}
}

void
MemoryState::downsample(const MemoryState &state)
{
int shift = myIgnoreBits - state.myIgnoreBits;

// Copy times first for the display to work correctly
myTime = state.myTime;
myHRTime = state.myHRTime;

DisplayIterator it(const_cast<MemoryState &>(state));
for (it.rewind(); !it.atEnd(); it.advance())
{
DisplayPage page(it.page());
for (uint64 i = 0; i < page.size(); i++)
{
State state = page.state(i);

uint64 myaddr = (page.addr() + i) >> shift;
uint64 tidx = topIndex(myaddr);
uint64 bidx = bottomIndex(myaddr);

if (!myTable[tidx])
myTable[tidx] = new StateArray;
if (state.time() > myTable[tidx]->myState[bidx].time())
{
myTable[tidx]->myState[bidx] = state;
myTable[tidx]->myDirty[bidx >> theDisplayBits] = true;
}
}
}
}

4 changes: 4 additions & 0 deletions MemoryState.h
Expand Up @@ -122,10 +122,14 @@ class MemoryState {
}
void incrementTime();
uint32 getTime() const { return myTime; }
int getIgnoreBits() const { return myIgnoreBits; }

// Print status information for a memory address
void printStatusInfo(QString &message, uint64 addr);

// Build a mipmap from another memory state
void downsample(const MemoryState &state);

// Abstract access to a single display page
class DisplayPage {
public:
Expand Down

0 comments on commit 11ab9b4

Please sign in to comment.