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.util; |
24 |
|
|
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.Map; |
27 |
|
import java.util.Set; |
28 |
|
|
29 |
|
import net.sf.infrared.aspects.jdbc.SqlExecuteContext; |
30 |
|
import net.sf.infrared.aspects.jdbc.SqlPrepareContext; |
31 |
|
import net.sf.infrared.base.model.AggregateExecutionTime; |
32 |
|
import net.sf.infrared.base.model.ApplicationStatistics; |
33 |
|
import net.sf.infrared.base.model.ExecutionContext; |
34 |
|
import net.sf.infrared.base.model.StatisticsSnapshot; |
35 |
|
|
36 |
0 |
public class PerformanceDataSnapshot { |
37 |
|
|
38 |
|
|
39 |
|
private StatisticsSnapshot stats; |
40 |
|
private Set applicationNames; |
41 |
|
private Set instanceNames; |
42 |
|
|
43 |
|
public Set getApplicationNames() { |
44 |
0 |
return applicationNames; |
45 |
|
} |
46 |
|
public void setApplicationNames(Set applicationNames) { |
47 |
0 |
this.applicationNames = applicationNames; |
48 |
0 |
} |
49 |
|
public Set getInstanceNames() { |
50 |
0 |
return instanceNames; |
51 |
|
} |
52 |
|
public void setInstanceNames(Set instanceNames) { |
53 |
0 |
this.instanceNames = instanceNames; |
54 |
0 |
} |
55 |
|
|
56 |
|
public StatisticsSnapshot getStats() { |
57 |
0 |
return stats; |
58 |
|
} |
59 |
|
|
60 |
|
public void setStats(StatisticsSnapshot stats) { |
61 |
0 |
this.stats = stats; |
62 |
0 |
} |
63 |
|
|
64 |
|
public SqlStatistics[] getSqlStatistics(){ |
65 |
0 |
Map sqlStatsMap = new HashMap(); |
66 |
|
SqlStatistics sqlStats; |
67 |
0 |
String[] layers = stats.getHierarchicalLayers(); |
68 |
0 |
for (int i = 0; i < layers.length; i++) { |
69 |
0 |
String layer = layers[i]; |
70 |
0 |
if (! layer.endsWith("SQL")) { |
71 |
0 |
continue; |
72 |
|
} |
73 |
0 |
AggregateExecutionTime[] sqlTimes = stats.getExecutionsInHierarchicalLayer(layer); |
74 |
0 |
for (int j = 0; j < sqlTimes.length; j++) { |
75 |
0 |
AggregateExecutionTime aet = (AggregateExecutionTime) sqlTimes[j]; |
76 |
0 |
ExecutionContext ctx = aet.getContext(); |
77 |
|
|
78 |
0 |
if (ctx instanceof SqlPrepareContext) { |
79 |
0 |
String sql = ctx.getName(); |
80 |
0 |
sqlStats = getSqlStatsFromMap(sqlStatsMap, sql); |
81 |
0 |
sqlStats.mergePrepareTime(aet); |
82 |
0 |
} else if(ctx instanceof SqlExecuteContext) { |
83 |
0 |
String sql = ctx.getName(); |
84 |
0 |
sqlStats = getSqlStatsFromMap(sqlStatsMap, sql); |
85 |
0 |
sqlStats.mergeExecuteTime(aet); |
86 |
|
} |
87 |
|
} |
88 |
|
} |
89 |
0 |
return (SqlStatistics[]) sqlStatsMap.values().toArray(new SqlStatistics[0]); |
90 |
|
} |
91 |
|
|
92 |
|
public SqlStatistics[] getSqlStatisticsForLayer(String layer, String layerType){ |
93 |
|
|
94 |
0 |
Map sqlStatsMap = new HashMap(); |
95 |
|
SqlStatistics sqlStats; |
96 |
0 |
AggregateExecutionTime[] sqlTimes = null; |
97 |
0 |
if(layerType.equals("hier")){ |
98 |
0 |
sqlTimes = stats.getExecutionsInHierarchicalLayer(layer); |
99 |
|
} |
100 |
0 |
else if(layerType.equals("abs")){ |
101 |
0 |
sqlTimes = stats.getExecutionsInAbsoluteLayer(layer); |
102 |
|
} |
103 |
|
|
104 |
0 |
for (int j = 0; j < sqlTimes.length; j++) { |
105 |
0 |
AggregateExecutionTime aet = (AggregateExecutionTime) sqlTimes[j]; |
106 |
0 |
ExecutionContext ctx = aet.getContext(); |
107 |
|
|
108 |
0 |
if (ctx instanceof SqlPrepareContext) { |
109 |
0 |
String sql = ctx.getName(); |
110 |
0 |
sqlStats = getSqlStatsFromMap(sqlStatsMap, sql); |
111 |
0 |
sqlStats.mergePrepareTime(aet); |
112 |
|
} |
113 |
0 |
else if(ctx instanceof SqlExecuteContext) { |
114 |
0 |
String sql = ctx.getName(); |
115 |
0 |
sqlStats = getSqlStatsFromMap(sqlStatsMap, sql); |
116 |
0 |
sqlStats.mergeExecuteTime(aet); |
117 |
|
} |
118 |
|
} |
119 |
0 |
return (SqlStatistics[]) sqlStatsMap.values().toArray(new SqlStatistics[0]); |
120 |
|
} |
121 |
|
|
122 |
|
public SqlStatistics getSqlStatsFromMap(Map sqlStatsMap, String sql){ |
123 |
|
SqlStatistics stats; |
124 |
0 |
if(sqlStatsMap.get(sql) == null){ |
125 |
0 |
stats = new SqlStatistics(); |
126 |
0 |
sqlStatsMap.put(sql, stats); |
127 |
|
} |
128 |
|
else{ |
129 |
0 |
stats = (SqlStatistics)sqlStatsMap.get(sql); |
130 |
|
} |
131 |
0 |
return stats; |
132 |
|
} |
133 |
|
} |