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