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 24 25 package org.graalvm.compiler.debug; 26 27 import java.util.concurrent.TimeUnit; 28 29 /** 30 * A timer for some activity of interest. A timer should be deployed using the try-with-resources 31 * pattern: 32 * 33 * <pre> 34 * try (TimerCloseable a = timer.start()) { 35 * // the code to time 36 * } 37 * </pre> 38 */ 39 public interface TimerKey extends MetricKey { 40 41 /** 42 * Starts this timer. 43 * 44 * @return an object that must be closed once the activity has completed to add the elapsed time 45 * since this call to the total for this timer 46 */ 47 DebugCloseable start(DebugContext debug); 48 49 /** 50 * Gets the current value of this timer. 51 */ 52 long getCurrentValue(DebugContext debug); 53 54 /** 55 * Gets the time unit of this timer. 56 */ 57 TimeUnit getTimeUnit(); 58 59 @Override 60 TimerKey doc(String string); 61 62 /** 63 * Gets the timer recording the amount time spent within a timed scope minus the time spent in 64 * any nested timed scopes. 65 * 66 * @return null if this timer does not support flat timing 67 */ 68 default TimerKey getFlat() { 69 return null; 70 } 71 }