KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > profiler > ProfilerResult


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.profiler;
17
18
19
20 /**
21  * A ProfilerResult stores a collection of the lastest n ProfilerDatas
22  * for one pipeline.
23  *
24  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
25  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
26  * @author <a HREF="mailto:bruno@outerthought.org">Bruno Dumon</a>
27  * @version CVS $Id: ProfilerResult.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29 public class ProfilerResult {
30
31     // URI of the request
32
private String JavaDoc uri;
33
34     // Roles of the sitemap components
35
private String JavaDoc[] roles;
36
37     // Sources of the sitemap components
38
private String JavaDoc[] sources;
39
40     // Count of the ProfilerData entries
41
private int count = 0;
42
43     // Environment information of each request.
44
private EnvironmentInfo[] latestEnvironmentInfo;
45
46     // Total times of each request
47
private long[] totalTime;
48
49     // Setup times of each component of the latest n-requests
50
private long[][] latestSetupTimes;
51
52     // Processing times of each component of the latest n-requests
53
private long[][] latestProcessingTimes;
54
55     // SAX fragments of eac component of the latest n-requests
56
private Object JavaDoc[][] latestFragments;
57
58     public ProfilerResult(String JavaDoc uri, int latestResultsCount) {
59         this.uri = uri;
60         this.latestEnvironmentInfo = new EnvironmentInfo[(latestResultsCount>0)?latestResultsCount:5];
61         this.latestSetupTimes = new long[(latestResultsCount>0)?latestResultsCount:5][];
62         this.latestProcessingTimes = new long[(latestResultsCount>0)?latestResultsCount:5][];
63         this.totalTime = new long[(latestResultsCount>0)?latestResultsCount:5];
64         this.latestFragments = new Object JavaDoc[(latestResultsCount>0)?latestResultsCount:5][];
65         this.count = 0;
66     }
67
68     /**
69      * Add a new profiler data from a request to the result.
70      */

71     public void addData(ProfilerData data) {
72         ProfilerData.Entry[] entries = data.getEntries();
73         synchronized(this){
74             if(roles == null || roles.length != entries.length){
75                 // Reinitialize arrays about the pipeline
76
roles = new String JavaDoc[entries.length];
77                 sources = new String JavaDoc[entries.length];
78                 for(int i=0; i<entries.length; i++){
79                     roles[i] = entries[i].role;
80                     sources[i] = entries[i].source;
81                 }
82
83                 // Clear counter
84
this.count = 0;
85             }
86
87             if (latestProcessingTimes != null) {
88                 // move the current data
89
for (int i = latestProcessingTimes.length - 1; i > 0; i--) {
90                     latestEnvironmentInfo[i] = latestEnvironmentInfo[i - 1];
91                     totalTime[i] = totalTime[i - 1];
92                     latestSetupTimes[i] = latestSetupTimes[i - 1];
93                     latestProcessingTimes[i] = latestProcessingTimes[i - 1];
94                     latestFragments[i] = latestFragments[i - 1];
95                 }
96                 latestEnvironmentInfo[0] = data.getEnvironmentInfo();
97                 totalTime[0] = data.getTotalTime();
98
99                 latestSetupTimes[0] = new long[entries.length];
100                 for(int i=0; i<entries.length; i++)
101                     this.latestSetupTimes[0][i] = entries[i].setup;
102
103                 latestProcessingTimes[0] = new long[entries.length];
104                 for(int i=0; i<entries.length; i++)
105                     this.latestProcessingTimes[0][i] = entries[i].time;
106
107                 latestFragments[0] = new Object JavaDoc[entries.length];
108                 for(int i=0; i<entries.length; i++)
109                     latestFragments[0][i] = entries[i].fragment;
110
111                 if (count<latestProcessingTimes.length)
112                     count++;
113             }
114         }
115     }
116
117     /**
118      * The URI of the request.
119      */

120     public String JavaDoc getURI() {
121         return uri;
122     }
123
124     /**
125      * Roles of the sitemap components.
126      */

127     public String JavaDoc[] getRoles() {
128         return roles;
129     }
130
131     /**
132      * Sources of the sitemap components.
133      */

134     public String JavaDoc[] getSources() {
135         return sources;
136     }
137
138     /**
139      * Count of the ProfilerData entries
140      */

141     public int getCount() {
142         return count;
143     }
144
145     /**
146      * Environment infomation of the latest n-requests
147      */

148     public EnvironmentInfo[] getLatestEnvironmentInfos() {
149         return latestEnvironmentInfo;
150     }
151
152     /**
153      * Total times of each request.
154      */

155     public long[] getTotalTime() {
156         return totalTime;
157     }
158
159     /**
160      * Setup times of each component of the latest n-requests
161      */

162     public long[][] getSetupTimes() {
163         return latestSetupTimes;
164     }
165
166     /**
167      * Processing times of each component of the latest n-requests
168      */

169     public long[][] getProcessingTimes() {
170         return latestProcessingTimes;
171     }
172
173     /**
174      * SAX fragment of each component of the latest n-requests
175      */

176     public Object JavaDoc[][] getSAXFragments() {
177         return latestFragments;
178     }
179 }
180
Popular Tags