1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.debug; 24 25 import java.util.concurrent.TimeUnit; 26 27 /** 28 * A timer for some activity of interest. A timer should be deployed using the try-with-resources 29 * pattern: 30 * 31 * <pre> 32 * try (TimerCloseable a = timer.start()) { 33 * // the code to time 34 * } 35 * </pre> 36 */ 37 public interface DebugTimer { 38 39 /** 40 * Starts this timer if timing is {@linkplain Debug#isTimeEnabled() enabled} or this is an 41 * {@linkplain #isConditional() unconditional} timer. 42 * 43 * @return an object that must be closed once the activity has completed to add the elapsed time 44 * since this call to the total for this timer 45 */ 46 DebugCloseable start(); 47 48 /** 49 * Sets a flag determining if this timer is only enabled if timing is 50 * {@link Debug#isTimeEnabled() enabled}. 51 */ 52 void setConditional(boolean flag); 53 54 /** 55 * Determines if this timer is only enabled if timing is {@link Debug#isTimeEnabled() enabled}. 56 */ 57 boolean isConditional(); 58 59 /** 60 * Gets the current value of this timer. 61 */ 62 long getCurrentValue(); 63 64 /** 65 * Gets the time unit of this timer. 66 */ 67 TimeUnit getTimeUnit(); 68 69 /** 70 * Gets the timer recording the amount time spent within a timed scope minus the time spent in 71 * any nested timed scopes. 72 * 73 * @return null if this timer does not support flat timing 74 */ 75 default DebugTimer getFlat() { 76 return null; 77 } 78 }