sk0x50 commented on code in PR #6100: URL: https://github.com/apache/ignite-3/pull/6100#discussion_r2163273977
########## modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/timebag/IgniteStopwatch.java: ########## @@ -0,0 +1,217 @@ +/* + * 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.ignite.internal.metastorage.timebag; + +import static java.util.concurrent.TimeUnit.NANOSECONDS; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +/** + * An object that measures elapsed time in nanoseconds. It is useful to measure elapsed time using + * this class instead of direct calls to {@link System#nanoTime} for a few reasons: + * + * <ul> + * <li>An alternate time source can be substituted, for testing or performance reasons. + * <li>As documented by {@code nanoTime}, the value returned has no absolute meaning, and can only + * be interpreted as relative to another timestamp returned by {@code nanoTime} at a different + * time. {@code Stopwatch} is a more effective abstraction because it exposes only these + * relative values, not the absolute ones. + * </ul> + * + * <p>Basic usage: + * + * <pre>{@code + * Stopwatch stopwatch = Stopwatch.createStarted(); + * doSomething(); + * stopwatch.stop(); // optional + * + * Duration duration = stopwatch.elapsed(); + * + * log.info("time: " + stopwatch); // formatted string like "12.3 ms" + * }</pre> + * + * <p>Stopwatch methods are not idempotent; it is an error to start or stop a stopwatch that is + * already in the desired state. + * + * <p>When testing code that uses this class, use {@link #createUnstarted(IgniteTicker)} or {@link + * #createStarted(IgniteTicker)} to supply a fake or mock ticker. This allows you to simulate any valid + * behavior of the stopwatch. + * + * <p><b>Note:</b> This class is not thread-safe. + * + * <p><b>Warning for Android users:</b> a stopwatch with default behavior may not continue to keep + * time while the device is asleep. Instead, create one like this: Review Comment: Thanks for pointing this out! Will clean up. -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org