1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
package net.sf.infrared.web.action; |
24 |
|
|
25 |
|
import java.lang.reflect.InvocationTargetException; |
26 |
|
import java.net.URLEncoder; |
27 |
|
import java.text.NumberFormat; |
28 |
|
import java.util.ArrayList; |
29 |
|
import java.util.Set; |
30 |
|
|
31 |
|
import javax.servlet.http.HttpServletRequest; |
32 |
|
import javax.servlet.http.HttpServletResponse; |
33 |
|
import javax.servlet.http.HttpSession; |
34 |
|
|
35 |
|
import net.sf.infrared.base.model.AggregateExecutionTime; |
36 |
|
import net.sf.infrared.base.model.AggregateOperationTree; |
37 |
|
import net.sf.infrared.base.model.ExecutionContext; |
38 |
|
import net.sf.infrared.base.util.TreeNode; |
39 |
|
import net.sf.infrared.web.formbean.AggrExecTimeFormBean; |
40 |
|
import net.sf.infrared.web.formbean.SqlStatisticsFormBean; |
41 |
|
import net.sf.infrared.web.treecontrolmodel.NodeToStringConverter; |
42 |
|
import net.sf.infrared.web.treecontrolmodel.TreeFactoryImpl; |
43 |
|
import net.sf.infrared.web.util.DataFetchUtil; |
44 |
|
import net.sf.infrared.web.util.PerformanceDataSnapshot; |
45 |
|
import net.sf.infrared.web.util.SqlStatistics; |
46 |
|
import net.sf.infrared.web.util.TreeUtil; |
47 |
|
import net.sf.infrared.web.util.ViewUtil; |
48 |
|
import net.sf.jsptree.tree.TreeFactory; |
49 |
|
|
50 |
|
import org.apache.commons.beanutils.BeanUtils; |
51 |
|
import org.apache.struts.action.Action; |
52 |
|
import org.apache.struts.action.ActionForm; |
53 |
|
import org.apache.struts.action.ActionForward; |
54 |
|
import org.apache.struts.action.ActionMapping; |
55 |
|
|
56 |
|
public class PerfDataCallTracesAction extends Action { |
57 |
|
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
58 |
|
HttpServletResponse response) |
59 |
|
throws IllegalAccessException, InvocationTargetException { |
60 |
|
HttpSession session = request.getSession(); |
61 |
|
|
62 |
|
TreeFactory treeFactory = null; |
63 |
|
String apiName = request.getParameter("api"); |
64 |
|
if (apiName != null) { |
65 |
|
session.setAttribute("api", apiName); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
String actualLayerName = request.getParameter("layerName"); |
71 |
|
if(actualLayerName != null){ |
72 |
|
session.setAttribute("layerName", actualLayerName); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
String className = request.getParameter("ctx"); |
77 |
|
|
78 |
|
if(className != null){ |
79 |
|
session.setAttribute("ctx", className); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
String type = request.getParameter("type"); |
87 |
|
if (type != null) { |
88 |
|
session.setAttribute("type", type); |
89 |
|
} |
90 |
|
|
91 |
|
final PerformanceDataSnapshot perData = |
92 |
|
(PerformanceDataSnapshot) session.getAttribute("perfData"); |
93 |
|
final String layerType = (String)session.getAttribute("layerType"); |
94 |
|
|
95 |
|
AggregateOperationTree aggrOptree = perData.getStats().getTree(); |
96 |
|
String hierarchicalLayerName = null; |
97 |
|
if(layerType.equals("hier")){ |
98 |
|
hierarchicalLayerName = type; |
99 |
|
} |
100 |
|
TreeNode mergedHead = TreeUtil.getMergedExecutionContextTreeNode(aggrOptree, apiName, |
101 |
|
actualLayerName, className, hierarchicalLayerName); |
102 |
|
|
103 |
|
if(mergedHead != null) { |
104 |
|
|
105 |
|
final long OVERALL_TIME = |
106 |
|
((AggregateExecutionTime)mergedHead.getValue()).getTotalInclusiveTime(); |
107 |
|
final NumberFormat nf = NumberFormat.getInstance(); |
108 |
|
nf.setMaximumFractionDigits(2); |
109 |
|
|
110 |
|
|
111 |
|
NodeToStringConverter nodeToStringConverterMergedTree = new NodeToStringConverter() { |
112 |
|
public String toString(AggregateExecutionTime aggApiTime) { |
113 |
0 |
StringBuffer display = new StringBuffer(); |
114 |
0 |
if(OVERALL_TIME == 0){ |
115 |
0 |
display.append(aggApiTime.getContext().toString()) |
116 |
|
.append(" [ ") |
117 |
|
.append(" Total Time = ") |
118 |
|
.append(aggApiTime.getTotalInclusiveTime()) |
119 |
|
.append(" Exclusive Time = ") |
120 |
|
.append(aggApiTime.getTotalExclusiveTime()) |
121 |
|
.append(" Count = ") |
122 |
|
.append(aggApiTime.getExecutionCount()) |
123 |
|
.append(" ] "); |
124 |
|
} |
125 |
|
else{ |
126 |
0 |
display.append(aggApiTime.getContext().toString()) |
127 |
|
.append(" [ ") |
128 |
|
.append(nf.format((aggApiTime.getTotalInclusiveTime() * 100.0) |
129 |
|
/ OVERALL_TIME)) |
130 |
|
.append("% -") |
131 |
|
.append(" Total Time = ") |
132 |
|
.append(aggApiTime.getTotalInclusiveTime()) |
133 |
|
.append(" Exclusive Time = ") |
134 |
|
.append(aggApiTime.getTotalExclusiveTime()) |
135 |
|
.append(" Count = ") |
136 |
|
.append(aggApiTime.getExecutionCount()) |
137 |
|
.append(" ] "); |
138 |
|
|
139 |
|
} |
140 |
0 |
return display.toString(); |
141 |
|
} |
142 |
|
|
143 |
|
public String getHref(AggregateExecutionTime apiTime) { |
144 |
0 |
ExecutionContext ctx = apiTime.getContext(); |
145 |
0 |
String name = ctx.getName(); |
146 |
0 |
String layer = ctx.getLayer(); |
147 |
0 |
String layerName =""; |
148 |
0 |
String temp = null; |
149 |
0 |
if(layerType.equals("abs")){ |
150 |
0 |
layerName = ctx.getLayer(); |
151 |
|
} |
152 |
0 |
else if(layerType.equals("hier")){ |
153 |
0 |
layerName = apiTime.getLayerName(); |
154 |
|
} |
155 |
|
|
156 |
|
try{ |
157 |
0 |
temp = "perfData_apiSumm_callTracesAction.do?" + "api="+ URLEncoder.encode(name, "UTF-8") + |
158 |
|
"&type="+ layerName + |
159 |
|
"&ctx="+ ctx.getClass().getName()+ |
160 |
|
"&layerName="+ layer; |
161 |
0 |
}catch (Exception e) { |
162 |
|
|
163 |
0 |
e.printStackTrace(); |
164 |
0 |
} |
165 |
0 |
return temp; |
166 |
|
} |
167 |
|
|
168 |
0 |
public boolean isContextRelative() { |
169 |
0 |
return false; |
170 |
|
} |
171 |
|
}; |
172 |
|
|
173 |
|
String tree = "InfraTree"; |
174 |
|
treeFactory = new TreeFactoryImpl(mergedHead, tree, nodeToStringConverterMergedTree); |
175 |
|
} |
176 |
|
|
177 |
|
AggregateExecutionTime[] mergedTreeJdbcSummaries = new AggregateExecutionTime[0]; |
178 |
|
SqlStatistics[] mergedTreeSqlStatistics = new SqlStatistics[0]; |
179 |
|
|
180 |
|
|
181 |
|
if (mergedHead != null) { |
182 |
|
mergedTreeJdbcSummaries = ViewUtil.getJDBCSummary(mergedHead); |
183 |
|
mergedTreeSqlStatistics = ViewUtil.getSqlStatistics(mergedHead); |
184 |
|
} |
185 |
|
|
186 |
|
ArrayList jdbcSummaries = new ArrayList(); |
187 |
|
|
188 |
|
for (int i = 0; i < mergedTreeJdbcSummaries.length; i++) { |
189 |
|
AggrExecTimeFormBean formBean = new AggrExecTimeFormBean(); |
190 |
|
BeanUtils.copyProperties(formBean, mergedTreeJdbcSummaries[i]); |
191 |
|
jdbcSummaries.add(formBean); |
192 |
|
} |
193 |
|
|
194 |
|
ArrayList sqlStatisticsByExec = new ArrayList(); |
195 |
|
int n = 5; |
196 |
|
SqlStatistics[] topNQueriesByExecution = |
197 |
|
ViewUtil.getTopNQueriesByExecutionTime(mergedTreeSqlStatistics, n); |
198 |
|
|
199 |
|
for (int i = 0; i < topNQueriesByExecution.length; i++) { |
200 |
|
SqlStatisticsFormBean formBean = new SqlStatisticsFormBean(); |
201 |
|
BeanUtils.copyProperties(formBean, topNQueriesByExecution[i]); |
202 |
|
sqlStatisticsByExec.add(formBean); |
203 |
|
} |
204 |
|
|
205 |
|
ArrayList sqlStatisticsByCount = new ArrayList(); |
206 |
|
SqlStatistics[] topNQueriesByCount = |
207 |
|
ViewUtil.getTopNQueriesByCount(mergedTreeSqlStatistics, n); |
208 |
|
|
209 |
|
for (int i = 0; i < topNQueriesByCount.length; i++) { |
210 |
|
SqlStatisticsFormBean formBean = new SqlStatisticsFormBean(); |
211 |
|
BeanUtils.copyProperties(formBean, topNQueriesByCount[i]); |
212 |
|
sqlStatisticsByCount.add(formBean); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
session.setAttribute("mergedHead", mergedHead); |
220 |
|
session.setAttribute("jdbcSummaries", jdbcSummaries); |
221 |
|
session.setAttribute("sqlStatisticsByExec", sqlStatisticsByExec); |
222 |
|
session.setAttribute("sqlStatisticsByCount", sqlStatisticsByCount); |
223 |
|
|
224 |
|
session.setAttribute("treeFactory", treeFactory); |
225 |
|
return mapping.findForward("repeat"); |
226 |
|
} |
227 |
|
|
228 |
|
} |