fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * CDDL HEADER START
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * The contents of this file are subject to the terms of the
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Common Development and Distribution License (the "License").
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * You may not use this file except in compliance with the License.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * See the License for the specific language governing permissions
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * and limitations under the License.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * When distributing Covered Code, include this CDDL HEADER in each
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * If applicable, add the following below this CDDL HEADER, with the
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * fields enclosed by brackets "[]" replaced with your own identifying
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * information: Portions Copyright [yyyy] [name of copyright owner]
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * CDDL HEADER END
e77b06d21580f630e0a7c437495ab283d3672828tomee * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Use is subject to license terms.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * ident "%Z%%M% %I% %E% SMI"
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * A snapshot of a DTrace aggregation. The name of an {@code
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Aggregation} instance matches the source declaration, for example
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @a[execname] = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * results in an {@code Aggregation} named "a" (the name does not
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * include the preceding {@code @}). For convenience, a single
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * aggregation can remain unnamed (multiple aggregations in the same D
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * program need distinct names). The unnamed aggregation results in an
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * {@code Aggregation} instance whose name is the empty string, for
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @[execname] = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * An aggregation can list more than one variable in square brackets in
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * order to accumulate a value for each unique combination, or {@link
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Tuple}. Each tuple instance is associated with its accumulated
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * {@link AggregationValue} in an {@link AggregationRecord}. For
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @counts[execname, probefunc, cpu] = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * results in an {@code Aggregation} named "counts" containing records
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * each pairing a {@link CountValue} to a three-element {@code Tuple}.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * It is also possible to omit the square brackets, for example
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @a = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * results in an {@code Aggregation} named "a" with only a single record
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * keyed to the empty tuple ({@link Tuple#EMPTY}).
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * For more information, see the <a
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * href=http://docs.sun.com/app/docs/doc/817-6223/6mlkidlh7?a=view>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <b>Aggregations</b></a> chapter of the <i>Solaris Dynamic Tracing
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Guide</i>. Also, the <a
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * href=http://docs.sun.com/app/docs/doc/817-6223/6mlkidlfv?a=view>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <b>Built-in Variables</b></a> section of the <b>Variables</b> chapter
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * describes variables like {@code execname}, {@code probefunc}, and
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * {@code cpu} useful for aggregating.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @see Aggregate
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @see PrintaRecord
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @author Tom Erickson
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomeepublic final class Aggregation implements Serializable {
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee static final long serialVersionUID = 2340811719178724026L;
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee BeanInfo info = Introspector.getBeanInfo(Aggregation.class);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee protected boolean
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee return ((newInstance != null) && (oldInstance != null) &&
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee d.setValue("persistenceDelegate", persistenceDelegate);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee /** @serial */
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee /** @serial */
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Package-level access, called by Aggregate
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee Aggregation(String aggregationName, long aggregationID)
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee name = Aggregate.filterUnnamedAggregationName(aggregationName);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Creates an aggregation with the given name, ID, and records.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Supports XML persistence.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @param aggregationName the name of this aggregation, empty string
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * if this aggregation is unnamed
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @param aggregationID ID generated from a sequence by the native
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * DTrace library
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @param aggregationRecords unordered collection of records
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * belonging to this aggregation
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @throws NullPointerException if the specified name or list of
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * records is {@code null}
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @throws IllegalArgumentException if any record has an empty
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * tuple, unless it is the only record in the given collection (only
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * a singleton generated by an aggregation without square brackets
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * uses {@link Tuple#EMPTY} as a key)
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @see #getRecord(Tuple key)
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee Aggregation(String aggregationName, long aggregationID,
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee name = Aggregate.filterUnnamedAggregationName(aggregationName);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // assumes map is not yet created
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee private void
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee int capacity = (int)(((float)records.size() * 3.0f) / 2.0f);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // avoid rehashing and optimize lookup; will never be modified
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee map = new HashMap <Tuple, AggregationRecord> (capacity, 1.0f);
91cfa10a8e55050a5103c4b2e83b0bf8d783a7cbtomee private final void
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee "allowed only in singleton aggregation");
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Gets the name of this aggregation.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return the name of this aggregation exactly as it appears in the
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * D program minus the preceding {@code @}, or an empty string if
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * the aggregation is unnamed, for example:
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @[execname] = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Gets the D compiler-generated ID of this aggregation.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return the D compiler-generated ID
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee public long
e77b06d21580f630e0a7c437495ab283d3672828tomee * Gets an unordered list of this aggregation's records. The list is
e77b06d21580f630e0a7c437495ab283d3672828tomee * sortable using {@link java.util.Collections#sort(List list,
e77b06d21580f630e0a7c437495ab283d3672828tomee * Comparator c)} with any user-defined ordering. Modifying the
e77b06d21580f630e0a7c437495ab283d3672828tomee * returned list has no effect on this aggregation. Supports XML
e77b06d21580f630e0a7c437495ab283d3672828tomee * persistence.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return a newly created list that copies this aggregation's
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * records by reference in no particular order
e77b06d21580f630e0a7c437495ab283d3672828tomee * @see Aggregate#getRecords()
e77b06d21580f630e0a7c437495ab283d3672828tomee * @see Aggregate#getOrderedRecords()
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Package level access, called by Aggregate and PrintaRecord.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @throws IllegalArgumentException if this aggregation already
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * contains a record with the same tuple key as the given record
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee throw new IllegalArgumentException("already contains a record " +
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Gets a read-only {@code Map} view of this aggregation.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return a read-only {@code Map} view of this aggregation
e77b06d21580f630e0a7c437495ab283d3672828tomee return Collections. <Tuple, AggregationRecord> unmodifiableMap(map);
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Compares the specified object with this aggregation for equality.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Defines equality as having equal names and equal records.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return {@code true} if and only if the specified object is an
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * {@code Aggregation} with the same name as this aggregation and
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * the {@code Map} views of both aggregations returned by {@link
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * #asMap()} are equal as defined by {@link
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * AbstractMap#equals(Object o) AbstractMap.equals()}
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee public boolean
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee if (o instanceof Aggregation) {
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee return false;
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Overridden to ensure that equal aggregations have equal hash
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Gets the record associated with the given key, or the singleton
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * record of an aggregation declared without square brackets if
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * {@code key} is {@code null} or empty.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @param key The record key, or an empty tuple (see {@link
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Tuple#EMPTY}) to obtain the value from a <i>singleton</i> (a
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * non-keyed instance with only a single value) generated from a
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * DTrace aggregation declarated without square brackets, for
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre> {@code @a = count();}</pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @return the record associated with the given key, or {@code null}
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * if no record in this aggregation is associated with the given key
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Serialize this {@code Aggregation} instance.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * @serialData Serialized fields are emitted, followed by a {@link
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * java.util.List} of {@link AggregationRecord} instances.
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee private void
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee private void
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // cannot cast to parametric type without compiler warning
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee List <AggregationRecord> records = (List)s.readObject();
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // load serialized form into private map as a defensive copy
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // Check class invariants (only after defensive copy)
91cfa10a8e55050a5103c4b2e83b0bf8d783a7cbtomee } catch (Exception e) {
4ae67516a1d5dc4a5dbc761762bad5b596647388tomee InvalidObjectException x = new InvalidObjectException(
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * Gets a string representation of this aggregation useful for
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * logging and not intended for display. The exact details of the
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * representation are unspecified and subject to change, but the
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * following format may be regarded as typical:
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * <pre><code>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * class-name[property1 = value1, property2 = value2]
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee * </code></pre>
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee // Sort by tuple so that equal aggregations have equal strings
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee Collections.sort(recordList, new Comparator <AggregationRecord> () {
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee public int compare(AggregationRecord r1, AggregationRecord r2) {
fb3fb4f3d76d55b64440afd0af72775dfad3bd1dtomee boolean first = true;