1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.monitor.api; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Date; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.Iterator; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 42 |
Complexity Density: 0.47 |
|
33 |
|
public class MonitorData |
34 |
|
{ |
35 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(MonitorData.class); |
36 |
|
|
37 |
|
private URL url; |
38 |
|
|
39 |
|
private String wikiPage; |
40 |
|
|
41 |
|
private String action; |
42 |
|
|
43 |
|
private String threadName; |
44 |
|
|
45 |
|
private Date startTime; |
46 |
|
|
47 |
|
private Date endTime; |
48 |
|
|
49 |
|
private Map<String, MonitorTimer> timers = new HashMap<>(); |
50 |
|
|
51 |
|
private Map<String, MonitorTimerSummary> timerSummaries = new HashMap<>(); |
52 |
|
|
53 |
|
private List<MonitorTimer> timerList = new ArrayList<>(); |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
55 |
0 |
public MonitorData(String wikiPage, String action, URL url, String threadName)... |
56 |
|
{ |
57 |
0 |
this.setWikiPage(wikiPage); |
58 |
0 |
this.setURL(url); |
59 |
0 |
this.setThreadName(threadName); |
60 |
0 |
this.setStartTime(new Date()); |
61 |
0 |
this.setAction(action); |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
64 |
0 |
public void startRequest(String page, URL url)... |
65 |
|
{ |
66 |
0 |
setWikiPage(page); |
67 |
0 |
setURL(url); |
68 |
0 |
setStartTime(new Date()); |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
public void endRequest()... |
72 |
|
{ |
73 |
0 |
endRequest(true); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
76 |
0 |
public void endRequest(boolean normal)... |
77 |
|
{ |
78 |
0 |
setEndTime(new Date()); |
79 |
0 |
log(); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
public URL getURL()... |
83 |
|
{ |
84 |
0 |
return this.url; |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0 |
public void setURL(URL url)... |
88 |
|
{ |
89 |
0 |
this.url = url; |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0 |
public String getWikiPage()... |
93 |
|
{ |
94 |
0 |
return this.wikiPage; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0 |
public void setWikiPage(String page)... |
98 |
|
{ |
99 |
0 |
this.wikiPage = page; |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
public Date getStartTime()... |
103 |
|
{ |
104 |
0 |
return this.startTime; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0 |
public void setStartTime(Date startTime)... |
108 |
|
{ |
109 |
0 |
this.startTime = startTime; |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0 |
public Date getEndTime()... |
113 |
|
{ |
114 |
0 |
return this.endTime; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
public void setEndTime(Date endTime)... |
118 |
|
{ |
119 |
0 |
this.endTime = endTime; |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
public long getDuration()... |
123 |
|
{ |
124 |
0 |
return (this.endTime.getTime() - this.startTime.getTime()); |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
127 |
0 |
public long getDuration(String timer)... |
128 |
|
{ |
129 |
0 |
MonitorTimerSummary tsummary = this.timerSummaries.get(timer); |
130 |
0 |
if (tsummary == null) { |
131 |
0 |
return 0; |
132 |
|
} else { |
133 |
0 |
return tsummary.getDuration(); |
134 |
|
} |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
137 |
0 |
public void startTimer(String timername, String details)... |
138 |
|
{ |
139 |
|
|
140 |
0 |
if (this.startTime == null) { |
141 |
0 |
return; |
142 |
|
} |
143 |
|
|
144 |
0 |
MonitorTimer timer; |
145 |
0 |
timer = this.timers.get(timername); |
146 |
0 |
if (timer != null) { |
147 |
0 |
if (LOGGER.isDebugEnabled()) { |
148 |
0 |
LOGGER.debug("MONITOR: error recursive timers for " + timername); |
149 |
|
} |
150 |
|
} else { |
151 |
0 |
timer = new MonitorTimer(timername, details); |
152 |
0 |
timer.setStartDate(); |
153 |
0 |
this.timers.put(timername, timer); |
154 |
|
} |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public void startTimer(String timername)... |
158 |
|
{ |
159 |
0 |
startTimer(timername, ""); |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
162 |
0 |
public void setTimerDetails(String timername, String details)... |
163 |
|
{ |
164 |
0 |
MonitorTimer timer; |
165 |
0 |
timer = this.timers.get(timername); |
166 |
0 |
if (timer == null) { |
167 |
0 |
if (LOGGER.isDebugEnabled()) { |
168 |
0 |
LOGGER.debug("MONITOR: could not find timer for " + timername); |
169 |
|
} |
170 |
|
} else { |
171 |
0 |
timer.setDetails(details); |
172 |
|
} |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 7 |
Complexity Density: 0.39 |
|
175 |
0 |
public void endTimer(String timername)... |
176 |
|
{ |
177 |
0 |
if (this.startTime == null) { |
178 |
0 |
return; |
179 |
|
} |
180 |
|
|
181 |
0 |
MonitorTimer timer; |
182 |
0 |
timer = this.timers.get(timername); |
183 |
0 |
if (timer == null) { |
184 |
0 |
if (LOGGER.isDebugEnabled()) { |
185 |
0 |
LOGGER.debug("MONITOR: could not find timer for " + timername); |
186 |
|
} |
187 |
|
} else { |
188 |
0 |
timer.setEndDate(); |
189 |
0 |
if (timer.getDetails() != null) { |
190 |
0 |
this.timerList.add(timer); |
191 |
|
} |
192 |
0 |
this.timers.remove(timername); |
193 |
0 |
MonitorTimerSummary tsummary = this.timerSummaries.get(timername); |
194 |
0 |
if (tsummary == null) { |
195 |
0 |
tsummary = new MonitorTimerSummary(timername); |
196 |
0 |
this.timerSummaries.put(timername, tsummary); |
197 |
|
} |
198 |
0 |
tsummary.addTimer(timer.getDuration()); |
199 |
0 |
if (LOGGER.isDebugEnabled()) { |
200 |
0 |
LOGGER.debug("MONITOR " + this.wikiPage + " " + this.action + " " + timer.getName() + ": " |
201 |
|
+ timer.getDuration() + "ms " + timer.getDetails()); |
202 |
|
} |
203 |
|
} |
204 |
|
} |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
public List<MonitorTimer> getTimerList()... |
207 |
|
{ |
208 |
0 |
return this.timerList; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
211 |
0 |
public Map<String, MonitorTimerSummary> getTimerSummaries()... |
212 |
|
{ |
213 |
0 |
return this.timerSummaries; |
214 |
|
} |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
216 |
0 |
public void log()... |
217 |
|
{ |
218 |
0 |
if (LOGGER.isDebugEnabled()) { |
219 |
0 |
LOGGER.debug("MONITOR " + this.wikiPage + ": " + getDuration() + "ms"); |
220 |
0 |
Iterator<MonitorTimerSummary> it = this.timerSummaries.values().iterator(); |
221 |
0 |
while (it.hasNext()) { |
222 |
0 |
MonitorTimerSummary tsummary = it.next(); |
223 |
0 |
LOGGER.debug("MONITOR " + this.wikiPage + " " + this.action + " " + tsummary.getName() + ": " |
224 |
|
+ tsummary.getDuration() + "ms " + tsummary.getNbCalls()); |
225 |
|
} |
226 |
|
} |
227 |
|
} |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
0 |
public String getThreadName()... |
230 |
|
{ |
231 |
0 |
return this.threadName; |
232 |
|
} |
233 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
234 |
0 |
public void setThreadName(String threadName)... |
235 |
|
{ |
236 |
0 |
this.threadName = threadName; |
237 |
|
} |
238 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
239 |
0 |
public long getNbCalls(String timer)... |
240 |
|
{ |
241 |
0 |
MonitorTimerSummary tsummary = this.timerSummaries.get(timer); |
242 |
0 |
if (tsummary == null) { |
243 |
0 |
return 0; |
244 |
|
} else { |
245 |
0 |
return tsummary.getNbCalls(); |
246 |
|
} |
247 |
|
} |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
249 |
0 |
public String getAction()... |
250 |
|
{ |
251 |
0 |
return this.action; |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
254 |
0 |
public void setAction(String action)... |
255 |
|
{ |
256 |
0 |
this.action = action; |
257 |
|
} |
258 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
259 |
0 |
@Override... |
260 |
|
public String toString() |
261 |
|
{ |
262 |
0 |
StringBuffer str = new StringBuffer(); |
263 |
0 |
str.append("WikiPage: "); |
264 |
0 |
str.append(this.wikiPage); |
265 |
0 |
str.append(" Action: "); |
266 |
0 |
str.append(this.action); |
267 |
0 |
str.append(" URL: "); |
268 |
0 |
str.append(this.url.toString()); |
269 |
0 |
str.append(" Thread: "); |
270 |
0 |
str.append(this.threadName); |
271 |
0 |
str.append(" StartTime: " + this.startTime); |
272 |
0 |
str.append(" EndTime: " + this.endTime); |
273 |
0 |
str.append(getTimerSummaries()); |
274 |
0 |
str.append(getTimerList()); |
275 |
0 |
return str.toString(); |
276 |
|
} |
277 |
|
} |