Java Code Examples for io.perfmark.PerfMark#createTag()
The following examples show how to use
io.perfmark.PerfMark#createTag() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerCallImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
private void serverSendsOne_okFailsOnMissingResponse( MethodDescriptor<Long, Long> method) { ServerCallImpl<Long, Long> serverCall = new ServerCallImpl<>( stream, method, requestHeaders, context, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), serverCallTracer, PerfMark.createTag()); serverCall.close(Status.OK, new Metadata()); ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class); verify(stream, times(1)).cancel(statusCaptor.capture()); assertEquals(Status.Code.INTERNAL, statusCaptor.getValue().getCode()); assertEquals(ServerCallImpl.MISSING_RESPONSE, statusCaptor.getValue().getDescription()); }
Example 2
Source File: ServerCallImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
private void sendMessage_serverSendsOne_closeOnSecondCall( MethodDescriptor<Long, Long> method) { ServerCallImpl<Long, Long> serverCall = new ServerCallImpl<>( stream, method, requestHeaders, context, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), serverCallTracer, PerfMark.createTag()); serverCall.sendHeaders(new Metadata()); serverCall.sendMessage(1L); verify(stream, times(1)).writeMessage(any(InputStream.class)); verify(stream, never()).close(any(Status.class), any(Metadata.class)); // trying to send a second message causes gRPC to close the underlying stream serverCall.sendMessage(1L); verify(stream, times(1)).writeMessage(any(InputStream.class)); ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class); verify(stream, times(1)).cancel(statusCaptor.capture()); assertEquals(Status.Code.INTERNAL, statusCaptor.getValue().getCode()); assertEquals(ServerCallImpl.TOO_MANY_RESPONSES, statusCaptor.getValue().getDescription()); }
Example 3
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void onReady_runtimeExceptionCancelsCall() { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); RuntimeException expectedT = new RuntimeException(); doThrow(expectedT).when(mockListener).onReady(); listener.onReady(); try { executor.runDueTasks(); fail("Expected exception"); } catch (RuntimeException t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 4
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void onReady_errorCancelsCall() { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); TestError expectedT = new TestError(); doThrow(expectedT).when(mockListener).onReady(); listener.onReady(); try { executor.runDueTasks(); fail("Expected exception"); } catch (TestError t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 5
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void halfClosed_runtimeExceptionCancelsCall() { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); RuntimeException expectedT = new RuntimeException(); doThrow(expectedT).when(mockListener).halfClosed(); listener.halfClosed(); try { executor.runDueTasks(); fail("Expected exception"); } catch (RuntimeException t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 6
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void halfClosed_errorCancelsCall() { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); TestError expectedT = new TestError(); doThrow(expectedT).when(mockListener).halfClosed(); listener.halfClosed(); try { executor.runDueTasks(); fail("Expected exception"); } catch (TestError t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 7
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void messageRead_runtimeExceptionCancelsCall() throws Exception { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); RuntimeException expectedT = new RuntimeException(); doThrow(expectedT).when(mockListener) .messagesAvailable(any(StreamListener.MessageProducer.class)); // Closing the InputStream is done by the delegated listener (generally ServerCallImpl) listener.messagesAvailable(mock(StreamListener.MessageProducer.class)); try { executor.runDueTasks(); fail("Expected exception"); } catch (RuntimeException t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 8
Source File: ServerImplTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void messageRead_errorCancelsCall() throws Exception { JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener( executor.getScheduledExecutorService(), executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation(), PerfMark.createTag()); ServerStreamListener mockListener = mock(ServerStreamListener.class); listener.setListener(mockListener); TestError expectedT = new TestError(); doThrow(expectedT).when(mockListener) .messagesAvailable(any(StreamListener.MessageProducer.class)); // Closing the InputStream is done by the delegated listener (generally ServerCallImpl) listener.messagesAvailable(mock(StreamListener.MessageProducer.class)); try { executor.runDueTasks(); fail("Expected exception"); } catch (TestError t) { assertSame(expectedT, t); ensureServerStateNotLeaked(); } }
Example 9
Source File: NettyServerHandler.java From grpc-java with Apache License 2.0 | 6 votes |
@Override protected void onStreamError(ChannelHandlerContext ctx, boolean outbound, Throwable cause, StreamException http2Ex) { logger.log(Level.WARNING, "Stream Error", cause); NettyServerStream.TransportState serverStream = serverStream( connection().stream(Http2Exception.streamId(http2Ex))); Tag tag = serverStream != null ? serverStream.tag() : PerfMark.createTag(); PerfMark.startTask("NettyServerHandler.onStreamError", tag); try { if (serverStream != null) { serverStream.transportReportStatus(Utils.statusFromThrowable(cause)); } // TODO(ejona): Abort the stream by sending headers to help the client with debugging. // Delegate to the base class to send a RST_STREAM. super.onStreamError(ctx, outbound, cause, http2Ex); } finally { PerfMark.stopTask("NettyServerHandler.onStreamError", tag); } }
Example 10
Source File: OkHttpClientStream.java From grpc-java with Apache License 2.0 | 6 votes |
public TransportState( int maxMessageSize, StatsTraceContext statsTraceCtx, Object lock, ExceptionHandlingFrameWriter frameWriter, OutboundFlowController outboundFlow, OkHttpClientTransport transport, int initialWindowSize, String methodName) { super(maxMessageSize, statsTraceCtx, OkHttpClientStream.this.getTransportTracer()); this.lock = checkNotNull(lock, "lock"); this.frameWriter = frameWriter; this.outboundFlow = outboundFlow; this.transport = transport; this.window = initialWindowSize; this.processedWindow = initialWindowSize; this.initialWindowSize = initialWindowSize; tag = PerfMark.createTag(methodName); }
Example 11
Source File: ServerImpl.java From grpc-java with Apache License 2.0 | 5 votes |
@Override public void streamCreated(ServerStream stream, String methodName, Metadata headers) { Tag tag = PerfMark.createTag(methodName, stream.streamId()); PerfMark.startTask("ServerTransportListener.streamCreated", tag); try { streamCreatedInternal(stream, methodName, headers, tag); } finally { PerfMark.stopTask("ServerTransportListener.streamCreated", tag); } }
Example 12
Source File: ClientCallImpl.java From grpc-java with Apache License 2.0 | 5 votes |
ClientCallImpl( MethodDescriptor<ReqT, RespT> method, Executor executor, CallOptions callOptions, ClientTransportProvider clientTransportProvider, ScheduledExecutorService deadlineCancellationExecutor, CallTracer channelCallsTracer, boolean retryEnabled) { this.method = method; // TODO(carl-mastrangelo): consider moving this construction to ManagedChannelImpl. this.tag = PerfMark.createTag(method.getFullMethodName(), System.identityHashCode(this)); // If we know that the executor is a direct executor, we don't need to wrap it with a // SerializingExecutor. This is purely for performance reasons. // See https://github.com/grpc/grpc-java/issues/368 if (executor == directExecutor()) { this.callExecutor = new SerializeReentrantCallsDirectExecutor(); callExecutorIsDirect = true; } else { this.callExecutor = new SerializingExecutor(executor); callExecutorIsDirect = false; } this.channelCallsTracer = channelCallsTracer; // Propagate the context from the thread which initiated the call to all callbacks. this.context = Context.current(); this.unaryRequest = method.getType() == MethodType.UNARY || method.getType() == MethodType.SERVER_STREAMING; this.callOptions = callOptions; this.clientTransportProvider = clientTransportProvider; this.deadlineCancellationExecutor = deadlineCancellationExecutor; this.retryEnabled = retryEnabled; PerfMark.event("ClientCall.<init>", tag); }
Example 13
Source File: NettyServerStream.java From grpc-java with Apache License 2.0 | 5 votes |
public TransportState( NettyServerHandler handler, EventLoop eventLoop, Http2Stream http2Stream, int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer, String methodName) { super(maxMessageSize, statsTraceCtx, transportTracer); this.http2Stream = checkNotNull(http2Stream, "http2Stream"); this.handler = checkNotNull(handler, "handler"); this.eventLoop = eventLoop; this.tag = PerfMark.createTag(methodName, http2Stream.id()); }
Example 14
Source File: NettyClientStream.java From grpc-java with Apache License 2.0 | 5 votes |
public TransportState( NettyClientHandler handler, EventLoop eventLoop, int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer, String methodName) { super(maxMessageSize, statsTraceCtx, transportTracer); this.methodName = checkNotNull(methodName, "methodName"); this.handler = checkNotNull(handler, "handler"); this.eventLoop = checkNotNull(eventLoop, "eventLoop"); tag = PerfMark.createTag(methodName); }
Example 15
Source File: ServerCallImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); context = Context.ROOT.withCancellation(); call = new ServerCallImpl<>(stream, UNARY_METHOD, requestHeaders, context, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), serverCallTracer, PerfMark.createTag()); }
Example 16
Source File: ServerCallImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
private void callTracer0(Status status) { CallTracer tracer = CallTracer.getDefaultFactory().create(); ServerStats.Builder beforeBuilder = new ServerStats.Builder(); tracer.updateBuilder(beforeBuilder); ServerStats before = beforeBuilder.build(); assertEquals(0, before.callsStarted); assertEquals(0, before.lastCallStartedNanos); call = new ServerCallImpl<>(stream, UNARY_METHOD, requestHeaders, context, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), tracer, PerfMark.createTag()); // required boilerplate call.sendHeaders(new Metadata()); call.sendMessage(123L); // end: required boilerplate call.close(status, new Metadata()); ServerStats.Builder afterBuilder = new ServerStats.Builder(); tracer.updateBuilder(afterBuilder); ServerStats after = afterBuilder.build(); assertEquals(1, after.callsStarted); if (status.isOk()) { assertEquals(1, after.callsSucceeded); } else { assertEquals(1, after.callsFailed); } }
Example 17
Source File: PerfMarkTransformerTest.java From perfmark with Apache License 2.0 | 5 votes |
@Test public void transform_ctor() throws Exception { PerfMark.setEnabled(true); Storage.resetForTest(); final class ClzLocal { public ClzLocal() { Tag tag = PerfMark.createTag("tag", 1); PerfMark.startTask("task"); PerfMark.stopTask("task"); PerfMark.startTask("task", tag); PerfMark.stopTask("task", tag); } } Class<?> clz = transformAndLoad(ClzLocal.class); Constructor<?> ctor = clz.getConstructor(PerfMarkTransformerTest.class); ctor.setAccessible(true); ctor.newInstance(this); List<Mark> marks = Storage.readForTest(); assertThat(marks).hasSize(4); for (Mark mark : marks) { assertNotNull(mark.getMarker()); StackTraceElement element = Internal.getElement(mark.getMarker()); assertThat(element.getClassName()).isEqualTo(ClzLocal.class.getName()); assertThat(element.getMethodName()).isEqualTo("<init>"); assertThat(element.getFileName()).isEqualTo("PerfMarkTransformerTest.java"); assertThat(element.getLineNumber()).isGreaterThan(0); } }
Example 18
Source File: ServerCallImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
private void sendMessage_serverSendsOne_closeOnSecondCall_appRunToCompletion( MethodDescriptor<Long, Long> method) { ServerCallImpl<Long, Long> serverCall = new ServerCallImpl<>( stream, method, requestHeaders, context, DecompressorRegistry.getDefaultInstance(), CompressorRegistry.getDefaultInstance(), serverCallTracer, PerfMark.createTag()); serverCall.sendHeaders(new Metadata()); serverCall.sendMessage(1L); serverCall.sendMessage(1L); verify(stream, times(1)).writeMessage(any(InputStream.class)); verify(stream, times(1)).cancel(any(Status.class)); // App runs to completion but everything is ignored serverCall.sendMessage(1L); serverCall.close(Status.OK, new Metadata()); try { serverCall.close(Status.OK, new Metadata()); fail("calling a second time should still cause an error"); } catch (IllegalStateException expected) { // noop } }
Example 19
Source File: NettyClientStream.java From grpc-java with Apache License 2.0 | 4 votes |
public void setId(int id) { checkArgument(id > 0, "id must be positive %s", id); checkState(this.id == 0, "id has been previously set: %s", this.id); this.id = id; this.tag = PerfMark.createTag(methodName, id); }
Example 20
Source File: EnabledUtilBenchmark.java From perfmark with Apache License 2.0 | 4 votes |
@Setup public void setup() { PerfMark.setEnabled(enabled); tag = PerfMark.createTag("tag", 2); }