Search in sources :

Example 1 with Profile

use of com.insightfullogic.honest_profiler.core.profiles.Profile in project honest-profiler by jvm-profiling-tools.

the class LogCollectorTest method logCollectorShouldCopeWithUnexpectedFrames.

@Test
public void logCollectorShouldCopeWithUnexpectedFrames() {
    final Deque<Profile> found = new ArrayDeque<>();
    final LogCollector collector = new LogCollector(found::add, true);
    for (int i = 0; i < 10; i++) {
        collector.handle(new Method(i, "a", "Bass", "c" + i));
    }
    assertTrue("methods don't cause profiles", found.isEmpty());
    int threadId = 0;
    collector.handle(new TraceStart(2, ++threadId, 1, 1));
    assertTrue("nothing to profile still", found.isEmpty());
    collector.handle(new StackFrame(LINE, 0));
    collector.handle(new StackFrame(LINE, 1));
    // ..and one unexpected frame
    collector.handle(new StackFrame(LINE, 2));
    // normal method afterwards
    collector.handle(new TraceStart(2, ++threadId, 1, 1));
    collector.handle(new StackFrame(LINE, 6));
    collector.handle(new StackFrame(LINE, 7));
    // and continuation
    collector.handle(new TraceStart(20, ++threadId, 1, 1));
    assertArrayEquals(new long[] { 2, 7 }, idOfLastMethodInEachThread(found.getLast()));
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Method(com.insightfullogic.honest_profiler.core.parser.Method) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 2 with Profile

use of com.insightfullogic.honest_profiler.core.profiles.Profile in project honest-profiler by jvm-profiling-tools.

the class AgentIntegrationTest method discoverVirtualMachines.

private AtomicReference<Profile> discoverVirtualMachines() {
    AtomicReference<Profile> lastProfile = new AtomicReference<>();
    parkNanos(SECONDS.toNanos(1));
    new LocalMachineSource(logger, new MachineListener() {

        @Override
        public void onNewMachine(final VirtualMachine machine) {
            if (machine.isAgentLoaded()) {
                final FileLogSource logSource = (FileLogSource) machine.getLogSource();
                file.set(logSource);
                Monitor.pipeFile(logSource, lastProfile::set);
            }
        }

        @Override
        public void onClosedMachine(final VirtualMachine machine) {
        }
    }).discoverVirtualMachines();
    return lastProfile;
}
Also used : FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) LocalMachineSource(com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) MachineListener(com.insightfullogic.honest_profiler.core.MachineListener) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) VirtualMachine(com.insightfullogic.honest_profiler.core.sources.VirtualMachine)

Example 3 with Profile

use of com.insightfullogic.honest_profiler.core.profiles.Profile in project honest-profiler by jvm-profiling-tools.

the class FlatProfileTest method calculateMajorityFlatProfiles.

@Test
public void calculateMajorityFlatProfiles() {
    TraceStart startTrace = new TraceStart(1, 1, 1, 1);
    collector.handle(startTrace);
    collector.handle(new StackFrame(20, 5));
    collector.handle(ProfileFixtures.println);
    collector.handle(startTrace);
    collector.handle(new StackFrame(20, 5));
    collector.handle(startTrace);
    collector.handle(new StackFrame(25, 6));
    collector.handle(ProfileFixtures.append);
    collector.endOfLog();
    Profile profile = listener.getProfile();
    assertEquals(3, profile.getTraceCount());
    assertEquals(2L, profile.flatByMethodProfile().count());
    assertEntry(ProfileFixtures.println, 2.0 / 3, profile.flatByMethodProfile().findFirst());
    assertEntry(ProfileFixtures.append, 1.0 / 3, profile.flatByMethodProfile().filter(e -> e.getTotalTimeShare() < 0.5).findFirst());
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) Test(org.junit.Test)

Example 4 with Profile

use of com.insightfullogic.honest_profiler.core.profiles.Profile in project honest-profiler by jvm-profiling-tools.

the class FlatProfileTest method looksUpMethodNames.

@Test
public void looksUpMethodNames() {
    collector.handle(new TraceStart(1, 1, 1, 1));
    collector.handle(new StackFrame(20, 5));
    collector.handle(ProfileFixtures.println);
    collector.endOfLog();
    Profile profile = listener.getProfile();
    assertEquals(1, profile.getTraceCount());
    assertEquals(1L, profile.flatByMethodProfile().count());
    assertEntry(ProfileFixtures.println, 1.0, profile.flatByMethodProfile().findFirst());
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) Test(org.junit.Test)

Example 5 with Profile

use of com.insightfullogic.honest_profiler.core.profiles.Profile in project honest-profiler by jvm-profiling-tools.

the class AgentIntegrationTest method expectTraceCount.

private int expectTraceCount(final Expect expect, final int seenTraceCount, final Matcher<Integer> matcher, final AtomicReference<Profile> lastProfile) {
    logger.debug("Last seen trace count is {}", seenTraceCount);
    parkNanos(SECONDS.toNanos(1));
    Profile profile = lastProfile.get();
    int currentTraceCount = profile == null ? 0 : profile.getTraceCount();
    expect.that(currentTraceCount).is(matcher);
    return currentTraceCount;
}
Also used : Profile(com.insightfullogic.honest_profiler.core.profiles.Profile)

Aggregations

Profile (com.insightfullogic.honest_profiler.core.profiles.Profile)9 Test (org.junit.Test)5 StackFrame (com.insightfullogic.honest_profiler.core.parser.StackFrame)3 TraceStart (com.insightfullogic.honest_profiler.core.parser.TraceStart)3 FlatProfileEntry (com.insightfullogic.honest_profiler.core.collector.FlatProfileEntry)2 ProfileNode (com.insightfullogic.honest_profiler.core.profiles.ProfileNode)2 MachineListener (com.insightfullogic.honest_profiler.core.MachineListener)1 Method (com.insightfullogic.honest_profiler.core.parser.Method)1 ProfileTree (com.insightfullogic.honest_profiler.core.profiles.ProfileTree)1 VirtualMachine (com.insightfullogic.honest_profiler.core.sources.VirtualMachine)1 FileLogSource (com.insightfullogic.honest_profiler.ports.sources.FileLogSource)1 LocalMachineSource (com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource)1 ArrayDeque (java.util.ArrayDeque)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1