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());
}
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));
}
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());
}
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);
}
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);
}
Aggregations