Path: blob/master/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatResults.java
41159 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package utils;2324import common.ToolResults;25import java.text.NumberFormat;26import java.text.ParseException;272829/**30* Results of running the jstat tool Concrete subclasses will detail the jstat31* tool options32*/33abstract public class JstatResults extends ToolResults {3435private static final float FLOAT_COMPARISON_TOLERANCE = 0.0011f;3637public JstatResults(ToolResults rawResults) {38super(rawResults);39}4041/**42* Gets a string result from the column labeled 'name'43*44* @param name - name of the column45* @return the result46*/47public String getStringValue(String name) {48int valueNdx = new StringOfValues(getStdoutLine(0)).getIndex(name);49return new StringOfValues(getStdoutLine(1)).getValue(valueNdx);50}5152/**53* Gets a float result from the column labeled 'name'54*55* @param name - name of the column56* @return the result57*/58public float getFloatValue(String name) {59int valueNdx = new StringOfValues(getStdoutLine(0)).getIndex(name);60// Let the parsing use the current locale format.61try {62return NumberFormat.getInstance().parse(new StringOfValues(getStdoutLine(1)).getValue(valueNdx)).floatValue();63} catch (ParseException e) {64throw new NumberFormatException(e.getMessage());65}6667}6869/**70* Gets an integer result from the column labeled 'name'71*72* @param name - name of the column73* @return the result74*/75public int getIntValue(String name) {76int valueNdx = new StringOfValues(getStdoutLine(0)).getIndex(name);77try {78return NumberFormat.getInstance().parse(new StringOfValues(getStdoutLine(1)).getValue(valueNdx)).intValue();79} catch (ParseException e) {80throw new NumberFormatException(e.getMessage());81}82}8384/**85* Checks if a column with a given name exists86*87* @param name - name of the column88* @return true if the column exist, false otherwise89*/90public boolean valueExists(String name) {91return new StringOfValues(getStdoutLine(0)).getIndex(name) != -1;92}9394/**95* Helper function to assert the increase of the GC events between 296* measurements97*98* @param measurement1 -first measurement99* @param measurement2 -first measurement100*/101public static void assertGCEventsIncreased(JstatResults measurement1, JstatResults measurement2) {102assertThat(measurement2.getFloatValue("YGC") > measurement1.getFloatValue("YGC"), "YGC didn't increase between measurements 1 and 2");103assertThat(measurement2.getFloatValue("FGC") > measurement1.getFloatValue("FGC"), "FGC didn't increase between measurements 2 and 3");104}105106/**107* Helper function to assert the increase of the GC time between 2108* measurements109*110* @param measurement1 -first measurement111* @param measurement2 -second measurement112*/113public static void assertGCTimeIncreased(JstatResults measurement1, JstatResults measurement2) {114assertThat(measurement2.getFloatValue("YGCT") >= measurement1.getFloatValue("YGCT"), "YGCT time rewinded between measurements 1 and 2");115assertThat(measurement2.getFloatValue("FGCT") >= measurement1.getFloatValue("FGCT"), "FGCT time rewinded between measurements 1 and 2");116assertThat(measurement2.getFloatValue("GCT") >= measurement1.getFloatValue("GCT"), "GCT time rewinded between measurements 1 and 2");117}118119/**120* Helper function to assert the utilization of the space121*122* @param measurement - measurement results to analyze123* @param targetMemoryUsagePercent -assert that not less than this amount of124* space has been utilized125*/126public static void assertSpaceUtilization(JstatResults measurement, float targetMemoryUsagePercent) {127assertSpaceUtilization(measurement, targetMemoryUsagePercent, targetMemoryUsagePercent);128}129130/**131* Helper function to assert the utilization of the space132*133* @param measurement - measurement results to analyze134* @param targetMetaspaceUsagePercent -assert that not less than this amount135* of metaspace has been utilized136* @param targetOldSpaceUsagePercent -assert that not less than this amount137* of old space has been utilized138*/139public static void assertSpaceUtilization(JstatResults measurement, float targetMetaspaceUsagePercent,140float targetOldSpaceUsagePercent) {141142if (measurement.valueExists("OU")) {143float OC = measurement.getFloatValue("OC");144float OU = measurement.getFloatValue("OU");145assertThat((OU / OC) > targetOldSpaceUsagePercent, "Old space utilization should be > "146+ (targetOldSpaceUsagePercent * 100) + "%, actually OU / OC = " + (OU / OC));147}148149if (measurement.valueExists("MU")) {150float MC = measurement.getFloatValue("MC");151float MU = measurement.getFloatValue("MU");152assertThat((MU / MC) > targetMetaspaceUsagePercent, "Metaspace utilization should be > "153+ (targetMetaspaceUsagePercent * 100) + "%, actually MU / MC = " + (MU / MC));154}155156if (measurement.valueExists("O")) {157float O = measurement.getFloatValue("O");158assertThat(O > targetOldSpaceUsagePercent * 100, "Old space utilization should be > "159+ (targetOldSpaceUsagePercent * 100) + "%, actually O = " + O);160}161162if (measurement.valueExists("M")) {163float M = measurement.getFloatValue("M");164assertThat(M > targetMetaspaceUsagePercent * 100, "Metaspace utilization should be > "165+ (targetMetaspaceUsagePercent * 100) + "%, actually M = " + M);166}167}168169public static void assertThat(boolean result, String message) {170if (!result) {171throw new RuntimeException(message);172}173}174175public static boolean checkFloatIsSum(float sum, float... floats) {176for (float f : floats) {177sum -= f;178}179180return Math.abs(sum) <= FLOAT_COMPARISON_TOLERANCE;181}182183abstract public void assertConsistency();184}185186187