BewareMyPower commented on code in PR #26163: URL: https://github.com/apache/pulsar/pull/26163#discussion_r3575804423
########## pulsar-common/src/main/java/org/apache/pulsar/common/util/LatencyTracer.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar.common.util; + +import java.util.ArrayList; +import java.util.Queue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + +public class LatencyTracer { + + private final Queue<Timepoint> timepoints; + private final NanoTimeSupplier nanoTimeSupplier; + private final long startNs; + + public LatencyTracer(Queue<Timepoint> timepoints, NanoTimeSupplier nanoTimeSupplier) { + this.timepoints = timepoints; + this.nanoTimeSupplier = nanoTimeSupplier; + this.startNs = nanoTimeSupplier.getNanos(); + } + + public <T> CompletableFuture<T> trace(String message, CompletableFuture<T> future) { + if (future.isDone()) { + return future; + } + return future.whenComplete((__, ___) -> trace(message)); + } + + public void trace(String action) { + timepoints.add(new Timepoint(action, nanoTimeSupplier.getNanos())); + } Review Comment: Yes, but it can record the previous step. For example, if the latency description only includes `topic exists: 1 ms, fail: 29999 ms`, it's still easy to identify it's stuck at the system topic loading. For debugging purpose, it's enough, because this PR does not aim at introducing a formal tracer, which usually collects spans that have both start time and end time (and something else) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
