summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorTom Erickson <tomee@eng.sun.com>2008-09-03 15:14:25 -0700
committerTom Erickson <tomee@eng.sun.com>2008-09-03 15:14:25 -0700
commit3e359d9c8f6757343a2958bb1e6e1cbbe9a657b8 (patch)
tree8794a66ed0b49bf8c98e2d57c4d5d6c4e8e4b064 /usr/src
parent1f713840d3b0fdc1eb54245ec133d1c87df73d13 (diff)
downloadillumos-joyent-3e359d9c8f6757343a2958bb1e6e1cbbe9a657b8.tar.gz
6737926 getAggregate() method fails to specify anonymous aggregation explicitly
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java252
-rw-r--r--usr/src/cmd/dtrace/test/tst/common/java_api/tst.GetAggregate.ksh36
-rw-r--r--usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/AggregateSpec.java18
-rw-r--r--usr/src/pkgdefs/SUNWdtrt/prototype_com3
4 files changed, 299 insertions, 10 deletions
diff --git a/usr/src/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java b/usr/src/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java
new file mode 100644
index 0000000000..e02df85824
--- /dev/null
+++ b/usr/src/cmd/dtrace/test/tst/common/java_api/src/TestGetAggregate.java
@@ -0,0 +1,252 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+import org.opensolaris.os.dtrace.*;
+import java.util.*;
+
+/**
+ * Assert getAggregate() can explicitly specify the anonymous aggregation.
+ */
+public class TestGetAggregate {
+ static final String programString =
+ "profile:::tick-50ms" +
+ "{" +
+ " @ = count();" +
+ " @a = count();" +
+ "}";
+
+ static final String ANONYMOUS_AGGREGATION = "";
+ static final int TICK = 50;
+ static final int EXPECTED_TICKS = 3;
+ static final int INTERVALS = 4;
+
+ static void
+ testIncluded(Consumer consumer, String ... aggregationNames)
+ throws DTraceException, InterruptedException
+ {
+ Aggregate aggregate;
+ Set <String> included = new HashSet <String> ();
+ int n = 1;
+
+ for (String name : aggregationNames) {
+ included.add(name);
+ }
+
+ // Wait up to a full second to obtain aggregate data. Without a
+ // time limit, we'll loop forever if no aggregation was
+ // successfully included.
+ do {
+ Thread.sleep(TICK);
+ aggregate = consumer.getAggregate(included, null);
+ } while (aggregate.asMap().isEmpty() && n++ < (1000 / TICK));
+
+ for (String name : included) {
+ if (aggregate.getAggregation(name) == null) {
+ throw new IllegalStateException("@" + name +
+ " was explicitly included but did not appear " +
+ "in the aggregate");
+ }
+ }
+ for (Aggregation a : aggregate.getAggregations()) {
+ if (!included.contains(a.getName())) {
+ throw new IllegalStateException("@" + a.getName() +
+ " was not explicitly included but appeared " +
+ "in the aggregate anyway");
+ }
+ }
+
+ if (!consumer.isRunning()) {
+ throw new IllegalStateException("consumer exited");
+ }
+ }
+
+ static void
+ testCleared(Consumer consumer, String ... aggregationNames)
+ throws DTraceException, InterruptedException
+ {
+ Aggregate aggregate;
+ AggregationRecord rec;
+ long value;
+ Long firstValue;
+ int n = 1;
+ Map <String, Long> firstValues = new HashMap <String, Long> ();
+ Set <String> cleared = new HashSet <String> ();
+
+ for (String name : aggregationNames) {
+ cleared.add(name);
+ }
+
+ do {
+ Thread.sleep(TICK);
+ aggregate = consumer.getAggregate(null, cleared);
+ } while (aggregate.asMap().isEmpty() && n++ < (1000 / TICK));
+ n = 1;
+
+ do {
+ Thread.sleep(TICK * EXPECTED_TICKS);
+ aggregate = consumer.getAggregate(null, cleared);
+
+ for (Aggregation a : aggregate.getAggregations()) {
+ if (!firstValues.containsKey(a.getName())) {
+ rec = a.getRecord(Tuple.EMPTY);
+ value = rec.getValue().getValue().longValue();
+ firstValues.put(a.getName(), value);
+ }
+ }
+ } while (consumer.isRunning() && n++ < INTERVALS);
+
+ for (Aggregation a : aggregate.getAggregations()) {
+ rec = a.getRecord(Tuple.EMPTY);
+ value = rec.getValue().getValue().longValue();
+ firstValue = firstValues.get(a.getName());
+
+ if (cleared.contains(a.getName())) {
+ // last value should be about the same as first value
+ if (value > (firstValue * 2)) {
+ throw new IllegalStateException(
+ "@" + a.getName() + " should have " +
+ "been cleared but instead grew from " +
+ firstValue + " to " + value);
+ }
+ } else {
+ // last value should be about (INTERVALS * firstValue)
+ if (value < (firstValue * 2)) {
+ throw new IllegalStateException(
+ "@" + a.getName() + " should have " +
+ "accumulated a running total but " +
+ "instead went from " +
+ firstValue + " to " + value);
+ }
+ }
+ }
+
+ if (!consumer.isRunning()) {
+ throw new IllegalStateException("consumer exited");
+ }
+ }
+
+ static Integer includedStatus;
+ static Integer clearedStatus;
+
+ static void
+ startIncludedTest()
+ {
+ final Consumer consumer = new LocalConsumer();
+ consumer.addConsumerListener(new ConsumerAdapter() {
+ public void consumerStarted(ConsumerEvent e) {
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ testIncluded(consumer, ANONYMOUS_AGGREGATION);
+ includedStatus = 0;
+ } catch (Exception e) {
+ includedStatus = 1;
+ e.printStackTrace();
+ } finally {
+ consumer.abort();
+ }
+ }
+ }).start();
+ }
+ });
+
+ try {
+ consumer.open();
+ consumer.setOption(Option.aggrate, Option.millis(TICK));
+ consumer.compile(programString);
+ consumer.enable();
+ consumer.go();
+ } catch (Exception e) {
+ includedStatus = 1;
+ e.printStackTrace();
+ }
+ }
+
+ static void
+ startClearedTest()
+ {
+ final Consumer consumer = new LocalConsumer();
+ consumer.addConsumerListener(new ConsumerAdapter() {
+ public void consumerStarted(ConsumerEvent e) {
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ testCleared(consumer, ANONYMOUS_AGGREGATION);
+ clearedStatus = 0;
+ } catch (Exception e) {
+ clearedStatus = 1;
+ e.printStackTrace();
+ } finally {
+ consumer.abort();
+ }
+ }
+ }).start();
+ }
+ });
+
+ try {
+ consumer.open();
+ consumer.setOption(Option.aggrate, Option.millis(TICK));
+ consumer.compile(programString);
+ consumer.enable();
+ consumer.go();
+ } catch (Exception e) {
+ clearedStatus = 1;
+ e.printStackTrace();
+ }
+ }
+
+ public static void
+ main(String[] args)
+ {
+ startIncludedTest();
+
+ do {
+ try {
+ Thread.sleep(TICK);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } while (includedStatus == null);
+
+ startClearedTest();
+
+ do {
+ try {
+ Thread.sleep(TICK);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } while (clearedStatus == null);
+
+ if (includedStatus != 0 || clearedStatus != 0) {
+ System.out.println("Failure");
+ System.exit(1);
+ }
+
+ System.out.println("Success");
+ }
+}
diff --git a/usr/src/cmd/dtrace/test/tst/common/java_api/tst.GetAggregate.ksh b/usr/src/cmd/dtrace/test/tst/common/java_api/tst.GetAggregate.ksh
new file mode 100644
index 0000000000..2fdd5a9eac
--- /dev/null
+++ b/usr/src/cmd/dtrace/test/tst/common/java_api/tst.GetAggregate.ksh
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+############################################################################
+# ASSERTION:
+# getAggregate() can explicitly specify the anonymous aggregation
+#
+# SECTION: Java API
+#
+############################################################################
+
+java -cp test.jar TestGetAggregate
diff --git a/usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/AggregateSpec.java b/usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/AggregateSpec.java
index 3617ac9ea4..3c1f37b923 100644
--- a/usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/AggregateSpec.java
+++ b/usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/AggregateSpec.java
@@ -22,8 +22,6 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
- *
- * ident "%Z%%M% %I% %E% SMI"
*/
package org.opensolaris.os.dtrace;
@@ -32,8 +30,6 @@ import java.util.*;
/**
* Implementation detail used by {@link Consumer#getAggregate()}.
* Package level access.
- *
- * @author Tom Erickson
*/
class AggregateSpec {
private Set <String> includedAggregationNames;
@@ -90,7 +86,8 @@ class AggregateSpec {
if (includedAggregationNames == null) {
includedAggregationNames = new HashSet <String> ();
}
- includedAggregationNames.add(name);
+ includedAggregationNames.add(
+ Aggregate.filterUnnamedAggregationName(name));
}
/**
@@ -109,7 +106,8 @@ class AggregateSpec {
if (clearedAggregationNames == null) {
clearedAggregationNames = new HashSet <String> ();
}
- clearedAggregationNames.add(name);
+ clearedAggregationNames.add(
+ Aggregate.filterUnnamedAggregationName(name));
}
public Set <String>
@@ -130,18 +128,22 @@ class AggregateSpec {
return Collections. <String> unmodifiableSet(clearedAggregationNames);
}
+ // Called by native code
public boolean
isIncluded(String aggregationName)
{
return ((includedAggregationNames == null) ||
- includedAggregationNames.contains(aggregationName));
+ includedAggregationNames.contains(
+ Aggregate.filterUnnamedAggregationName(aggregationName)));
}
+ // Called by native code
public boolean
isCleared(String aggregationName)
{
return ((clearedAggregationNames == null) ||
- clearedAggregationNames.contains(aggregationName));
+ clearedAggregationNames.contains(
+ Aggregate.filterUnnamedAggregationName(aggregationName)));
}
public String
diff --git a/usr/src/pkgdefs/SUNWdtrt/prototype_com b/usr/src/pkgdefs/SUNWdtrt/prototype_com
index fee3c8f36f..6cdbe3d4e3 100644
--- a/usr/src/pkgdefs/SUNWdtrt/prototype_com
+++ b/usr/src/pkgdefs/SUNWdtrt/prototype_com
@@ -23,8 +23,6 @@
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# ident "%Z%%M% %I% %E% SMI"
-#
i pkginfo
i copyright
i depend
@@ -1473,3 +1471,4 @@ f none SUNWdtrt/tst/common/java_api/tst.MaxConsumers.ksh 0444 root bin
f none SUNWdtrt/tst/common/java_api/tst.MaxConsumers.ksh.out 0444 root bin
f none SUNWdtrt/tst/common/java_api/tst.Drop.ksh 0444 root bin
f none SUNWdtrt/tst/common/java_api/tst.Drop.ksh.out 0444 root bin
+f none SUNWdtrt/tst/common/java_api/tst.GetAggregate.ksh 0444 root bin