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.processing.statistics.aggregator; 25 26 import sun.evtracing.processing.Sanity; 27 import sun.evtracing.processing.statistics.metadata.Contention; 28 29 public class NegativeDurationContentionFilter implements ContentionProcessor { 30 31 private final ContentionProcessor delegate; 32 33 public NegativeDurationContentionFilter(ContentionProcessor delegate) { 34 this.delegate = delegate; 35 } 36 37 @Override 38 public void submit(Contention c) { 39 if (c.duration >= 0) { 40 delegate.submit(c); 41 } else { 42 // The participating threads typically execute on different CPUs. The 43 // clocks of different CPUs are always slightly out of sync, which 44 // results in some error. In some cases, this causes small durations to 45 // become negative. 46 47 // TODO: filtering negative durations is ok for computing sums, but for 48 // correct counts and averages, we need to find a way to deal with them. 49 50 if (c.duration < -1000000) { 51 Sanity.warn("dropped contention with negative duration above 1ms: %.3f ms", c.duration / (1000.f * 1000)); 52 } else { 53 Sanity.warn("dropped contention with negative duration in sub-millisecond range: %.3f us", c.duration); 54 } 55 } 56 } 57 58 @Override 59 public void merge() { 60 delegate.merge(); 61 } 62 63 }