Search in sources :

Example 1 with ProfilerParameters

use of com.newrelic.agent.profile.ProfilerParameters in project newrelic-java-agent by newrelic.

the class RPMServiceTest method doSendProfileData.

private void doSendProfileData() throws Exception {
    List<String> appNames = singletonList("MyApplication");
    RPMService svc = new RPMService(appNames, null, null, Collections.<AgentConnectionEstablishedListener>emptyList());
    ProfilerParameters parameters = new ProfilerParameters(0L, 0L, 0L, false, false, Agent.isDebugEnabled(), null, null);
    Profile profile = new Profile(parameters);
    List<IProfile> profiles = new ArrayList<>();
    profiles.add(profile);
    ProfileSampler sampler = new ProfileSampler();
    sampler.sampleStackTraces(profiles);
    profile.start();
    profile.end();
    svc.launch();
    IProfile profile2 = new Profile(parameters);
    List<Long> ids = svc.sendProfileData(Arrays.<ProfileData>asList(profile, profile2));
    assertEquals(2, ids.size());
}
Also used : ArrayList(java.util.ArrayList) IProfile(com.newrelic.agent.profile.IProfile) ProfileSampler(com.newrelic.agent.profile.ProfileSampler) Profile(com.newrelic.agent.profile.Profile) IProfile(com.newrelic.agent.profile.IProfile) ProfilerParameters(com.newrelic.agent.profile.ProfilerParameters)

Example 2 with ProfilerParameters

use of com.newrelic.agent.profile.ProfilerParameters in project newrelic-java-agent by newrelic.

the class ProfileTest method testGetCallCount.

/*
     * @Test public void testGetCallCounts() { Profile profile = new Profile(50);
     * 
     * Assert.assertEquals(0, profile.getProfileTree(ThreadType.BasicThreadType.OTHER).getCallCounts().size());
     * 
     * StackTraceElement stackElement = new StackTraceElement("com.acme.rocket", "launch", "rocket.java", 123);
     * profile.add(new ProfileSegment(stackElement, (ProfileSegment)null), null);
     * 
     * Map<ProfiledMethod,Integer> callCounts =
     * profile.getProfileTree(ThreadType.BasicThreadType.OTHER).getCallCounts(); Integer count =
     * (Integer)callCounts.get(new ProfiledMethod(stackElement)); Assert.assertEquals(1, count.longValue()); }
     */
@Test
public void testGetCallCount() {
    ProfilerParameters parameters = new ProfilerParameters(0L, 0L, 0L, false, false, false, null, null).setProfilerFormat("v2");
    ThreadMXBean threadMXBean = mock(ThreadMXBean.class);
    when(threadMXBean.getThreadCpuTime(0)).thenReturn(10L);
    IProfile profile = new Profile(parameters, TransactionGuidFactory.generate16CharGuid(), threadNameNormalizer, threadMXBean);
    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);
    StackTraceElement methodCallerToo = new StackTraceElement("com.wileecoyote.cartoon", "show", "cartoon.java", 321);
    // profile.addStackTrace(0, false,methodCaller);
    ThreadInfo threadInfo1 = getMockedThreadInfo(0, methodOnce, methodCaller);
    profile.addStackTrace(threadInfo1, true, ThreadType.BasicThreadType.OTHER);
    ThreadInfo threadInfo2 = getMockedThreadInfo(0, methodTwice);
    profile.addStackTrace(threadInfo2, true, ThreadType.BasicThreadType.OTHER);
    ThreadInfo threadInfo3 = getMockedThreadInfo(0, methodTwice, methodCaller);
    profile.addStackTrace(threadInfo3, true, ThreadType.BasicThreadType.OTHER);
    String normalizedThread1Name = threadNameNormalizer.getNormalizedThreadName(new BasicThreadInfo(threadInfo1));
    ProfileSegment methodCallerSegment = profile.getProfileTree(normalizedThread1Name).getSegmentForMethod(methodCaller);
    Assert.assertEquals(2, methodCallerSegment.getCallCount(methodCallerSegment.getMethod()));
    ProfileSegment methodCallerTooSegment = profile.getProfileTree(normalizedThread1Name).getSegmentForMethod(methodCallerToo);
    Assert.assertNull(methodCallerTooSegment);
    Map<ProfiledMethod, ProfileSegment> methodCallerChilden = methodCallerSegment.getChildMap();
    Assert.assertEquals(2, methodCallerChilden.size());
    ProfiledMethod methodOnceProfiledMethod = profile.getProfiledMethodFactory().getProfiledMethod(methodOnce);
    Assert.assertEquals(1, methodCallerChilden.get(methodOnceProfiledMethod).getCallCount(methodOnceProfiledMethod));
    ProfiledMethod methodTwiceProfiledMethod = profile.getProfiledMethodFactory().getProfiledMethod(methodTwice);
    Assert.assertEquals(1, methodCallerChilden.get(methodTwiceProfiledMethod).getCallCount(methodTwiceProfiledMethod));
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) ProfilerParameters(com.newrelic.agent.profile.ProfilerParameters) Test(org.junit.Test)

