Line data Source code
1 : // Copyright (C) 2019 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.logging; 16 : 17 : import com.google.gerrit.extensions.annotations.ExtensionPoint; 18 : 19 : /** 20 : * Extension point for logging performance records. 21 : * 22 : * <p>This extension point is invoked for all operations for which the execution time is measured. 23 : * The invocation of the extension point does not happen immediately, but only at the end of a 24 : * request (REST call, SSH call, git push). Implementors can write the execution times into a 25 : * performance log for further analysis. 26 : * 27 : * <p>For optimal performance implementors should overwrite the default <code>log</code> methods to 28 : * avoid an unneeded instantiation of Metadata. 29 : */ 30 : @ExtensionPoint 31 : public interface PerformanceLogger { 32 : /** 33 : * Record the execution time of an operation in a performance log. 34 : * 35 : * @param operation operation that was performed 36 : * @param durationMs time that the execution of the operation took (in milliseconds) 37 : */ 38 : default void log(String operation, long durationMs) { 39 2 : log(operation, durationMs, Metadata.empty()); 40 2 : } 41 : 42 : /** 43 : * Record the execution time of an operation in a performance log. 44 : * 45 : * @param operation operation that was performed 46 : * @param durationMs time that the execution of the operation took (in milliseconds) 47 : * @param metadata metadata 48 : */ 49 : void log(String operation, long durationMs, Metadata metadata); 50 : }