1 /* 2 * Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved. 3 * 4 * This file is part of the Lock Contention Tracing Subsystem for the HotSpot 5 * Virtual Machine, which is developed at Christian Doppler Laboratory on 6 * Monitoring and Evolution of Very-Large-Scale Software Systems. Please 7 * contact us at <http://mevss.jku.at/> if you need additional information 8 * or have any questions. 9 * 10 * This code is free software; you can redistribute it and/or modify it 11 * under the terms of the GNU General Public License version 2 only, as 12 * published by the Free Software Foundation. 13 * 14 * This code is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 * version 2 for more details (a copy is included in the LICENSE file that 18 * accompanied this code). 19 * 20 * You should have received a copy of the GNU General Public License version 21 * 2 along with this work. If not, see <http://www.gnu.org/licenses/>. 22 * 23 */ 24 package sun.evtracing; 25 26 import java.util.HashMap; 27 import java.util.Map; 28 29 public class EventTracing { 30 31 private static final EventTracing instance; 32 33 public static EventTracing getEventTracing() { 34 // TODO: check permissions 35 return instance; 36 } 37 38 public static boolean isEnabled() { 39 return instance != null; 40 } 41 42 private StatisticsProvider statisticsProvider; 43 44 private EventTracing() { 45 } 46 47 public native long queueCount(long queueHandle); 48 49 public native TraceBuffer dequeueBuffer(long queueHandle, boolean shouldBlock); 50 51 public native void enqueueBuffer(long queueHandle, long bufferHandle); 52 53 public native void resetAndEnqueueBuffer(long queueHandle, long bufferHandle); 54 55 public native void freeBuffer(long bufferHandle); 56 57 public native void writeGroupEvent(long parkGlobalSeqBeginRef, Object source); 58 59 public native String getConfiguration(); 60 61 public Map<String, Double> getStatistics() { 62 Map<String, Double> map = new HashMap<String, Double>() { 63 private static final long serialVersionUID = 1L; 64 65 @Override 66 public Double put(String key, Double value) { 67 Double old = super.put(key, value); 68 assert old == null : "overwriting not permitted"; 69 return old; 70 } 71 }; 72 73 putNativeStatistics(map); 74 if (statisticsProvider != null) { 75 statisticsProvider.putStatistics(map); 76 } 77 return map; 78 } 79 80 public void resetStatistics() { 81 resetNativeStatistics(); 82 if (statisticsProvider != null) { 83 statisticsProvider.resetStatistics(); 84 } 85 } 86 87 public void setStatisticsProvider(StatisticsProvider provider) { 88 assert statisticsProvider == null : "already set"; 89 this.statisticsProvider = provider; 90 } 91 92 private native void putNativeStatistics(Map<String, Double> map); 93 94 private native void resetNativeStatistics(); 95 96 public native void reclaimBuffers(boolean waitUntilProcessed); 97 98 public void resetMetadata() { 99 resetNativeMetadata(); 100 } 101 102 private native void resetNativeMetadata(); 103 104 105 private static native boolean registerNatives(); 106 107 static { 108 if (registerNatives()) { 109 instance = new EventTracing(); 110 } else { 111 instance = null; 112 } 113 } 114 }