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.io.IOException; |
26 |
|
import java.lang.reflect.InvocationTargetException; |
27 |
|
import java.text.NumberFormat; |
28 |
|
import java.util.ArrayList; |
29 |
|
import java.util.List; |
30 |
|
import java.util.Set; |
31 |
|
|
32 |
|
import javax.servlet.ServletException; |
33 |
|
import javax.servlet.http.HttpServletRequest; |
34 |
|
import javax.servlet.http.HttpServletResponse; |
35 |
|
import javax.servlet.http.HttpSession; |
36 |
|
|
37 |
|
import net.sf.infrared.base.model.AggregateExecutionTime; |
38 |
|
import net.sf.infrared.base.model.AggregateOperationTree; |
39 |
|
import net.sf.infrared.base.model.ExecutionContext; |
40 |
|
import net.sf.infrared.base.util.Tree; |
41 |
|
import net.sf.infrared.base.util.TreeNode; |
42 |
|
import net.sf.infrared.web.formbean.LastInvocationTreeBean; |
43 |
|
import net.sf.infrared.web.formbean.SqlStatisticsFormBean; |
44 |
|
import net.sf.infrared.web.treecontrolmodel.NodeToStringConverter; |
45 |
|
import net.sf.infrared.web.treecontrolmodel.TreeFactoryImpl; |
46 |
|
import net.sf.infrared.web.util.DataFetchUtil; |
47 |
|
import net.sf.infrared.web.util.PerformanceDataSnapshot; |
48 |
|
import net.sf.infrared.web.util.SqlStatistics; |
49 |
|
import net.sf.infrared.web.util.ViewUtil; |
50 |
|
|
51 |
|
import org.apache.commons.beanutils.BeanUtils; |
52 |
|
import org.apache.struts.action.Action; |
53 |
|
import org.apache.struts.action.ActionForm; |
54 |
|
import org.apache.struts.action.ActionForward; |
55 |
|
import org.apache.struts.action.ActionMapping; |
56 |
|
|
57 |
|
public class PerfDataLastInvocationCallSeq extends Action { |
58 |
|
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, |
59 |
|
HttpServletResponse response) |
60 |
|
throws IOException, ServletException, IllegalAccessException, |
61 |
|
InvocationTargetException { |
62 |
|
|
63 |
|
HttpSession session = request.getSession(); |
64 |
|
|
65 |
|
final PerformanceDataSnapshot perfData = (PerformanceDataSnapshot) |
66 |
|
session.getAttribute("perfData");; |
67 |
|
|
68 |
|
List lastInvTreeList = perfData.getStats().getLastInvocations(); |
69 |
|
Tree [] lastInvocationTrees = new Tree[lastInvTreeList.size()]; |
70 |
|
lastInvTreeList.toArray(lastInvocationTrees); |
71 |
|
|
72 |
|
NodeToStringConverter nodeToStringConverter = new NodeToStringConverter() { |
73 |
|
public String toString(AggregateExecutionTime aggApiTime) { |
74 |
0 |
StringBuffer display = new StringBuffer(); |
75 |
0 |
display.append(aggApiTime.getContext().toString()) |
76 |
|
.append(" [ ") |
77 |
|
.append(" Total Time = ") |
78 |
|
.append(aggApiTime.getTotalInclusiveTime()) |
79 |
|
.append(" Exclusive Time = ") |
80 |
|
.append(aggApiTime.getTotalExclusiveTime()) |
81 |
|
.append(" Count = ") |
82 |
|
.append(aggApiTime.getExecutionCount()) |
83 |
|
.append(" ] "); |
84 |
0 |
return display.toString(); |
85 |
|
} |
86 |
|
|
87 |
|
public String getHref(AggregateExecutionTime apiTime) { |
88 |
0 |
return "/perfData_lastInvTrees.jsp"; |
89 |
|
} |
90 |
|
|
91 |
0 |
public boolean isContextRelative() { |
92 |
0 |
return true; |
93 |
|
} |
94 |
|
}; |
95 |
|
|
96 |
|
ArrayList lastInvBeans = new ArrayList(); |
97 |
|
ArrayList sqlStatsForAllTrees = new ArrayList(); |
98 |
|
|
99 |
|
for (int i = 0; i < lastInvocationTrees.length; i++) { |
100 |
|
String treeName = "InfraTree" + i; |
101 |
|
ArrayList sqlStatsList = new ArrayList(); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
AggregateOperationTree lastInvocationtree = new AggregateOperationTree(); |
106 |
|
lastInvocationtree.merge(lastInvocationTrees[i]); |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
TreeNode headNode = (TreeNode)lastInvocationtree.getAggregateTree().getRoot() |
111 |
|
.getChildren() |
112 |
|
.get(0); |
113 |
|
|
114 |
|
TreeFactoryImpl treeFactory = new TreeFactoryImpl(headNode, treeName, |
115 |
|
nodeToStringConverter); |
116 |
|
session.setAttribute(treeName, treeFactory); |
117 |
|
|
118 |
|
LastInvocationTreeBean treeBean = new LastInvocationTreeBean(headNode); |
119 |
|
|
120 |
|
|
121 |
|
SqlStatistics[] sqlStatistics = ViewUtil.getSqlStatistics(headNode); |
122 |
|
|
123 |
|
for (int j = 0; j < sqlStatistics.length; j++) { |
124 |
|
SqlStatisticsFormBean formBean = new SqlStatisticsFormBean(); |
125 |
|
BeanUtils.copyProperties(formBean, sqlStatistics[j]); |
126 |
|
sqlStatsList.add(formBean); |
127 |
|
} |
128 |
|
treeBean.setSqlStatsLength(new Integer(sqlStatistics.length).toString()); |
129 |
|
lastInvBeans.add(treeBean); |
130 |
|
sqlStatsForAllTrees.add(sqlStatsList); |
131 |
|
} |
132 |
|
|
133 |
|
session.setAttribute("lastInvBeanTree", lastInvBeans); |
134 |
|
session.setAttribute("sqlStats", sqlStatsForAllTrees); |
135 |
|
|
136 |
|
return mapping.findForward("continue"); |
137 |
|
} |
138 |
|
|
139 |
|
} |