2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/Apackage org.opensolaris.os.dtrace;
2N/A
2N/Aimport java.util.*;
2N/A
2N/A/**
2N/A * Implementation detail used by {@link Consumer#getAggregate()}.
2N/A * Package level access.
2N/A */
2N/Aclass AggregateSpec {
2N/A private Set <String> includedAggregationNames;
2N/A private Set <String> clearedAggregationNames;
2N/A
2N/A AggregateSpec()
2N/A {
2N/A includedAggregationNames = new HashSet <String> ();
2N/A clearedAggregationNames = new HashSet <String> ();
2N/A }
2N/A
2N/A public boolean
2N/A isIncludeByDefault()
2N/A {
2N/A return (includedAggregationNames == null);
2N/A }
2N/A
2N/A public boolean
2N/A isClearByDefault()
2N/A {
2N/A return (clearedAggregationNames == null);
2N/A }
2N/A
2N/A public void
2N/A setIncludeByDefault(boolean include)
2N/A {
2N/A if (include) {
2N/A includedAggregationNames = null;
2N/A } else if (includedAggregationNames == null) {
2N/A includedAggregationNames = new HashSet <String> ();
2N/A }
2N/A }
2N/A
2N/A public void
2N/A setClearByDefault(boolean clear)
2N/A {
2N/A if (clear) {
2N/A clearedAggregationNames = null;
2N/A } else if (clearedAggregationNames == null) {
2N/A clearedAggregationNames = new HashSet <String> ();
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Specifies which aggregations to include in an aggregate snapshot.
2N/A * If none are specified, all aggregations are included. A snapshot
2N/A * is read-consistent across all included aggregations.
2N/A *
2N/A * @see Consumer#getAggregate(AggregateSpec spec)
2N/A */
2N/A public void
2N/A addIncludedAggregationName(String name)
2N/A {
2N/A if (includedAggregationNames == null) {
2N/A includedAggregationNames = new HashSet <String> ();
2N/A }
2N/A includedAggregationNames.add(
2N/A Aggregate.filterUnnamedAggregationName(name));
2N/A }
2N/A
2N/A /**
2N/A * Specifies which aggregations to clear after snapping the
2N/A * aggregate. If none are specified, no aggregations are cleared.
2N/A * <p>
2N/A * Aggregations are cleared immediately after they are snapped
2N/A * before any more data can be accumulated in order to prevent loss
2N/A * of data between snapshots.
2N/A *
2N/A * @see Consumer#getAggregate(AggregateSpec spec)
2N/A */
2N/A public void
2N/A addClearedAggregationName(String name)
2N/A {
2N/A if (clearedAggregationNames == null) {
2N/A clearedAggregationNames = new HashSet <String> ();
2N/A }
2N/A clearedAggregationNames.add(
2N/A Aggregate.filterUnnamedAggregationName(name));
2N/A }
2N/A
2N/A public Set <String>
2N/A getIncludedAggregationNames()
2N/A {
2N/A if (includedAggregationNames == null) {
2N/A return Collections. <String> emptySet();
2N/A }
2N/A return Collections. <String> unmodifiableSet(includedAggregationNames);
2N/A }
2N/A
2N/A public Set <String>
2N/A getClearedAggregationNames()
2N/A {
2N/A if (clearedAggregationNames == null) {
2N/A return Collections. <String> emptySet();
2N/A }
2N/A return Collections. <String> unmodifiableSet(clearedAggregationNames);
2N/A }
2N/A
2N/A // Called by native code
2N/A public boolean
2N/A isIncluded(String aggregationName)
2N/A {
2N/A return ((includedAggregationNames == null) ||
2N/A includedAggregationNames.contains(
2N/A Aggregate.filterUnnamedAggregationName(aggregationName)));
2N/A }
2N/A
2N/A // Called by native code
2N/A public boolean
2N/A isCleared(String aggregationName)
2N/A {
2N/A return ((clearedAggregationNames == null) ||
2N/A clearedAggregationNames.contains(
2N/A Aggregate.filterUnnamedAggregationName(aggregationName)));
2N/A }
2N/A
2N/A public String
2N/A toString()
2N/A {
2N/A StringBuilder buf = new StringBuilder();
2N/A buf.append(AggregateSpec.class.getName());
2N/A buf.append("[includedAggregationNames = ");
2N/A buf.append(Arrays.toString(getIncludedAggregationNames().toArray()));
2N/A buf.append(", clearedAggregationNames = ");
2N/A buf.append(Arrays.toString(getClearedAggregationNames().toArray()));
2N/A buf.append(", includeByDefault = ");
2N/A buf.append(isIncludeByDefault());
2N/A buf.append(", clearByDefault = ");
2N/A buf.append(isClearByDefault());
2N/A buf.append(']');
2N/A return buf.toString();
2N/A }
2N/A}