001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)METimestamps.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging.stats;
030:
031: import com.sun.jbi.messaging.MessageExchangeProxy;
032:
033: import javax.jbi.messaging.ExchangeStatus;
034:
035: import com.sun.jbi.messaging.RegisteredEndpoint;
036:
037: import java.net.URI;
038:
039: import javax.xml.namespace.QName;
040:
041: /** This is used to record a sequence of timestamps and the associated tag.
042: * Used by the NMR performance monitoring system to capture timings information along
043: * the primary send()->accept() codepaths.
044: *
045: * @author Sun Microsystems, Inc.
046: */
047: public class METimestamps {
048: private static final int STAMP_COUNT = 12;
049:
050: private int mIndex;
051: private long mStamps[];
052: private byte mTags[];
053: public long mConsumerTime;
054: public long mProviderTime;
055: public long mNMRTime;
056: public long mConsumerChannelTime;
057: public long mProviderChannelTime;
058: public long mResponseTime;
059: public long mStatusTime;
060:
061: private static String mStrings[] = { "???", "Csend", "Pqueue",
062: "Paccept", "Psend", "Cqueue", "Caccept" };
063: public static final byte TAG_CSEND = 1;
064: public static final byte TAG_PQUEUE = 2;
065: public static final byte TAG_PACCEPT = 3;
066: public static final byte TAG_PSEND = 4;
067: public static final byte TAG_CQUEUE = 5;
068: public static final byte TAG_CACCEPT = 6;
069:
070: public METimestamps() {
071: mStamps = new long[STAMP_COUNT + 1];
072: mTags = new byte[STAMP_COUNT + 1];
073: }
074:
075: public void capture(byte tag) {
076: if (mIndex < STAMP_COUNT) {
077: mStamps[mIndex] = System.nanoTime();
078: mTags[mIndex] = tag;
079: mIndex++;
080: }
081: }
082:
083: public String toString() {
084: StringBuffer sb = new StringBuffer();
085: if (mStamps != null) {
086: sb.append("Timestamps(" + mIndex + "): ");
087: for (int i = 0; i < mIndex; i++) {
088: sb.append(mStrings[(mTags[i] <= TAG_CACCEPT) ? mTags[i]
089: : 0]);
090: sb.append("(");
091: sb
092: .append(i == 0 ? mStamps[0] : mStamps[i]
093: - mStamps[0]);
094: sb.append(")");
095: }
096: } else {
097: sb.append("Timing: Consumer: " + mConsumerTime);
098: sb.append(" +Channel: " + mConsumerChannelTime);
099: sb.append(" Provider: " + mProviderTime);
100: sb.append(" +Channel: " + mProviderChannelTime);
101: sb.append(" NMR: " + mNMRTime);
102: sb.append(" Response: " + mResponseTime);
103: sb.append(" Status: " + mStatusTime);
104: }
105:
106: return (sb.toString());
107: }
108:
109: public void compute() {
110: int statusStart = 0;
111: boolean response = false;
112:
113: for (int i = 0; i < mIndex; i++) {
114: if ((mTags[i] == TAG_CSEND && mTags[i + 1] == TAG_PQUEUE)
115: || (mTags[i] == TAG_PSEND && mTags[i + 1] == TAG_CQUEUE)) {
116: mNMRTime += mStamps[i + 1] - mStamps[i];
117: } else if (mTags[i] == TAG_PQUEUE
118: && mTags[i + 1] == TAG_PACCEPT) {
119: mProviderChannelTime += mStamps[i + 1] - mStamps[i];
120: } else if (mTags[i] == TAG_PACCEPT) {
121: if (mTags[i + 1] == TAG_PSEND) {
122: mProviderTime += mStamps[i + 1] - mStamps[i];
123: }
124: if (statusStart != 0) {
125: mStatusTime = mStamps[i] - mStamps[statusStart];
126: }
127: } else if (mTags[i] == TAG_CACCEPT) {
128: if (mTags[i + 1] == TAG_CSEND) {
129: mConsumerTime += mStamps[i + 1] - mStamps[i];
130: }
131: if (!response) {
132: mResponseTime += mStamps[i] - mStamps[0];
133: response = true;
134: }
135: } else if (mTags[i] == TAG_CQUEUE
136: && mTags[i + 1] == TAG_CACCEPT) {
137: mConsumerChannelTime += mStamps[i + 1] - mStamps[i];
138: }
139: if (mTags[i] == TAG_PSEND) {
140: statusStart = i;
141: }
142: }
143: mTags = null;
144: mStamps = null;
145: }
146: }
|