test/jdk/sun/tools/jstatd/JstatGCUtilParser.java
changeset 50671 1637a4e50fc9
parent 49377 ecd91135d645
child 51754 594919232b8f
equal deleted inserted replaced
50670:e810abb27deb 50671:1637a4e50fc9
    23 
    23 
    24 import java.util.Arrays;
    24 import java.util.Arrays;
    25 
    25 
    26 import jdk.testlibrary.Utils;
    26 import jdk.testlibrary.Utils;
    27 import static jdk.testlibrary.Asserts.*;
    27 import static jdk.testlibrary.Asserts.*;
       
    28 import java.text.NumberFormat;
    28 
    29 
    29 /**
    30 /**
    30  * The helper class for parsing following output from command 'jstat -gcutil':
    31  * The helper class for parsing following output from command 'jstat -gcutil':
    31  *
    32  *
    32  *  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
    33  *  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT
    33  *  100.00   0.00  64.68  13.17  73.39  33.46      2    0.003     1    0.156    0.158
    34  *  0.00   0.00  86.67   0.00   -      -      0      0.000     0    0.000     0    0.000    0.000
    34  *  100.00   0.00  76.54  13.17  73.39  33.46      2    0.003     1    0.156    0.158
    35  *  0.00   0.00  86.67   0.00   -      -      0      0.000     0    0.000     0    0.000    0.000
    35  *  100.00   0.00  83.49  13.17  73.39  33.46      2    0.003     1    0.156    0.158
       
    36  *  100.00   0.00  84.53  13.17  73.39  33.46      2    0.003     1    0.156    0.158
       
    37  *  100.00   0.00  85.57  13.17  73.39  33.46      2    0.003     1    0.156    0.158
       
    38  *
    36  *
    39  *  It will be verified that numerical values have defined types and are reasonable,
    37  *  It will be verified that numerical values have defined types and are reasonable,
    40  *  for example percentage should fit within 0-100 interval.
    38  *  for example percentage should fit within 0-100 interval.
    41  */
    39  */
    42 public class JstatGCUtilParser {
    40 public class JstatGCUtilParser {
    48     public enum GcStatistics {
    46     public enum GcStatistics {
    49         S0(GcStatisticsType.PERCENTAGE),
    47         S0(GcStatisticsType.PERCENTAGE),
    50         S1(GcStatisticsType.PERCENTAGE),
    48         S1(GcStatisticsType.PERCENTAGE),
    51         E(GcStatisticsType.PERCENTAGE),
    49         E(GcStatisticsType.PERCENTAGE),
    52         O(GcStatisticsType.PERCENTAGE),
    50         O(GcStatisticsType.PERCENTAGE),
    53         M(GcStatisticsType.PERCENTAGE),
    51         M(GcStatisticsType.PERCENTAGE_OR_DASH),
    54         CCS(GcStatisticsType.PERCENTAGE_OR_DASH),
    52         CCS(GcStatisticsType.PERCENTAGE_OR_DASH),
    55         YGC(GcStatisticsType.INTEGER),
    53         YGC(GcStatisticsType.INTEGER),
    56         YGCT(GcStatisticsType.DOUBLE),
    54         YGCT(GcStatisticsType.DOUBLE),
    57         FGC(GcStatisticsType.INTEGER),
    55         FGC(GcStatisticsType.INTEGER),
    58         FGCT(GcStatisticsType.DOUBLE),
    56         FGCT(GcStatisticsType.DOUBLE),
    95             verifyLength(valueArray);
    93             verifyLength(valueArray);
    96             for (int i = 0; i < values().length; i++) {
    94             for (int i = 0; i < values().length; i++) {
    97                 GcStatisticsType type = values()[i].getType();
    95                 GcStatisticsType type = values()[i].getType();
    98                 String value = valueArray[i].trim();
    96                 String value = valueArray[i].trim();
    99                 if (type.equals(GcStatisticsType.INTEGER)) {
    97                 if (type.equals(GcStatisticsType.INTEGER)) {
   100                     Integer.parseInt(value);
    98                     NumberFormat.getInstance().parse(value).intValue();
   101                     break;
    99                     break;
   102                 }
   100                 }
   103                 if (type.equals(GcStatisticsType.DOUBLE)) {
   101                 if (type.equals(GcStatisticsType.DOUBLE)) {
   104                     Double.parseDouble(value);
   102                     NumberFormat.getInstance().parse(value).doubleValue();
   105                     break;
   103                     break;
   106                 }
   104                 }
   107                 if (type.equals(GcStatisticsType.PERCENTAGE_OR_DASH) &&
   105                 if (type.equals(GcStatisticsType.PERCENTAGE_OR_DASH) &&
   108                         value.equals("-")) {
   106                         value.equals("-")) {
   109                     break;
   107                     break;
   110                 }
   108                 }
   111                 double percentage = Double.parseDouble(value);
   109                 double percentage = NumberFormat.getInstance().parse(value).doubleValue();
   112                 assertTrue(0 <= percentage && percentage <= 100,
   110                 assertTrue(0 <= percentage && percentage <= 100,
   113                         "Not a percentage: " + value);
   111                         "Not a percentage: " + value);
   114             }
   112             }
   115         }
   113         }
   116 
   114