From 4b2e60a06b3f4bd8edf63d3e30f56c3eb1ed73f7 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Wed, 24 Apr 2019 15:07:43 -0700 Subject: [PATCH] core: remove scopeid overloads of perfmark --- .../java/io/grpc/internal/ClientCallImpl.java | 44 ++-- .../java/io/grpc/internal/ServerCallImpl.java | 48 ++-- .../main/java/io/grpc/perfmark/PerfMark.java | 231 ------------------ 3 files changed, 30 insertions(+), 293 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/ClientCallImpl.java b/core/src/main/java/io/grpc/internal/ClientCallImpl.java index 1cab55ad30..6f4ec16be5 100644 --- a/core/src/main/java/io/grpc/internal/ClientCallImpl.java +++ b/core/src/main/java/io/grpc/internal/ClientCallImpl.java @@ -183,12 +183,11 @@ final class ClientCallImpl extends ClientCall { @Override public void start(Listener observer, Metadata headers) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ClientCall.start"); + PerfMark.taskStart(tag, "ClientCall.start"); try { startInternal(observer, headers); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -386,12 +385,11 @@ final class ClientCallImpl extends ClientCall { @Override public void cancel(@Nullable String message, @Nullable Throwable cause) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ClientCall.cancel"); + PerfMark.taskStart(tag, "ClientCall.cancel"); try { cancelInternal(message, cause); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -426,12 +424,11 @@ final class ClientCallImpl extends ClientCall { @Override public void halfClose() { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ClientCall.halfClose"); + PerfMark.taskStart(tag, "ClientCall.halfClose"); try { halfCloseInternal(); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -445,12 +442,11 @@ final class ClientCallImpl extends ClientCall { @Override public void sendMessage(ReqT message) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ClientCall.sendMessage"); + PerfMark.taskStart(tag, "ClientCall.sendMessage"); try { sendMessageInternal(message); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -512,7 +508,6 @@ final class ClientCallImpl extends ClientCall { private class ClientStreamListenerImpl implements ClientStreamListener { private final Listener observer; private boolean closed; - private final long listenerScopeId = PerfTag.allocateNumericId(); public ClientStreamListenerImpl(Listener observer) { this.observer = checkNotNull(observer, "observer"); @@ -530,8 +525,7 @@ final class ClientCallImpl extends ClientCall { if (closed) { return; } - PerfMark.taskStart( - listenerScopeId, Thread.currentThread().getName(), tag, "ClientCall.headersRead"); + PerfMark.taskStart(tag, "ClientCall.headersRead"); try { observer.onHeaders(headers); } catch (Throwable t) { @@ -540,7 +534,7 @@ final class ClientCallImpl extends ClientCall { stream.cancel(status); close(status, new Metadata()); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } } @@ -561,11 +555,7 @@ final class ClientCallImpl extends ClientCall { GrpcUtil.closeQuietly(producer); return; } - PerfMark.taskStart( - listenerScopeId, - Thread.currentThread().getName(), - tag, - "ClientCall.messagesAvailable"); + PerfMark.taskStart(tag, "ClientCall.messagesAvailable"); try { InputStream message; while ((message = producer.next()) != null) { @@ -584,7 +574,7 @@ final class ClientCallImpl extends ClientCall { stream.cancel(status); close(status, new Metadata()); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } } @@ -637,12 +627,11 @@ final class ClientCallImpl extends ClientCall { // We intentionally don't keep the status or metadata from the server. return; } - PerfMark.taskStart( - listenerScopeId, Thread.currentThread().getName(), tag, "ClientCall.closed"); + PerfMark.taskStart(tag, "ClientCall.closed"); try { close(savedStatus, savedTrailers); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } } @@ -659,8 +648,7 @@ final class ClientCallImpl extends ClientCall { @Override public final void runInContext() { - PerfMark.taskStart( - listenerScopeId, Thread.currentThread().getName(), tag, "ClientCall.onReady"); + PerfMark.taskStart(tag, "ClientCall.onReady"); try { observer.onReady(); } catch (Throwable t) { @@ -669,7 +657,7 @@ final class ClientCallImpl extends ClientCall { stream.cancel(status); close(status, new Metadata()); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } } diff --git a/core/src/main/java/io/grpc/internal/ServerCallImpl.java b/core/src/main/java/io/grpc/internal/ServerCallImpl.java index 4f418ec7c7..2713ea4d17 100644 --- a/core/src/main/java/io/grpc/internal/ServerCallImpl.java +++ b/core/src/main/java/io/grpc/internal/ServerCallImpl.java @@ -90,12 +90,11 @@ final class ServerCallImpl extends ServerCall { @Override public void sendHeaders(Metadata headers) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ServerCall.sendHeaders"); + PerfMark.taskStart(tag, "ServerCall.sendHeaders"); try { sendHeadersInternal(headers); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -140,12 +139,11 @@ final class ServerCallImpl extends ServerCall { @Override public void sendMessage(RespT message) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ServerCall.sendMessage"); + PerfMark.taskStart(tag, "ServerCall.sendMessage"); try { sendMessageInternal(message); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -194,12 +192,11 @@ final class ServerCallImpl extends ServerCall { @Override public void close(Status status, Metadata trailers) { - PerfMark.taskStart( - tag.getNumericTag(), Thread.currentThread().getName(), tag, "ServerCall.close"); + PerfMark.taskStart(tag, "ServerCall.close"); try { closeInternal(status, trailers); } finally { - PerfMark.taskEnd(tag.getNumericTag(), Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -263,7 +260,6 @@ final class ServerCallImpl extends ServerCall { private final ServerCallImpl call; private final ServerCall.Listener listener; private final Context.CancellableContext context; - private final long listenerScopeId = PerfTag.allocateNumericId(); public ServerStreamListenerImpl( ServerCallImpl call, ServerCall.Listener listener, @@ -292,11 +288,7 @@ final class ServerCallImpl extends ServerCall { return; } - PerfMark.taskStart( - listenerScopeId, - Thread.currentThread().getName(), - call.tag, - "ServerCall.messagesAvailable"); + PerfMark.taskStart(call.tag, "ServerCall.messagesAvailable"); InputStream message; try { while ((message = producer.next()) != null) { @@ -313,7 +305,7 @@ final class ServerCallImpl extends ServerCall { MoreThrowables.throwIfUnchecked(t); throw new RuntimeException(t); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -323,26 +315,18 @@ final class ServerCallImpl extends ServerCall { return; } - PerfMark.taskStart( - listenerScopeId, - Thread.currentThread().getName(), - call.tag, - "ServerCall.halfClosed"); + PerfMark.taskStart(call.tag, "ServerCall.halfClosed"); try { listener.onHalfClose(); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @Override public void closed(Status status) { - PerfMark.taskStart( - listenerScopeId, - Thread.currentThread().getName(), - call.tag, - "ServerCall.closed"); + PerfMark.taskStart(call.tag, "ServerCall.closed"); try { try { if (status.isOk()) { @@ -358,7 +342,7 @@ final class ServerCallImpl extends ServerCall { } } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } @@ -367,15 +351,11 @@ final class ServerCallImpl extends ServerCall { if (call.cancelled) { return; } - PerfMark.taskStart( - listenerScopeId, - Thread.currentThread().getName(), - call.tag, - "ServerCall.closed"); + PerfMark.taskStart(call.tag, "ServerCall.closed"); try { listener.onReady(); } finally { - PerfMark.taskEnd(listenerScopeId, Thread.currentThread().getName()); + PerfMark.taskEnd(); } } } diff --git a/core/src/main/java/io/grpc/perfmark/PerfMark.java b/core/src/main/java/io/grpc/perfmark/PerfMark.java index 66936e0feb..feeeac0ee2 100644 --- a/core/src/main/java/io/grpc/perfmark/PerfMark.java +++ b/core/src/main/java/io/grpc/perfmark/PerfMark.java @@ -42,23 +42,6 @@ public final class PerfMark { */ public static void taskStart(PerfTag tag, @CompileTimeConstant String taskName) {} - /** - * Start a Task with a Tag to identify it; a task represents some work that spans some time, and - * you are interested in both its start time and end time. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * #taskStart(String)} or {@link PerfTag#create(String)}. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static void taskStart( - long scopeId, String scopeName, PerfTag tag, @CompileTimeConstant String taskName) {} - /** * Start a Task; a task represents some work that spans some time, and you are interested in both * its start time and end time. @@ -68,19 +51,6 @@ public final class PerfMark { */ public static void taskStart(@CompileTimeConstant String taskName) {} - /** - * Start a Task; a task represents some work that spans some time, and you are interested in both - * its start time and end time. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static void taskStart( - long scopeId, String scopeName, @CompileTimeConstant String taskName) {} - /** * Start a Task with a Tag to identify it and with a time threshold; a task represents some work * that spans some time, and you are interested in both its start time and end time. @@ -101,33 +71,6 @@ public final class PerfMark { public static void taskStartWithMinPeriod( PerfTag tag, long minPeriodNanos, @CompileTimeConstant String taskName) {} - /** - * Start a Task with a Tag to identify it and with a time threshold; a task represents some work - * that spans some time, and you are interested in both its start time and end time. - * - *

Sometimes, you may be interested in only events that take more than a certain time - * threshold. In such cases, you can use this method. A Task that takes less than the specified - * threshold, along with all its sub-tasks, events, and additional tags will be discarded. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * #taskStartWithMinPeriod(long, String)} or {@link PerfTag#create(String)}. - * @param minPeriodNanos Tasks that takes less than the specified time period, in nanosecond, will - * be discarded, along with its sub-tasks, events, and additional tags. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static void taskStartWithMinPeriod( - long scopeId, - String scopeName, - PerfTag tag, - long minPeriodNanos, - @CompileTimeConstant String taskName) {} - /** * Start a Task with time threshold. A task represents some work that spans some time, and you are * interested in both its start time and end time. @@ -144,37 +87,9 @@ public final class PerfMark { public static void taskStartWithMinPeriod( long minPeriodNanos, @CompileTimeConstant String taskName) {} - /** - * Start a Task with time threshold. A task represents some work that spans some time, and you are - * interested in both its start time and end time. - * - *

Sometimes, you may be interested in only events that take more than a certain time - * threshold. In such cases, you can use this method. A task that takes less than the specified - * threshold, along with all its sub-tasks, events, and additional tags will be discarded. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param minPeriodNanos Tasks that takes less than the specified time period, in nanosecond, will - * be discarded, along with its sub-tasks, events, and additional tags. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static void taskStartWithMinPeriod( - long scopeId, String scopeName, long minPeriodNanos, @CompileTimeConstant String taskName) {} - /** End a Task. See {@link #taskStart(PerfTag, String)}. */ public static void taskEnd() {} - /** - * End a Task. See {@link #taskStart(PerfTag, String)}. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - */ - public static void taskEnd(long scopeId, String scopeName) {} - /** * Start a Task with a Tag to identify it in a try-with-resource statement; a task represents some * work that spans some time, and you are interested in both its start time and end time. @@ -192,27 +107,6 @@ public final class PerfMark { return AUTO_DO_NOTHING; } - /** - * Start a Task with a Tag to identify it in a try-with-resource statement; a task represents some - * work that spans some time, and you are interested in both its start time and end time. - * - *

Use this in a try-with-resource statement so that task will end automatically. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * #task(String)} or {@link PerfTag#create(String)}. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static PerfMarkTask task( - long scopeId, String scopeName, PerfTag tag, @CompileTimeConstant String taskName) { - return AUTO_DO_NOTHING; - } - /** * Start a Task it in a try-with-resource statement; a task represents some work that spans some * time, and you are interested in both its start time and end time. @@ -226,23 +120,6 @@ public final class PerfMark { return AUTO_DO_NOTHING; } - /** - * Start a Task it in a try-with-resource statement; a task represents some work that spans some - * time, and you are interested in both its start time and end time. - * - *

Use this in a try-with-resource statement so that task will end automatically. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static PerfMarkTask task( - long scopeId, String scopeName, @CompileTimeConstant String taskName) { - return AUTO_DO_NOTHING; - } - /** * Start a Task with a Tag to identify it, and with time threshold, in a try-with-resource * statement; a task represents some work that spans some time, and you are interested in both its @@ -268,38 +145,6 @@ public final class PerfMark { return AUTO_DO_NOTHING; } - /** - * Start a Task with a Tag to identify it, and with time threshold, in a try-with-resource - * statement; a task represents some work that spans some time, and you are interested in both its - * start time and end time. - * - *

Use this in a try-with-resource statement so that task will end automatically. - * - *

Sometimes, you may be interested in only events that take more than a certain time - * threshold. In such cases, you can use this method. A task that takes less than the specified - * threshold, along with all its sub-tasks, events, and additional tags will be discarded. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * #taskWithMinPeriod(long, String)} or {@link PerfTag#create(String)}. - * @param minPeriodNanos Tasks that takes less than the specified time period, in nanosecond, will - * be discarded, along with its sub-tasks, events, and additional tags. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static PerfMarkTask taskWithMinPeriod( - long scopeId, - String scopeName, - PerfTag tag, - long minPeriodNanos, - @CompileTimeConstant String taskName) { - return AUTO_DO_NOTHING; - } - /** * Start a Task with time threshold in a try-with-resource statement; a task represents some work * that spans some time, and you are interested in both its start time and end time. @@ -320,29 +165,6 @@ public final class PerfMark { return AUTO_DO_NOTHING; } - /** - * Start a Task with time threshold in a try-with-resource statement; a task represents some work - * that spans some time, and you are interested in both its start time and end time. - * - *

Use this in a try-with-resource statement so that task will end automatically. - * - *

Sometimes, you may be interested in only events that take more than a certain time - * threshold. In such cases, you can use this method. A task that takes less than the specified - * threshold, along with all its sub-tasks, events, and additional tags will be discarded. - * - * @param scopeId The scope of the task. The scope id is used to join task starting and ending - * across threads. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param minPeriodNanos Tasks that takes less than the specified time period, in nanosecond, will - * be discarded, along with its sub-tasks, events, and additional tags. - * @param taskName The name of the task. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this task. - */ - public static PerfMarkTask taskWithMinPeriod( - long scopeId, String scopeName, long minPeriodNanos, @CompileTimeConstant String taskName) { - return AUTO_DO_NOTHING; - } - static final PerfMarkTask AUTO_DO_NOTHING = new PerfMarkTask() { @Override public void close() {} @@ -363,25 +185,6 @@ public final class PerfMark { */ public static void event(PerfTag tag, @CompileTimeConstant String eventName) {} - /** - * Records an Event with a Tag to identify it. - * - *

An Event is different from a Task in that you don't care how much time it spanned. You are - * interested in only the time it happened. - * - * @param scopeId The scope of the event. The scope id is used to associated the event with a - * particular scope. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * #event(String)} or {@link PerfTag#create(String)}. - * @param eventName The name of the event. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this event. - */ - public static void event( - long scopeId, String scopeName, PerfTag tag, @CompileTimeConstant String eventName) {} - /** * Records an Event. * @@ -393,20 +196,6 @@ public final class PerfMark { */ public static void event(@CompileTimeConstant String eventName) {} - /** - * Records an Event. - * - *

An Event is different from a Task in that you don't care how much time it spanned. You are - * interested in only the time it happened. - * - * @param scopeId The scope of the event. The scope id is used to associate the event with a - * particular scope. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param eventName The name of the event. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this event. - */ - public static void event(long scopeId, String scopeName, @CompileTimeConstant String eventName) {} - /** * Add an additional tag to the last task that was started. * @@ -422,24 +211,4 @@ public final class PerfMark { * Otherwise, instrumentation result will show "(invalid name)" for this tag. */ public static void tag(PerfTag tag, @CompileTimeConstant String tagName) {} - - /** - * Add an additional tag to the last task that was started. - * - *

A tag is different from an Event or a task in that clients don't care about the time at - * which this tag is added. Instead, it allows clients to associate an additional tag to the - * current Task. - * - * @param scopeId The scope of the tag. The scope id is used to associate a tag with a particular - * scope. The scope id must be a positive number. - * @param scopeName The name of the scope. - * @param tag a Tag object associated with the task. See {@link PerfTag} for description. Don't - * use 0 for the {@code numericTag} of the Tag object. 0 is reserved to represent that a task - * does not have a numeric tag associated. In this case, you are encouraged to use {@link - * PerfTag#create(String)}. - * @param tagName The name of the tag. This parameter must be a compile-time constant! - * Otherwise, instrumentation result will show "(invalid name)" for this tag. - */ - public static void tag( - long scopeId, String scopeName, PerfTag tag, @CompileTimeConstant String tagName) {} }