Search in sources :

Example 6 with BasicThreadInfo

use of com.newrelic.agent.threads.BasicThreadInfo in project newrelic-java-agent by newrelic.

the class ProfileTest method testGetCallSiteCount.

@Test
public void testGetCallSiteCount() {
    IProfile profile = getProfile();
    StackTraceElement methodOnce = new StackTraceElement("com.acme.rocket", "launch", "rocket.java", 123);
    StackTraceElement methodTwice = new StackTraceElement("com.acme.explosive", "detonate", "explosive.java", 123);
    StackTraceElement methodCaller = new StackTraceElement("com.wileecoyote.cartoon", "show", "cartoon.java", 123);
    ThreadInfo threadInfo1 = getMockedThreadInfo(0, methodOnce);
    profile.addStackTrace(threadInfo1, true, ThreadType.BasicThreadType.OTHER);
    ThreadInfo threadInfo2 = getMockedThreadInfo(0, methodOnce, methodCaller);
    profile.addStackTrace(threadInfo2, true, ThreadType.BasicThreadType.OTHER);
    ThreadInfo threadInfo3 = getMockedThreadInfo(0, methodTwice);
    profile.addStackTrace(threadInfo3, true, ThreadType.BasicThreadType.OTHER);
    ThreadInfo threadInfo4 = getMockedThreadInfo(0, methodTwice, methodCaller);
    profile.addStackTrace(threadInfo4, true, ThreadType.BasicThreadType.OTHER);
    String normalizedThreadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo1));
    Assert.assertEquals(0, profile.getSampleCount());
    Assert.assertEquals(3, profile.getProfileTree(normalizedThreadName).getCallSiteCount());
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Test(org.junit.Test)

Example 7 with BasicThreadInfo

use of com.newrelic.agent.threads.BasicThreadInfo in project newrelic-java-agent by newrelic.

the class ProfileTest method oneFrameStackIgnored.

@Test
public void oneFrameStackIgnored() {
    IProfile profile = getProfile();
    StackTraceElement methodOnce = new StackTraceElement("com.acme.rocket", "launch", "rocket.java", 123);
    ThreadInfo threadInfo = getMockedThreadInfo(0, methodOnce);
    profile.addStackTrace(threadInfo, true, ThreadType.BasicThreadType.OTHER);
    String normalizedThreadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo));
    ProfileSegment methodOnceSegment = profile.getProfileTree(normalizedThreadName).getSegmentForMethod(methodOnce);
    Assert.assertNull(methodOnceSegment);
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Test(org.junit.Test)

Example 8 with BasicThreadInfo

use of com.newrelic.agent.threads.BasicThreadInfo in project newrelic-java-agent by newrelic.

the class ProfileTest method testAddStackTraces.

@Test
public void testAddStackTraces() {
    IProfile profile = getProfile();
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    ThreadInfo threadInfo = getMockedThreadInfo(0, stackTrace);
    profile.addStackTrace(threadInfo, true, ThreadType.BasicThreadType.OTHER);
    String normalizedThreadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo));
    Assert.assertEquals(stackTrace.length, profile.getProfileTree(normalizedThreadName).getCallSiteCount());
    profile.addStackTrace(getMockedThreadInfo(0, stackTrace), true, ThreadType.BasicThreadType.OTHER);
    Assert.assertEquals(stackTrace.length, profile.getProfileTree(normalizedThreadName).getCallSiteCount());
    stackTrace = Thread.currentThread().getStackTrace();
    profile.addStackTrace(getMockedThreadInfo(0, stackTrace), true, ThreadType.BasicThreadType.OTHER);
    Assert.assertEquals(stackTrace.length, profile.getProfileTree(normalizedThreadName).getCallSiteCount(), 2);
    Assert.assertEquals(1, profile.getProfileTree(normalizedThreadName).getRootCount());
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Test(org.junit.Test)

Example 9 with BasicThreadInfo

use of com.newrelic.agent.threads.BasicThreadInfo in project newrelic-java-agent by newrelic.

the class ProfileTest method testAddStackTrace.

@Test
public void testAddStackTrace() {
    IProfile profile = getProfile();
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    ThreadInfo threadInfo1 = getMockedThreadInfo(0, stackTrace);
    profile.addStackTrace(threadInfo1, true, ThreadType.BasicThreadType.OTHER);
    String normalizedThreadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo1));
    Assert.assertEquals(stackTrace.length, profile.getProfileTree(normalizedThreadName).getCallSiteCount());
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Test(org.junit.Test)

Example 10 with BasicThreadInfo

use of com.newrelic.agent.threads.BasicThreadInfo in project newrelic-java-agent by newrelic.

the class ProfileTest method testGetMethodCount.

@Test
public void testGetMethodCount() {
    IProfile profile = getProfile();
    StackTraceElement methodOnce = new StackTraceElement("com.acme.rocket", "launch", "rocket.java", 123);
    StackTraceElement methodTwice = new StackTraceElement("com.acme.explosive", "detonate", "explosive.java", 123);
    StackTraceElement methodCaller = new StackTraceElement("com.wileecoyote.cartoon", "show", "cartoon.java", 123);
    ThreadInfo threadInfo1 = getMockedThreadInfo(0, methodOnce, methodCaller);
    profile.addStackTrace(threadInfo1, true, ThreadType.BasicThreadType.OTHER);
    profile.addStackTrace(getMockedThreadInfo(0, methodTwice), true, ThreadType.BasicThreadType.OTHER);
    profile.addStackTrace(getMockedThreadInfo(0, methodTwice, methodCaller), true, ThreadType.BasicThreadType.OTHER);
    String normalizedThreadName = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo1));
    Assert.assertEquals(3, profile.getProfileTree(normalizedThreadName).getMethodCount());
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) Test(org.junit.Test)

Aggregations

BasicThreadInfo (com.newrelic.agent.threads.BasicThreadInfo)13 ThreadInfo (java.lang.management.ThreadInfo)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TransactionActivity (com.newrelic.agent.TransactionActivity)1 MetricName (com.newrelic.agent.metric.MetricName)1 ProfilerParameters (com.newrelic.agent.profile.ProfilerParameters)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 StatsWork (com.newrelic.agent.stats.StatsWork)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 IgnoreChildSocketCalls (com.newrelic.agent.tracers.IgnoreChildSocketCalls)1 Tracer (com.newrelic.agent.tracers.Tracer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 Collection (java.util.Collection)1