Example 3 with ProfilerParameters

use of com.newrelic.agent.profile.ProfilerParameters in project newrelic-java-agent by newrelic.

the class CommandParserThreadProfilerTest method setup.

@Before
public void setup() throws Exception {
    agentControl = new MockCoreService();
    createServiceManager(new HashMap<String, Object>());
    profilerService = new ProfilerService() {

        @Override
        public void startProfiler(ProfilerParameters parameters) {
            profilerParameters = parameters;
        }

        @Override
        public int stopProfiler(Long profileId, boolean report) {
            return 0;
        }

        @Override
        public boolean isEnabled() {
            return true;
        }
    };
    commandParser = new CommandParser();
    commandParser.doStart();
    commandParser.addCommands(new ShutdownCommand(agentControl), new RestartCommand());
}
Also used : MockCoreService(com.newrelic.agent.MockCoreService) ProfilerService(com.newrelic.agent.profile.ProfilerService) ProfilerParameters(com.newrelic.agent.profile.ProfilerParameters) Before(org.junit.Before)

Example 4 with ProfilerParameters

use of com.newrelic.agent.profile.ProfilerParameters in project newrelic-java-agent by newrelic.

the class ProfileTest method getProfile.

private IProfile getProfile() {
    ThreadInfo threadInfo = mock(ThreadInfo.class);
    when(threadInfo.getThreadId()).thenReturn(12L);
    when(threadInfo.getThreadName()).thenReturn("name");
    ThreadMXBean threadMXBean = mock(ThreadMXBean.class);
    when(threadMXBean.getThreadCpuTime(0)).thenReturn(10L);
    when(threadMXBean.getThreadInfo(anyLong(), eq(0))).thenReturn(threadInfo);
    ProfilerParameters parameters = new ProfilerParameters(0L, 0L, 0L, false, false, true, null, null).setProfilerFormat("v2");
    return new Profile(parameters, TransactionGuidFactory.generate16CharGuid(), threadNameNormalizer, threadMXBean);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) BasicThreadInfo(com.newrelic.agent.threads.BasicThreadInfo) ProfilerParameters(com.newrelic.agent.profile.ProfilerParameters)

Example 5 with ProfilerParameters

use of com.newrelic.agent.profile.ProfilerParameters in project newrelic-java-agent by newrelic.

the class JSONSerializerTest method serializeLargeProfileData.

@Test
public void serializeLargeProfileData() throws Exception {
    ServiceFactory.setServiceManager(new MockServiceManager());
    List<ProfileData> profileData = new ArrayList<>();
    ProfilerParameters parameters = new ProfilerParameters(0L, 0L, 0L, false, false, true, null, null);
    IProfile profile = new com.newrelic.agent.profile.Profile(parameters);
    StackTraceElement[] stackTraceElements = new StackTraceElement[2048];
    for (int i = 0; i < 2048; i++) {
        stackTraceElements[i] = new StackTraceElement("declaringClass", "methodName", "fileName", i);
    }
    profile.addStackTrace(1, true, ThreadType.BasicThreadType.OTHER, stackTraceElements);
    profileData.add(profile);
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(oStream);
    JSONValue.writeJSONString(profileData, writer);
    writer.close();
    String profileDataJson = oStream.toString();
    Assert.assertNotNull(profileDataJson);
    // Check to make sure the profile data has a reasonable size
    Assert.assertTrue(profileDataJson.getBytes(Charsets.UTF_8).length > 1024);
}
Also used : ArrayList(java.util.ArrayList) ProfileData(com.newrelic.agent.profile.ProfileData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IProfile(com.newrelic.agent.profile.IProfile) ProfilerParameters(com.newrelic.agent.profile.ProfilerParameters) OutputStreamWriter(java.io.OutputStreamWriter) IProfile(com.newrelic.agent.profile.IProfile) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test) StatsTest(com.newrelic.agent.stats.StatsTest)

Aggregations

ProfilerParameters (com.newrelic.agent.profile.ProfilerParameters)5 IProfile (com.newrelic.agent.profile.IProfile)2 BasicThreadInfo (com.newrelic.agent.threads.BasicThreadInfo)2 ThreadInfo (java.lang.management.ThreadInfo)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MockCoreService (com.newrelic.agent.MockCoreService)1 Profile (com.newrelic.agent.profile.Profile)1 ProfileData (com.newrelic.agent.profile.ProfileData)1 ProfileSampler (com.newrelic.agent.profile.ProfileSampler)1 ProfilerService (com.newrelic.agent.profile.ProfilerService)1 StatsTest (com.newrelic.agent.stats.StatsTest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Before (org.junit.Before)1