Search in sources :

Example 1 with ProfileScope

use of org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope in project beam by apache.

the class ScopedProfilerTest method testNoProfiler.

@Test
public void testNoProfiler() throws Exception {
    MockProfiler profiler = new MockProfiler(false);
    ScopedProfiler underTest = new ScopedProfiler(profiler);
    ProfileScope original = underTest.currentScope();
    underTest.registerScope("attribute").activate();
    original.activate();
    assertThat(profiler.interactions, Matchers.equalTo(1));
}
Also used : ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) Test(org.junit.Test)

Example 2 with ProfileScope

use of org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope in project beam by apache.

the class BatchModeExecutionContextTest method extractMsecCounters.

@Test
public void extractMsecCounters() {
    BatchModeExecutionContext executionContext = BatchModeExecutionContext.forTesting(PipelineOptionsFactory.create(), "testStage");
    MetricsContainer metricsContainer = Mockito.mock(MetricsContainer.class);
    ProfileScope profileScope = Mockito.mock(ProfileScope.class);
    ExecutionState start1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
    ExecutionState process1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.PROCESS_STATE_NAME, metricsContainer, profileScope);
    ExecutionState start2 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-2", "system-2", "user-2"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
    ExecutionState other = executionContext.executionStateRegistry.getState(NameContext.forStage("stage"), "other", null, NoopProfileScope.NOOP);
    other.takeSample(120);
    start1.takeSample(100);
    process1.takeSample(500);
    assertThat(executionContext.extractMsecCounters(false), containsInAnyOrder(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500)));
    process1.takeSample(200);
    start2.takeSample(200);
    assertThat(executionContext.extractMsecCounters(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 500 + 200), msec("start-msecs", "stage", "original-2", 200)));
    process1.takeSample(300);
    assertThat(executionContext.extractMsecCounters(true), hasItems(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500 + 200 + 300), msec("start-msecs", "stage", "original-2", 200)));
}
Also used : ExecutionState(org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState) BatchModeExecutionState(org.apache.beam.runners.dataflow.worker.BatchModeExecutionContext.BatchModeExecutionState) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) NoopProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope) Test(org.junit.Test)

Example 3 with ProfileScope

use of org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope in project beam by apache.

the class StreamingModeExecutionContextTest method extractMsecCounters.

@Test
public void extractMsecCounters() {
    MetricsContainer metricsContainer = Mockito.mock(MetricsContainer.class);
    ProfileScope profileScope = Mockito.mock(ProfileScope.class);
    ExecutionState start1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
    ExecutionState process1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.PROCESS_STATE_NAME, metricsContainer, profileScope);
    ExecutionState start2 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-2", "system-2", "user-2"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
    ExecutionState other = executionContext.executionStateRegistry.getState(NameContext.forStage("stage"), "other", null, NoopProfileScope.NOOP);
    other.takeSample(120);
    start1.takeSample(100);
    process1.takeSample(500);
    assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500)));
    process1.takeSample(200);
    start2.takeSample(200);
    assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 200), msec("start-msecs", "stage", "original-2", 200)));
    process1.takeSample(300);
    assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 300)));
}
Also used : ExecutionState(org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState) StreamingModeExecutionState(org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.StreamingModeExecutionState) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) NoopProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 4 with ProfileScope

use of org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope in project beam by apache.

the class ScopedProfilerTest method testProfilerNestedBlocks.

@Test
public void testProfilerNestedBlocks() throws Exception {
    MockProfiler profiler = new MockProfiler(true);
    ScopedProfiler underTest = new ScopedProfiler(profiler);
    assertThat(profiler.interactions, Matchers.equalTo(1));
    ProfileScope original = underTest.currentScope();
    ProfileScope block1 = underTest.registerScope("attribute1");
    ProfileScope block2 = underTest.registerScope("attribute2");
    block1.activate();
    assertThat(profiler.currentState, Matchers.equalTo(profiler.registeredAttributes.get("attribute1")));
    block2.activate();
    assertThat(profiler.currentState, Matchers.equalTo(profiler.registeredAttributes.get("attribute2")));
    block1.activate();
    assertThat(profiler.currentState, Matchers.equalTo(profiler.registeredAttributes.get("attribute1")));
    original.activate();
    assertThat(profiler.currentState, Matchers.equalTo(0));
}
Also used : ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) Test(org.junit.Test)

Example 5 with ProfileScope

use of org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope in project beam by apache.

the class ScopedProfilerTest method testProfilerOneBlock.

@Test
public void testProfilerOneBlock() throws Exception {
    MockProfiler profiler = new MockProfiler(true);
    ScopedProfiler underTest = new ScopedProfiler(profiler);
    ProfileScope original = underTest.currentScope();
    underTest.registerScope("attribute").activate();
    assertThat(profiler.currentState, Matchers.equalTo(profiler.registeredAttributes.get("attribute")));
    original.activate();
    assertThat(profiler.currentState, Matchers.equalTo(0));
}
Also used : ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) Test(org.junit.Test)

Aggregations

ProfileScope (org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope)5 Test (org.junit.Test)5 ExecutionState (org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState)2 NoopProfileScope (org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope)2 MetricsContainer (org.apache.beam.sdk.metrics.MetricsContainer)2 StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)1 BatchModeExecutionState (org.apache.beam.runners.dataflow.worker.BatchModeExecutionContext.BatchModeExecutionState)1 StreamingModeExecutionState (org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.StreamingModeExecutionState)1