Skip to content

Commit

Permalink
LeanProfile basic aggregation test added
Browse files Browse the repository at this point in the history
Also trying to keep the tests as compact and readable as possible.
  • Loading branch information
PhRX committed Apr 13, 2017
1 parent 910c8dd commit 1b2b66a
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 155 deletions.
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.math.BigInteger;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;


Expand All @@ -20,6 +21,7 @@
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener; import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener;
import com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo; import com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo;
import com.insightfullogic.honest_profiler.core.profiles.lean.info.MethodInfo; import com.insightfullogic.honest_profiler.core.profiles.lean.info.MethodInfo;
import com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo;
import com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo; import com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo;


public class LeanProfileGenerator implements LeanProfileListener public class LeanProfileGenerator implements LeanProfileListener
Expand Down Expand Up @@ -58,6 +60,20 @@ public LeanProfile getProfile()
return currentProfile; return currentProfile;
} }


public LeanNode getNode(long threadId, StackFrame... stack)
{
LeanNode current = currentProfile.getThreads().get(threadId);
List<StackFrame> frames = asList(stack);
reverse(frames);
for (StackFrame frame : frames)
{
Optional<LeanNode> child = current.getChildren().stream()
.filter(node -> node.getFrame().getMethodId() == frame.getMethodId()).findFirst();
current = child.get();
}
return current;
}

// LeanProfileListener Implementation // LeanProfileListener Implementation


@Override @Override
Expand Down Expand Up @@ -140,7 +156,11 @@ public void assertProfileContainsStack(long threadId, StackFrame... stack)
{ {
level++; level++;
Optional<LeanNode> child = current.getChildren().stream() Optional<LeanNode> child = current.getChildren().stream()
.filter(node -> node.getFrame().getMethodId() == frame.getMethodId()).findFirst(); .filter(
node -> node.getFrame().getMethodId() == frame.getMethodId()
&& node.getFrame().getLineNr() == frame.getLineNumber()
&& node.getFrame().getBci() == frame.getBci())
.findFirst();
assertTrue("Descendant at level " + level + " not found", child.isPresent()); assertTrue("Descendant at level " + level + " not found", child.isPresent());
current = child.get(); current = child.get();
assertNodeRepresentsFrame(current, frame); assertNodeRepresentsFrame(current, frame);
Expand All @@ -155,6 +175,44 @@ public void assertNodeRepresentsFrame(LeanNode node, StackFrame stackFrame)
assertEquals(stackFrame.getBci(), info.getBci()); assertEquals(stackFrame.getBci(), info.getBci());
} }


public void assertSelfCountEquals(int selfCount, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Self Count", selfCount, info.getSelfCnt());
}

public void assertTotalCountEquals(int totalCount, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Total Count", totalCount, info.getTotalCnt());
}

public void assertCountsEqual(int selfCount, int totalCount, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Self Count", selfCount, info.getSelfCnt());
assertEquals("Wrong Total Count", totalCount, info.getTotalCnt());
}

public void assertSelfTimeEquals(long selfTime, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Self Time", BigInteger.valueOf(selfTime), info.getSelfTime());
}

public void assertTotalTimeEquals(long totalTime, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Total Time", BigInteger.valueOf(totalTime), info.getTotalTime());
}

public void assertTimesEqual(long selfTime, long totalTime, long threadId, StackFrame... stack)
{
NumericInfo info = getNode(threadId, stack).getData();
assertEquals("Wrong Self Time", BigInteger.valueOf(selfTime), info.getSelfTime());
assertEquals("Wrong Total Time", BigInteger.valueOf(totalTime), info.getTotalTime());
}

// Initialization // Initialization


public void resetAndRequest() public void resetAndRequest()
Expand Down

0 comments on commit 1b2b66a

Please sign in to comment.