001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.profiler;
018:
019: /**
020: * A ProfilerResult stores a collection of the lastest n ProfilerDatas
021: * for one pipeline.
022: *
023: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
024: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
025: * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
026: * @version CVS $Id: ProfilerResult.java 433543 2006-08-22 06:22:54Z crossley $
027: */
028: public class ProfilerResult {
029:
030: // URI of the request
031: private String uri;
032:
033: // Roles of the sitemap components
034: private String[] roles;
035:
036: // Sources of the sitemap components
037: private String[] sources;
038:
039: // Count of the ProfilerData entries
040: private int count = 0;
041:
042: // Environment information of each request.
043: private EnvironmentInfo[] latestEnvironmentInfo;
044:
045: // Total times of each request
046: private long[] totalTime;
047:
048: // Setup times of each component of the latest n-requests
049: private long[][] latestSetupTimes;
050:
051: // Processing times of each component of the latest n-requests
052: private long[][] latestProcessingTimes;
053:
054: // SAX fragments of eac component of the latest n-requests
055: private Object[][] latestFragments;
056:
057: public ProfilerResult(String uri, int latestResultsCount) {
058: this .uri = uri;
059: this .latestEnvironmentInfo = new EnvironmentInfo[(latestResultsCount > 0) ? latestResultsCount
060: : 5];
061: this .latestSetupTimes = new long[(latestResultsCount > 0) ? latestResultsCount
062: : 5][];
063: this .latestProcessingTimes = new long[(latestResultsCount > 0) ? latestResultsCount
064: : 5][];
065: this .totalTime = new long[(latestResultsCount > 0) ? latestResultsCount
066: : 5];
067: this .latestFragments = new Object[(latestResultsCount > 0) ? latestResultsCount
068: : 5][];
069: this .count = 0;
070: }
071:
072: /**
073: * Add a new profiler data from a request to the result.
074: */
075: public void addData(ProfilerData data) {
076: ProfilerData.Entry[] entries = data.getEntries();
077: synchronized (this ) {
078: if (roles == null || roles.length != entries.length) {
079: // Reinitialize arrays about the pipeline
080: roles = new String[entries.length];
081: sources = new String[entries.length];
082: for (int i = 0; i < entries.length; i++) {
083: roles[i] = entries[i].role;
084: sources[i] = entries[i].source;
085: }
086:
087: // Clear counter
088: this .count = 0;
089: }
090:
091: if (latestProcessingTimes != null) {
092: // move the current data
093: for (int i = latestProcessingTimes.length - 1; i > 0; i--) {
094: latestEnvironmentInfo[i] = latestEnvironmentInfo[i - 1];
095: totalTime[i] = totalTime[i - 1];
096: latestSetupTimes[i] = latestSetupTimes[i - 1];
097: latestProcessingTimes[i] = latestProcessingTimes[i - 1];
098: latestFragments[i] = latestFragments[i - 1];
099: }
100: latestEnvironmentInfo[0] = data.getEnvironmentInfo();
101: totalTime[0] = data.getTotalTime();
102:
103: latestSetupTimes[0] = new long[entries.length];
104: for (int i = 0; i < entries.length; i++)
105: this .latestSetupTimes[0][i] = entries[i].setup;
106:
107: latestProcessingTimes[0] = new long[entries.length];
108: for (int i = 0; i < entries.length; i++)
109: this .latestProcessingTimes[0][i] = entries[i].time;
110:
111: latestFragments[0] = new Object[entries.length];
112: for (int i = 0; i < entries.length; i++)
113: latestFragments[0][i] = entries[i].fragment;
114:
115: if (count < latestProcessingTimes.length)
116: count++;
117: }
118: }
119: }
120:
121: /**
122: * The URI of the request.
123: */
124: public String getURI() {
125: return uri;
126: }
127:
128: /**
129: * Roles of the sitemap components.
130: */
131: public String[] getRoles() {
132: return roles;
133: }
134:
135: /**
136: * Sources of the sitemap components.
137: */
138: public String[] getSources() {
139: return sources;
140: }
141:
142: /**
143: * Count of the ProfilerData entries
144: */
145: public int getCount() {
146: return count;
147: }
148:
149: /**
150: * Environment infomation of the latest n-requests
151: */
152: public EnvironmentInfo[] getLatestEnvironmentInfos() {
153: return latestEnvironmentInfo;
154: }
155:
156: /**
157: * Total times of each request.
158: */
159: public long[] getTotalTime() {
160: return totalTime;
161: }
162:
163: /**
164: * Setup times of each component of the latest n-requests
165: */
166: public long[][] getSetupTimes() {
167: return latestSetupTimes;
168: }
169:
170: /**
171: * Processing times of each component of the latest n-requests
172: */
173: public long[][] getProcessingTimes() {
174: return latestProcessingTimes;
175: }
176:
177: /**
178: * SAX fragment of each component of the latest n-requests
179: */
180: public Object[][] getSAXFragments() {
181: return latestFragments;
182: }
183: }
|