1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * The contents of this file are subject to the terms of either the Universal Permissive License
   7  * v 1.0 as shown at http://oss.oracle.com/licenses/upl
   8  *
   9  * or the following license:
  10  *
  11  * Redistribution and use in source and binary forms, with or without modification, are permitted
  12  * provided that the following conditions are met:
  13  *
  14  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  15  * and the following disclaimer.
  16  *
  17  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
  18  * conditions and the following disclaimer in the documentation and/or other materials provided with
  19  * the distribution.
  20  *
  21  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  22  * endorse or promote products derived from this software without specific prior written permission.
  23  *
  24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  26  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  31  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 package org.openjdk.jmc.flightrecorder.jdk;
  34 
  35 import static org.openjdk.jmc.common.item.Aggregators.avg;
  36 import static org.openjdk.jmc.common.item.Aggregators.distinctAsString;
  37 import static org.openjdk.jmc.common.item.Aggregators.filter;
  38 import static org.openjdk.jmc.common.item.Aggregators.max;
  39 import static org.openjdk.jmc.common.item.Aggregators.min;
  40 import static org.openjdk.jmc.common.item.Aggregators.or;
  41 import static org.openjdk.jmc.common.item.Aggregators.sum;
  42 import static org.openjdk.jmc.flightrecorder.JfrAttributes.DURATION;
  43 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.CONCURRENT_GC_THREADS;
  44 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.FLAG_NAME;
  45 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.FLAG_VALUE_BOOLEAN;
  46 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.FLAG_VALUE_NUMBER;
  47 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.GC_TIME_RATIO;
  48 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_ADDRESS_SIZE;
  49 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_INITIAL_SIZE;
  50 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_MAX_SIZE;
  51 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_MIN_SIZE;
  52 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_OBJECT_ALIGNMENT;
  53 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_TOTAL;
  54 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HEAP_USED;
  55 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.HW_THREADS;
  56 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_ADDRESS;
  57 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_FILE_BYTES_READ;
  58 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_FILE_BYTES_WRITTEN;
  59 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_HOST;
  60 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_PORT;
  61 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_SOCKET_BYTES_READ;
  62 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.IO_SOCKET_BYTES_WRITTEN;
  63 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.NEW_RATIO;
  64 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.NUMBER_OF_CORES;
  65 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.NUMBER_OF_SOCKETS;
  66 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.PARALLEL_GC_THREADS;
  67 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.TENURING_THRESHOLD_INITIAL;
  68 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.TENURING_THRESHOLD_MAXIMUM;
  69 import static org.openjdk.jmc.flightrecorder.jdk.JdkAttributes.TLAB_REFILL_WASTE_LIMIT;
  70 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.AFTER_GC;
  71 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.ALLOC_INSIDE_TLAB;
  72 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.ALLOC_OUTSIDE_TLAB;
  73 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.BEFORE_GC;
  74 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.CODE_CACHE_FULL;
  75 import static org.openjdk.jmc.flightrecorder.jdk.JdkFilters.SOCKET_READ_OR_WRITE;
  76 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.BOOLEAN_FLAG;
  77 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.CPU_INFORMATION;
  78 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.FILE_READ;
  79 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.FILE_WRITE;
  80 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.GC_CONF;
  81 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.GC_CONF_SURVIVOR;
  82 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.GC_CONF_TLAB;
  83 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.GC_CONF_YOUNG_GENERATION;
  84 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.GC_PAUSE;
  85 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.HEAP_CONF;
  86 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.HEAP_SUMMARY;
  87 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.OBJECT_COUNT;
  88 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.OS_INFORMATION;
  89 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.OS_MEMORY_SUMMARY;
  90 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.SOCKET_READ;
  91 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.SOCKET_WRITE;
  92 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.ULONG_FLAG;
  93 import static org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs.VM_INFO;
  94 
  95 import java.text.MessageFormat;
  96 
  97 import org.openjdk.jmc.common.item.Aggregators;
  98 import org.openjdk.jmc.common.item.IAccessorFactory;
  99 import org.openjdk.jmc.common.item.IAggregator;
 100 import org.openjdk.jmc.common.item.IAttribute;
 101 import org.openjdk.jmc.common.item.IMemberAccessor;
 102 import org.openjdk.jmc.common.item.IType;
 103 import org.openjdk.jmc.common.item.ItemFilters;
 104 import org.openjdk.jmc.common.unit.IQuantity;
 105 import org.openjdk.jmc.common.unit.UnitLookup;
 106 import org.openjdk.jmc.flightrecorder.JfrAttributes;
 107 import org.openjdk.jmc.flightrecorder.jdk.messages.internal.Messages;
 108 
 109 /**
 110  * Various useful aggregators based on JDK flight recorder data.
 111  */
 112 public final class JdkAggregators {
 113 
 114         // VM Info
 115         public static final IAggregator<String, ?> JVM_NAME = distinctAsString(VM_INFO, JdkAttributes.JVM_NAME);
 116         public static final IAggregator<IQuantity, ?> JVM_PID = min(JdkAttributes.JVM_PID.getName(), null,
 117                         VM_INFO, JdkAttributes.JVM_PID);
 118         public static final IAggregator<IQuantity, ?> JVM_START_TIME = min(JdkAttributes.JVM_START_TIME.getName(), null,
 119                         VM_INFO, JdkAttributes.JVM_START_TIME);
 120         public static final IAggregator<String, ?> JVM_VERSION = distinctAsString(VM_INFO, JdkAttributes.JVM_VERSION);
 121         public static final IAggregator<String, ?> JAVA_ARGUMENTS = distinctAsString(VM_INFO, JdkAttributes.JAVA_ARGUMENTS);
 122         public static final IAggregator<String, ?> JVM_ARGUMENTS = distinctAsString(VM_INFO, JdkAttributes.JVM_ARGUMENTS);
 123         
 124         public static final IAggregator<IQuantity, ?> JVM_SHUTDOWN_TIME = min(Messages.getString(Messages.ATTR_SHUTDOWN_TIME), null,
 125                         JdkTypeIDs.VM_SHUTDOWN, JfrAttributes.START_TIME);
 126         public static final IAggregator<String, ?> JVM_SHUTDOWN_REASON = distinctAsString(JdkTypeIDs.VM_SHUTDOWN,
 127                         JdkAttributes.SHUTDOWN_REASON);
 128         // CPU info
 129         public static final IAggregator<IQuantity, ?> MIN_HW_THREADS = min(HW_THREADS.getName(), null, CPU_INFORMATION,
 130                         HW_THREADS);
 131         public static final IAggregator<IQuantity, ?> MIN_NUMBER_OF_CORES = min(NUMBER_OF_CORES.getName(), null,
 132                         CPU_INFORMATION, NUMBER_OF_CORES);
 133         public static final IAggregator<IQuantity, ?> MIN_NUMBER_OF_SOCKETS = min(NUMBER_OF_SOCKETS.getName(), null,
 134                         CPU_INFORMATION, NUMBER_OF_SOCKETS);
 135         public static final IAggregator<String, ?> CPU_DESCRIPTION = distinctAsString(CPU_INFORMATION,
 136                         JdkAttributes.CPU_DESCRIPTION);
 137         public static final IAggregator<String, ?> CPU_TYPE = distinctAsString(CPU_INFORMATION, JdkAttributes.CPU_TYPE);
 138         // OS info
 139         public static final IAggregator<String, ?> OS_VERSION = distinctAsString(OS_INFORMATION, JdkAttributes.OS_VERSION);
 140         public static final IAggregator<IQuantity, ?> MAX_USED_MEMORY = max(
 141                         Messages.getString(Messages.AGGR_MAX_USED_MEMORY), null, OS_MEMORY_SUMMARY, JdkAttributes.OS_MEMORY_USED);
 142         public static final IAggregator<IQuantity, ?> MIN_TOTAL_MEMORY = min(
 143                         Messages.getString(Messages.AGGR_MIN_TOTAL_MEMORY), null, OS_MEMORY_SUMMARY, JdkAttributes.OS_MEMORY_TOTAL);
 144         // Heap config
 145         public static final IAggregator<IQuantity, ?> HEAP_CONF_MAX_SIZE = max(HEAP_MAX_SIZE.getName(), null, HEAP_CONF,
 146                         HEAP_MAX_SIZE);
 147         public static final IAggregator<IQuantity, ?> HEAP_CONF_MIN_SIZE = min(HEAP_MIN_SIZE.getName(), null, HEAP_CONF,
 148                         HEAP_MIN_SIZE);
 149         public static final IAggregator<IQuantity, ?> HEAP_CONF_INITIAL_SIZE_MIN = min(HEAP_INITIAL_SIZE.getName(), null,
 150                         HEAP_CONF, HEAP_INITIAL_SIZE);
 151         public static final IAggregator<IQuantity, ?> HEAP_OBJECT_ALIGNMENT_MIN = min(HEAP_OBJECT_ALIGNMENT.getName(), null,
 152                         HEAP_CONF, HEAP_OBJECT_ALIGNMENT);
 153         public static final IAggregator<IQuantity, ?> HEAP_ADDRESS_SIZE_MIN = min(HEAP_ADDRESS_SIZE.getName(), null,
 154                         HEAP_CONF, HEAP_ADDRESS_SIZE);
 155         public static final IAggregator<Boolean, ?> USE_COMPRESSED_OOPS = or(HEAP_CONF,
 156                         JdkAttributes.HEAP_USE_COMPRESSED_OOPS);
 157         public static final IAggregator<String, ?> COMPRESSED_OOPS_MODE = distinctAsString(HEAP_CONF,
 158                         JdkAttributes.HEAP_COMPRESSED_OOPS_MODE);
 159         // GC config
 160         public static final IAggregator<String, ?> OLD_COLLECTOR = distinctAsString(GC_CONF, JdkAttributes.OLD_COLLECTOR);
 161         public static final IAggregator<String, ?> YOUNG_COLLECTOR = distinctAsString(GC_CONF,
 162                         JdkAttributes.YOUNG_COLLECTOR);
 163         public static final IAggregator<IQuantity, ?> PARALLEL_GC_THREAD_COUNT_MAX = max(GC_CONF, PARALLEL_GC_THREADS);
 164         public static final IAggregator<IQuantity, ?> PARALLEL_GC_THREAD_COUNT_MIN = min(PARALLEL_GC_THREADS.getName(),
 165                         null, GC_CONF, PARALLEL_GC_THREADS);
 166         public static final IAggregator<IQuantity, ?> CONCURRENT_GC_THREAD_COUNT_MIN = min(CONCURRENT_GC_THREADS.getName(),
 167                         null, GC_CONF, CONCURRENT_GC_THREADS);
 168         public static final IAggregator<Boolean, ?> EXPLICIT_GC_CONCURRENT = or(GC_CONF,
 169                         JdkAttributes.EXPLICIT_GC_CONCURRENT);
 170         public static final IAggregator<Boolean, ?> EXPLICIT_GC_DISABLED = or(GC_CONF, JdkAttributes.EXPLICIT_GC_DISABLED);
 171         public static final IAggregator<Boolean, ?> USE_DYNAMIC_GC_THREADS = or(GC_CONF,
 172                         JdkAttributes.USE_DYNAMIC_GC_THREADS);
 173         public static final IAggregator<IQuantity, ?> GC_TIME_RATIO_MIN = min(GC_TIME_RATIO.getName(), null, GC_CONF,
 174                         GC_TIME_RATIO);
 175         public static final IAggregator<IQuantity, ?> YOUNG_GENERATION_MIN_SIZE = max(
 176                         JdkAttributes.YOUNG_GENERATION_MIN_SIZE.getName(), null, GC_CONF_YOUNG_GENERATION,
 177                         JdkAttributes.YOUNG_GENERATION_MIN_SIZE);
 178         public static final IAggregator<IQuantity, ?> YOUNG_GENERATION_MAX_SIZE = min(
 179                         JdkAttributes.YOUNG_GENERATION_MAX_SIZE.getName(), null, GC_CONF_YOUNG_GENERATION,
 180                         JdkAttributes.YOUNG_GENERATION_MIN_SIZE);
 181         public static final IAggregator<IQuantity, ?> NEW_RATIO_MIN = min(NEW_RATIO.getName(), null,
 182                         GC_CONF_YOUNG_GENERATION, NEW_RATIO);
 183         public static final IAggregator<IQuantity, ?> TENURING_THRESHOLD_INITIAL_MIN = min(
 184                         TENURING_THRESHOLD_INITIAL.getName(), null, GC_CONF_SURVIVOR, TENURING_THRESHOLD_INITIAL);
 185         public static final IAggregator<IQuantity, ?> TENURING_THRESHOLD_MAX = max(TENURING_THRESHOLD_MAXIMUM.getName(),
 186                         null, GC_CONF_SURVIVOR, TENURING_THRESHOLD_MAXIMUM);
 187         public static final IAggregator<Boolean, ?> USES_TLABS = or(GC_CONF_TLAB, JdkAttributes.USES_TLABS);
 188         public static final IAggregator<IQuantity, ?> TLAB_MIN_SIZE = min(JdkAttributes.TLAB_MIN_SIZE.getName(), null,
 189                         GC_CONF_TLAB, JdkAttributes.TLAB_MIN_SIZE);
 190         public static final IAggregator<IQuantity, ?> TLAB_REFILL_WASTE_LIMIT_MIN = min(TLAB_REFILL_WASTE_LIMIT.getName(),
 191                         null, GC_CONF_TLAB, TLAB_REFILL_WASTE_LIMIT);
 192         // Other
 193         public static final IAggregator<IQuantity, ?> AVG_HEAP_USED_BEFORE_GC = filter(
 194                         Messages.getString(Messages.AGGR_AVG_HEAP_USED_BEFORE_GC), null, avg(HEAP_SUMMARY, HEAP_USED), BEFORE_GC);
 195         public static final IAggregator<IQuantity, ?> AVG_HEAP_USED_AFTER_GC = filter(
 196                         Messages.getString(Messages.AGGR_AVG_HEAP_USED_AFTER_GC), null, avg(HEAP_SUMMARY, HEAP_USED), AFTER_GC);
 197         public static final IAggregator<IQuantity, ?> SUM_HEAP_USED_BEFORE_GC = filter("SUM_HEAP_USED_BEFORE_GC", null, //$NON-NLS-1$
 198                         sum(HEAP_SUMMARY, HEAP_USED), BEFORE_GC);
 199         public static final IAggregator<IQuantity, ?> SUM_HEAP_USED_AFTER_GC = filter("SUM_HEAP_USED_AFTER_GC", null, //$NON-NLS-1$
 200                         sum(HEAP_SUMMARY, HEAP_USED), AFTER_GC);
 201 
 202         public static final IAggregator<IQuantity, ?> OBJECT_COUNT_MAX_SIZE = max(
 203                         Messages.getString(Messages.AGGR_OBJECT_COUNT_MAX_SIZE),
 204                         Messages.getString(Messages.AGGR_OBJECT_COUNT_MAX_SIZE_DESC), OBJECT_COUNT, HEAP_TOTAL);
 205         public static final IAggregator<IQuantity, ?> OBJECT_COUNT_MAX_INSTANCES = max(
 206                         Messages.getString(Messages.AGGR_OBJECT_COUNT_MAX_INSTANCES),
 207                         Messages.getString(Messages.AGGR_OBJECT_COUNT_MAX_INSTANCES_DESC), OBJECT_COUNT, JdkAttributes.COUNT);
 208         public static final IAggregator<Boolean, ?> UNLOCK_EXPERIMENTAL_VM_OPTIONS = filter(
 209                         Messages.getString(Messages.AGGR_UNLOCK_EXPERIMENTAL_VM_OPTIONS), null,
 210                         or(BOOLEAN_FLAG, FLAG_VALUE_BOOLEAN), ItemFilters.equals(FLAG_NAME, "UnlockExperimentalVMOptions")); //$NON-NLS-1$
 211         public static final IAggregator<Boolean, ?> IGNORE_UNRECOGNIZED_VM_OPTIONS = filter(
 212                         Messages.getString(Messages.AGGR_IGNORE_UNRECOGNIZED_VM_OPTIONS), null,
 213                         or(BOOLEAN_FLAG, FLAG_VALUE_BOOLEAN), ItemFilters.equals(FLAG_NAME, "IgnoreUnrecognizedVMOptions")); //$NON-NLS-1$
 214         public static final IAggregator<Boolean, ?> USE_STRING_DEDUPLICATION = filter("UseStringDeduplication", null, //$NON-NLS-1$
 215                         or(BOOLEAN_FLAG, FLAG_VALUE_BOOLEAN), ItemFilters.equals(FLAG_NAME, "UseStringDeduplication")); //$NON-NLS-1$
 216         public static final IAggregator<Boolean, ?> USE_G1_GC = filter("UseG1GC", null, //$NON-NLS-1$
 217                         or(BOOLEAN_FLAG, FLAG_VALUE_BOOLEAN), ItemFilters.equals(FLAG_NAME, "UseG1GC")); //$NON-NLS-1$
 218         public static final IAggregator<Boolean, ?> COMPACT_STRINGS = filter("CompactStrings", null, //$NON-NLS-1$
 219                         or(BOOLEAN_FLAG, FLAG_VALUE_BOOLEAN), ItemFilters.equals(FLAG_NAME, "CompactStrings")); //$NON-NLS-1$
 220         public static final IAggregator<IQuantity, ?> LARGEST_MAX_HEAP_SIZE_FROM_FLAG = filter(
 221                         Messages.getString(Messages.AGGR_LARGEST_MAX_HEAP_SIZE_FROM_FLAG), null, max(ULONG_FLAG, FLAG_VALUE_NUMBER),
 222                         ItemFilters.equals(FLAG_NAME, "MaxHeapSize")); //$NON-NLS-1$
 223         public static final IAggregator<IQuantity, ?> OUTSIDE_TLAB_COUNT = Aggregators.count(
 224                         Messages.getString(Messages.AGGR_OUTSIDE_TLAB_COUNT),
 225                         Messages.getString(Messages.AGGR_OUTSIDE_TLAB_COUNT_DESC), ALLOC_OUTSIDE_TLAB);
 226         public static final IAggregator<IQuantity, ?> INSIDE_TLAB_COUNT = Aggregators.count(
 227                         Messages.getString(Messages.AGGR_INSIDE_TLAB_COUNT),
 228                         Messages.getString(Messages.AGGR_INSIDE_TLAB_COUNT_DESC), ALLOC_INSIDE_TLAB);
 229         public static final IAggregator<IQuantity, ?> FILE_WRITE_LONGEST = Aggregators.max(FILE_WRITE, DURATION);


 230         public static final IAggregator<IQuantity, ?> FILE_READ_LONGEST = Aggregators.max(FILE_READ, DURATION);


 231         public static final IAggregator<IQuantity, ?> FILE_WRITE_SIZE = Aggregators.sum(
 232                         Messages.getString(Messages.AGGR_FILE_WRITE_SIZE), Messages.getString(Messages.AGGR_FILE_WRITE_SIZE_DESC),
 233                         FILE_WRITE, IO_FILE_BYTES_WRITTEN);
 234         public static final IAggregator<IQuantity, ?> FILE_READ_SIZE = Aggregators.sum(
 235                         Messages.getString(Messages.AGGR_FILE_READ_SIZE), Messages.getString(Messages.AGGR_FILE_READ_SIZE_DESC),
 236                         FILE_READ, IO_FILE_BYTES_READ);
 237         public static final IAggregator<IQuantity, ?> FILE_WRITE_COUNT = Aggregators.count(
 238                         Messages.getString(Messages.AGGR_FILE_WRITE_COUNT), Messages.getString(Messages.AGGR_FILE_WRITE_COUNT_DESC),
 239                         JdkFilters.FILE_WRITE);
 240         public static final IAggregator<IQuantity, ?> FILE_READ_COUNT = Aggregators.count(
 241                         Messages.getString(Messages.AGGR_FILE_READ_COUNT), Messages.getString(Messages.AGGR_FILE_READ_COUNT_DESC),
 242                         JdkFilters.FILE_READ);
 243         public static final IAggregator<IQuantity, ?> ERROR_COUNT = Aggregators.count(
 244                         Messages.getString(Messages.AGGR_ERROR_COUNT), Messages.getString(Messages.AGGR_ERROR_COUNT_DESC),
 245                         JdkFilters.ERRORS);
 246         public static final IAggregator<IQuantity, ?> EXCEPTIONS_COUNT = Aggregators.count(
 247                         Messages.getString(Messages.AGGR_EXCEPTIONS_COUNT), Messages.getString(Messages.AGGR_EXCEPTIONS_COUNT_DESC),
 248                         JdkFilters.EXCEPTIONS);
 249         public static final IAggregator<IQuantity, ?> THROWABLES_COUNT = Aggregators.count(
 250                         Messages.getString(Messages.AGGR_THROWABLES_COUNT), Messages.getString(Messages.AGGR_THROWABLES_COUNT_DESC),
 251                         JdkFilters.THROWABLES);
 252         public static final IAggregator<IQuantity, ?> CODE_CACHE_FULL_COUNT = Aggregators.count(
 253                         Messages.getString(Messages.AGGR_CODE_CACHE_FULL_COUNT),
 254                         Messages.getString(Messages.AGGR_CODE_CACHE_FULL_COUNT_DESC), CODE_CACHE_FULL);
 255         public static final IAggregator<IQuantity, ?> SOCKET_WRITE_LONGEST = Aggregators.max(SOCKET_WRITE, DURATION);

 256         public static final IAggregator<IQuantity, ?> SOCKET_READ_LONGEST = Aggregators.max(SOCKET_READ, DURATION);


 257         public static final IAggregator<IQuantity, ?> SOCKET_WRITE_SIZE = Aggregators.sum(
 258                         Messages.getString(Messages.AGGR_SOCKET_WRITE_SIZE),
 259                         Messages.getString(Messages.AGGR_SOCKET_WRITE_SIZE_DESC), SOCKET_WRITE, IO_SOCKET_BYTES_WRITTEN);
 260         public static final IAggregator<IQuantity, ?> SOCKET_READ_SIZE = Aggregators.sum(
 261                         Messages.getString(Messages.AGGR_SOCKET_READ_SIZE), Messages.getString(Messages.AGGR_SOCKET_READ_SIZE_DESC),
 262                         SOCKET_READ, IO_SOCKET_BYTES_READ);
 263         public static final IAggregator<IQuantity, ?> SOCKET_WRITE_COUNT = Aggregators.count(
 264                         Messages.getString(Messages.AGGR_SOCKET_WRITE_COUNT),
 265                         Messages.getString(Messages.AGGR_SOCKET_WRITE_COUNT_DESC), JdkFilters.SOCKET_WRITE);
 266         public static final IAggregator<IQuantity, ?> SOCKET_READ_COUNT = Aggregators.count(
 267                         Messages.getString(Messages.AGGR_SOCKET_READ_COUNT),
 268                         Messages.getString(Messages.AGGR_SOCKET_READ_COUNT_DESC), JdkFilters.SOCKET_READ);
 269         public static final IAggregator<IQuantity, ?> NUMBER_OF_DISTINCT_PORTS = Aggregators
 270                         .filter(Aggregators.countDistinct(Messages.getString(Messages.AGGR_NUMBER_OF_DISTINCT_PORTS),
 271                                         Messages.getString(Messages.AGGR_NUMBER_OF_DISTINCT_PORTS_DESC), IO_PORT), SOCKET_READ_OR_WRITE);
 272         public static final IAggregator<IQuantity, ?> NUMBER_OF_DISTINCT_HOSTS = Aggregators
 273                         .filter(Aggregators.countDistinct(Messages.getString(Messages.AGGR_NUMBER_OF_DISTINCT_HOSTS),
 274                                         Messages.getString(Messages.AGGR_NUMBER_OF_DISTINCT_HOSTS_DESC), IO_ADDRESS), SOCKET_READ_OR_WRITE);
 275         public static final IAggregator<String, ?> HOST_NAMES_DISTINCT = Aggregators
 276                         .filter(Aggregators.distinctAsString(IO_HOST, ","), SOCKET_READ_OR_WRITE); //$NON-NLS-1$
 277         public static final IAggregator<IQuantity, ?> LONGEST_GC_PAUSE = Aggregators.max(
 278                         Messages.getString(Messages.AGGR_LONGEST_GC_PAUSE), Messages.getString(Messages.AGGR_LONGEST_GC_PAUSE_DESC),
 279                         GC_PAUSE, DURATION);
 280         public static final IAggregator<IQuantity, ?> TOTAL_GC_PAUSE = Aggregators.sum(
 281                         Messages.getString(Messages.AGGR_TOTAL_GC_PAUSE), Messages.getString(Messages.AGGR_TOTAL_GC_PAUSE_DESC),
 282                         GC_PAUSE, DURATION);
 283 
 284         public static final IAggregator<IQuantity, ?> JFR_DATA_LOST_COUNT = Aggregators.count(
 285                         Messages.getString(Messages.AGGR_JFR_DATA_LOST_COUNT),
 286                         Messages.getString(Messages.AGGR_JFR_DATA_LOST_COUNT_DESC), JdkFilters.JFR_DATA_LOST);
 287         public static final IAggregator<IQuantity, ?> FLR_DATA_LOST_SIZE = Aggregators.sum(
 288                         Messages.getString(Messages.AGGR_FLR_DATA_LOST_SIZE),
 289                         Messages.getString(Messages.AGGR_FLR_DATA_LOST_SIZE_DESC), JdkTypeIDs.JFR_DATA_LOST,
 290                         JfrAttributes.FLR_DATA_LOST);
 291         public static final IAggregator<IQuantity, ?> AVG_JVM_USER_CPU = Aggregators.avg(JdkTypeIDs.CPU_LOAD,
 292                         JdkAttributes.JVM_USER);
 293         public static final IAggregator<IQuantity, ?> AVG_JVM_TOTAL_CPU = Aggregators.avg(JdkTypeIDs.CPU_LOAD,
 294                         JdkAttributes.JVM_TOTAL);
 295         public static final IAggregator<IQuantity, ?> EXECUTION_SAMPLE_COUNT = Aggregators.count(
 296                         Messages.getString(Messages.AGGR_EXECUTION_SAMPLE_COUNT),
 297                         Messages.getString(Messages.AGGR_EXECUTION_SAMPLE_COUNT_DESC), JdkFilters.EXECUTION_SAMPLE);
 298         public static final IAggregator<IQuantity, ?> METASPACE_OOM_COUNT = Aggregators.count(
 299                         Messages.getString(Messages.AGGR_METASPACE_OOM_COUNT),
 300                         Messages.getString(Messages.AGGR_METASPACE_OOM_COUNT_DESC), JdkFilters.METASPACE_OOM);
 301         public static final IAggregator<IQuantity, ?> TOTAL_BLOCKED_TIME = Aggregators.sum(
 302                         Messages.getString(Messages.AGGR_TOTAL_BLOCKED_TIME),
 303                         Messages.getString(Messages.AGGR_TOTAL_BLOCKED_TIME_DESC), JdkTypeIDs.MONITOR_ENTER, DURATION);
 304         public static final IAggregator<IQuantity, ?> TOTAL_BLOCKED_COUNT = Aggregators.count(
 305                         Messages.getString(Messages.AGGR_TOTAL_BLOCKED_COUNT),
 306                         Messages.getString(Messages.AGGR_TOTAL_BLOCKED_COUNT_DESC), JdkFilters.MONITOR_ENTER);
 307         public static final IAggregator<IQuantity, ?> MAX_BLOCKED_TIME = Aggregators.max(
 308                         Messages.getString(Messages.AGGR_MAX_BLOCKED_TIME), Messages.getString(Messages.AGGR_MAX_BLOCKED_TIME_DESC),
 309                         JdkTypeIDs.MONITOR_ENTER, DURATION);
 310         public static final IAggregator<IQuantity, ?> AVG_BLOCKED_TIME = Aggregators.avg(
 311                         Messages.getString(Messages.AGGR_AVG_BLOCKED_TIME), Messages.getString(Messages.AGGR_AVG_BLOCKED_TIME_DESC),
 312                         JdkTypeIDs.MONITOR_ENTER, DURATION);
 313         public static final IAggregator<IQuantity, ?> STDDEV_BLOCKED_TIME = Aggregators.stddevp(
 314                         Messages.getString(Messages.AGGR_STDDEV_BLOCKED_TIME),
 315                         Messages.getString(Messages.AGGR_STDDEV_BLOCKED_TIME_DESC), DURATION);
 316         public static final IAggregator<IQuantity, ?> ALLOC_INSIDE_TLAB_AVG = Aggregators.avg(
 317                         Messages.getString(Messages.AGGR_ALLOC_INSIDE_TLAB_AVG),
 318                         Messages.getString(Messages.AGGR_ALLOC_INSIDE_TLAB_AVG_DESC), JdkTypeIDs.ALLOC_INSIDE_TLAB,
 319                         JdkAttributes.ALLOCATION_SIZE);
 320         public static final IAggregator<IQuantity, ?> ALLOC_OUTSIDE_TLAB_AVG = Aggregators.avg(
 321                         Messages.getString(Messages.AGGR_ALLOC_OUTSIDE_TLAB_AVG),
 322                         Messages.getString(Messages.AGGR_ALLOC_OUTSIDE_TLAB_AVG_DESC), JdkTypeIDs.ALLOC_OUTSIDE_TLAB,
 323                         JdkAttributes.ALLOCATION_SIZE);
 324         public static final IAggregator<IQuantity, ?> ALLOC_INSIDE_TLAB_SUM = Aggregators.sum(
 325                         Messages.getString(Messages.AGGR_ALLOC_INSIDE_TLAB_SUM),
 326                         Messages.getString(Messages.AGGR_ALLOC_INSIDE_TLAB_SUM_DESC), JdkTypeIDs.ALLOC_INSIDE_TLAB,
 327                         JdkAttributes.TLAB_SIZE);
 328         public static final IAggregator<IQuantity, ?> ALLOC_OUTSIDE_TLAB_SUM = Aggregators.sum(
 329                         Messages.getString(Messages.AGGR_ALLOC_OUTSIDE_TLAB_SUM),
 330                         Messages.getString(Messages.AGGR_ALLOC_OUTSIDE_TLAB_SUM_DESC), JdkTypeIDs.ALLOC_OUTSIDE_TLAB,
 331                         JdkAttributes.ALLOCATION_SIZE);
 332         public static final IAggregator<IQuantity, ?> SWEEP_METHOD_SUM = Aggregators.sum(
 333                         Messages.getString(Messages.AGGR_SWEEP_METHOD_SUM), Messages.getString(Messages.AGGR_SWEEP_METHOD_SUM_DESC),
 334                         JdkTypeIDs.SWEEP_CODE_CACHE, JdkAttributes.SWEEP_METHOD_SWEPT);
 335         public static final IAggregator<IQuantity, ?> SWEEP_FLUSHED_SUM = Aggregators.sum(
 336                         Messages.getString(Messages.AGGR_SWEEP_FLUSHED_SUM),
 337                         Messages.getString(Messages.AGGR_SWEEP_FLUSHED_SUM_DESC), JdkTypeIDs.SWEEP_CODE_CACHE,
 338                         JdkAttributes.SWEEP_METHOD_FLUSHED);
 339         public static final IAggregator<IQuantity, ?> SWEEP_ZOMBIFIED_SUM = Aggregators.sum(
 340                         Messages.getString(Messages.AGGR_SWEEP_ZOMBIFIED_SUM),
 341                         Messages.getString(Messages.AGGR_SWEEP_ZOMBIFIED_SUM_DESC), JdkTypeIDs.SWEEP_CODE_CACHE,
 342                         JdkAttributes.SWEEP_METHOD_ZOMBIFIED);
 343         public static final IAggregator<IQuantity, ?> SWEEP_RECLAIMED_SUM = Aggregators.sum(
 344                         Messages.getString(Messages.AGGR_SWEEP_RECLAIMED_SUM),
 345                         Messages.getString(Messages.AGGR_SWEEP_RECLAIMED_SUM_DESC), JdkTypeIDs.SWEEP_CODE_CACHE,
 346                         JdkAttributes.SWEEP_METHOD_RECLAIMED);
 347         public static final IAggregator<IQuantity, ?> FIRST_ITEM_START = Aggregators.min(JfrAttributes.START_TIME);
 348         public static final IAggregator<IQuantity, ?> FIRST_ITEM_END = Aggregators.min(JfrAttributes.END_TIME);
 349         public static final IAggregator<IQuantity, ?> LAST_ITEM_END = Aggregators.max(JfrAttributes.END_TIME);
 350         public static final IAggregator<IQuantity, ?> LONGEST_EVENT = Aggregators.max(DURATION);
 351         public static final IAggregator<IQuantity, ?> ITEM_COUNT = Aggregators
 352                         .count(Messages.getString(Messages.AGGR_ITEM_COUNT), Messages.getString(Messages.AGGR_ITEM_COUNT_DESC));
 353 
 354         public static final IAggregator<IQuantity, ?> ALLOCATION_TOTAL = Aggregators.sum(
 355                         Messages.getString(Messages.AGGR_ALLOCATION_TOTAL), Messages.getString(Messages.AGGR_ALLOCATION_TOTAL_DESC),
 356                         UnitLookup.MEMORY, new IAccessorFactory<IQuantity>() {
 357 
 358                                 @Override
 359                                 public <T> IMemberAccessor<? extends IQuantity, T> getAccessor(IType<T> type) {
 360                                         if (type.getIdentifier().equals(JdkTypeIDs.ALLOC_INSIDE_TLAB)) {
 361                                                 return JdkAttributes.TLAB_SIZE.getAccessor(type);
 362                                         } else if (type.getIdentifier().equals(JdkTypeIDs.ALLOC_OUTSIDE_TLAB)) {
 363                                                 return JdkAttributes.ALLOCATION_SIZE.getAccessor(type);
 364                                         }
 365                                         return null;
 366                                 }
 367                         });
 368         public static final IAggregator<IQuantity, ?> TOTAL_IO_TIME = Aggregators.filter(
 369                         Aggregators.sum(Messages.getString(Messages.AGGR_TOTAL_IO_TIME),
 370                                         Messages.getString(Messages.AGGR_TOTAL_IO_TIME_DESC), JfrAttributes.DURATION),
 371                         JdkFilters.FILE_OR_SOCKET_IO);
 372         public static final IAggregator<IQuantity, ?> MAX_IO_TIME = Aggregators.filter(
 373                         Aggregators.max(Messages.getString(Messages.AGGR_MAX_IO_TIME),
 374                                         Messages.getString(Messages.AGGR_MAX_IO_TIME_DESC), JfrAttributes.DURATION),
 375                         JdkFilters.FILE_OR_SOCKET_IO);
 376         public static final IAggregator<IQuantity, ?> AVG_IO_TIME = Aggregators.filter(
 377                         Aggregators.avg(Messages.getString(Messages.AGGR_AVG_IO_TIME),
 378                                         Messages.getString(Messages.AGGR_AVG_IO_TIME_DESC), JfrAttributes.DURATION),
 379                         JdkFilters.FILE_OR_SOCKET_IO);
 380         public static final IAggregator<IQuantity, ?> STDDEV_IO_TIME = Aggregators.filter(
 381                         Aggregators.stddevp(Messages.getString(Messages.AGGR_STDDEV_IO_TIME),
 382                                         Messages.getString(Messages.AGGR_STDDEV_IO_TIME_DESC), JfrAttributes.DURATION),
 383                         JdkFilters.FILE_OR_SOCKET_IO);
 384         public static final IAggregator<IQuantity, ?> TOTAL_IO_COUNT = Aggregators.count(
 385                         Messages.getString(Messages.AGGR_TOTAL_IO_COUNT), Messages.getString(Messages.AGGR_TOTAL_IO_COUNT_DESC),
 386                         JdkFilters.FILE_OR_SOCKET_IO);
 387         public static final IAggregator<IQuantity, ?> CLASS_LOADING_COUNT = Aggregators.count(
 388                         Messages.getString(Messages.AGGR_CLASS_LOADING_COUNT),
 389                         Messages.getString(Messages.AGGR_CLASS_LOADING_COUNT_DESC), JdkFilters.CLASS_LOAD);
 390         public static final IAggregator<IQuantity, ?> CLASS_LOADING_TIME_SUM = Aggregators.sum(
 391                         Messages.getString(Messages.AGGR_CLASS_LOADING_TIME_SUM),
 392                         Messages.getString(Messages.AGGR_CLASS_LOADING_TIME_SUM_DESC), JdkTypeIDs.CLASS_LOAD,
 393                         JfrAttributes.DURATION);
 394 
 395         public static final IAggregator<IQuantity, ?> VM_OPERATION_COUNT = Aggregators.count(
 396                         Messages.getString(Messages.AGGR_VM_OPERATION_COUNT),
 397                         Messages.getString(Messages.AGGR_VM_OPERATION_COUNT_DESC), JdkFilters.VM_OPERATIONS);
 398         public static final IAggregator<IQuantity, ?> VM_OPERATION_DURATION = Aggregators.sum(
 399                         Messages.getString(Messages.AGGR_VM_OPERATION_DURATION),
 400                         Messages.getString(Messages.AGGR_VM_OPERATION_DURATION_DESC), JfrAttributes.DURATION);
 401 
 402         public static final IAggregator<IQuantity, ?> COMPILATIONS_COUNT = Aggregators.count(
 403                         Messages.getString(Messages.AGGR_COMPILATIONS_COUNT),
 404                         Messages.getString(Messages.AGGR_COMPILATIONS_COUNT_DESC), JdkFilters.COMPILATION);
 405         public static final IAggregator<IQuantity, ?> LONGEST_COMPILATION = Aggregators.filter(Aggregators.max(DURATION),
 406                         JdkFilters.COMPILATION);
 407 
 408         public static final IAggregator<String, ?> DUMP_REASON = distinctAsString(JdkTypeIDs.DUMP_REASON,
 409                         JdkAttributes.DUMP_REASON);
 410 
 411         public static final IAggregator<IQuantity, ?> ADDRESSES_COUNT = Aggregators.countDistinct(
 412                         Messages.getString(Messages.AGGR_ADDRESSES_COUNT), Messages.getString(Messages.AGGR_ADDRESSES_COUNT_DESC),
 413                         JdkAttributes.MONITOR_ADDRESS);
 414         public static final IAggregator<IQuantity, ?> OLD_OBJECT_ADDRESSES_COUNT = Aggregators.countDistinct(
 415                         Messages.getString(Messages.AGGR_ADDRESSES_COUNT), Messages.getString(Messages.AGGR_ADDRESSES_COUNT_DESC),
 416                         JdkAttributes.OLD_OBJECT_ADDRESS);
 417 
 418         /**
 419          * Aggregator for getting the first value, ie. the value from the event with the first occurring
 420          * start time.
 421          *
 422          * @param attribute
 423          *            attribute to get value from
 424          * @return the value provided by the very first event
 425          */
 426         public static <V> IAggregator<V, ?> first(IAttribute<V> attribute) {
 427                 return new Aggregators.AdvancedMinAggregator<>(
 428                                 MessageFormat.format(Messages.getString(Messages.AGGR_FIRST_ATTRIBUTE), attribute.getName()),
 429                                 MessageFormat.format(Messages.getString(Messages.AGGR_FIRST_ATTRIBUTE_DESC), attribute.getName()),
 430                                 attribute, JfrAttributes.START_TIME);
 431         }
 432 
 433         /**
 434          * Aggregator for getting the last value, ie. the value from the event with the last occurring
 435          * end time.
 436          *
 437          * @param attribute
 438          *            attribute to get value from
 439          * @return the value provided by the very last event
 440          */
 441         public static <V> IAggregator<V, ?> last(IAttribute<V> attribute) {
 442                 return new Aggregators.AdvancedMaxAggregator<>(
 443                                 MessageFormat.format(Messages.getString(Messages.AGGR_LAST_ATTRIBUTE), attribute.getName()),
 444                                 MessageFormat.format(Messages.getString(Messages.AGGR_LAST_ATTRIBUTE_DESC), attribute.getName()),
 445                                 attribute, JfrAttributes.END_TIME);
 446         }
 447 
 448 }
--- EOF ---