anjy7 commented on code in PR #22669: URL: https://github.com/apache/kafka/pull/22669#discussion_r3538979839
########## raft/src/testFixtures/java/org/apache/kafka/raft/DrainableCounter.java: ########## @@ -0,0 +1,45 @@ +/* + * 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.kafka.raft; + +import java.util.function.IntSupplier; + +/** + * Tracks a cumulative, monotonically increasing counter (e.g. the work counters on the raft mocks) as + * a drainable delta against a baseline. {@link #reset()} snapshots the current value (so the next + * {@link #delta()} starts from zero), and {@link #delta()} returns the increase since the last + * reset/delta and advances the baseline. + */ +final class DrainableCounter { + private final IntSupplier source; + private int baseline; + + DrainableCounter(IntSupplier source) { + this.source = source; + } + + void reset() { + baseline = source.getAsInt(); + } Review Comment: 1. Yes that's true. Currently we were on the assumption that every benchmark setup will have a `benchmark.zeroCountersOnSetup()` call in the end to exclude the setup cost/ counter values. Adding this to the constructor will let the benchmark author to skip that function in cases where the counter values remain zero even after the setup. 2. Yes, that would work. Only concern was using `delta()` to perform the reset could seem a bit confusing. However I added a comment that explains it, it should be good now. -- 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]
