use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.
the class ThreadInfoRequestCoordinatorTest method createMockTaskManagerGateway.
private static CompletableFuture<TaskExecutorThreadInfoGateway> createMockTaskManagerGateway(CompletionType completionType) {
final CompletableFuture<TaskThreadInfoResponse> responseFuture = new CompletableFuture<>();
switch(completionType) {
case SUCCESSFULLY:
ThreadInfoSample sample = JvmUtils.createThreadInfoSample(Thread.currentThread().getId(), 100).get();
responseFuture.complete(new TaskThreadInfoResponse(Collections.singletonList(sample)));
break;
case EXCEPTIONALLY:
responseFuture.completeExceptionally(new RuntimeException("Request failed."));
break;
case TIMEOUT:
executorService.schedule(() -> responseFuture.completeExceptionally(new TimeoutException(REQUEST_TIMEOUT_MESSAGE)), REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
break;
case NEVER_COMPLETE:
// do nothing
break;
default:
throw new RuntimeException("Unknown completion type.");
}
final TaskExecutorThreadInfoGateway executorGateway = (taskExecutionAttemptId, requestParams, timeout) -> responseFuture;
return CompletableFuture.completedFuture(executorGateway);
}
use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.
the class ThreadInfoSampleServiceTest method testSampleTaskThreadInfo.
/**
* Tests successful thread info samples request.
*/
@Test(timeout = 10000L)
public void testSampleTaskThreadInfo() throws Exception {
final List<ThreadInfoSample> threadInfoSamples = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), requestParams).get();
assertThat(threadInfoSamples, hasSize(NUMBER_OF_SAMPLES));
for (ThreadInfoSample sample : threadInfoSamples) {
StackTraceElement[] traces = sample.getStackTrace();
assertTrue(sample.getStackTrace().length <= MAX_STACK_TRACK_DEPTH);
assertThat(traces, is(arrayWithSize(lessThanOrEqualTo(MAX_STACK_TRACK_DEPTH))));
}
}
use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.
the class ThreadInfoSampleServiceTest method testTruncateStackTraceIfLimitIsSpecified.
/**
* Tests that stack traces are truncated when exceeding the configured depth.
*/
@Test(timeout = 10000L)
public void testTruncateStackTraceIfLimitIsSpecified() throws Exception {
final List<ThreadInfoSample> threadInfoSamples1 = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), requestParams).get();
final List<ThreadInfoSample> threadInfoSamples2 = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), new ThreadInfoSamplesRequest(1, NUMBER_OF_SAMPLES, DELAY_BETWEEN_SAMPLES, MAX_STACK_TRACK_DEPTH - 5)).get();
for (ThreadInfoSample sample : threadInfoSamples1) {
assertThat(sample.getStackTrace(), is(arrayWithSize(lessThanOrEqualTo(MAX_STACK_TRACK_DEPTH))));
assertTrue(sample.getStackTrace().length <= MAX_STACK_TRACK_DEPTH);
}
for (ThreadInfoSample sample : threadInfoSamples2) {
assertThat(sample.getStackTrace(), is(arrayWithSize(MAX_STACK_TRACK_DEPTH - 5)));
}
}
use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.
the class JobVertexFlameGraphFactory method createFlameGraphFromSample.
private static JobVertexFlameGraph createFlameGraphFromSample(JobVertexThreadInfoStats sample, Set<Thread.State> threadStates) {
final NodeBuilder root = new NodeBuilder("root");
for (List<ThreadInfoSample> threadInfoSubSamples : sample.getSamplesBySubtask().values()) {
for (ThreadInfoSample threadInfo : threadInfoSubSamples) {
if (threadStates.contains(threadInfo.getThreadState())) {
StackTraceElement[] traces = threadInfo.getStackTrace();
root.incrementHitCount();
NodeBuilder parent = root;
for (int i = traces.length - 1; i >= 0; i--) {
final String name = traces[i].getClassName() + "." + traces[i].getMethodName() + ":" + traces[i].getLineNumber();
parent = parent.addChild(name);
}
}
}
}
return new JobVertexFlameGraph(sample.getEndTime(), root.toNode());
}
Aggregations