getOptimizationResult.jsp
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ taglib uri="/WEB-INF/weaver.tld" prefix="wea"%>
<%@ page import="java.lang.management.ManagementFactory" %>
<%@ page import="java.lang.management.ThreadInfo" %>
<%@ page import="java.lang.management.ThreadMXBean" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.GCONST" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="java.util.Random" %>
<script src="../profiler/js/jquery-1.4.2.min_wev8.js"></script>
<script type="text/javascript">
var idlist = new Array();
var index = 0;
var displayMap = {};
function closeThisDiv(id){
closeDiv(id,displayMap[id]);
if(displayMap[id]){
displayMap[id]= false;
}else{
displayMap[id] = true;
}
}
function closeDiv(id,none){
var find = false;
for (var thisid in idlist){
if(idlist[thisid].indexOf(id+",")!=-1){
find = true;
}
}
if(!find) return;
for (var thisid in idlist){
if(idlist[thisid].indexOf(id+",")!=-1){
var dd = document.getElementById(idlist[thisid].split(",")[1]);
if(none){
dd.style.display='none';
closeDiv(idlist[thisid].split(",")[1],none);
}else{
dd.style.display='';
}
}
}
}
window.onload = function(){
var $divlist = $("div[id]");
var divindex = 0;
var rootDiv = new Array();
$divlist.each(function(){
var rootid = $(this).attr('parentid');
if(rootid.indexOf("ROOT")!=-1){
rootDiv[divindex++] = $(this).attr('id');
var dd = document.getElementById($(this).attr('id'));
dd.style.display='';
displayMap[$(this).attr('id')]=true;
}
});
$divlist.each(function(){
var parentid = $(this).attr('parentid')+"";
var thisid = $(this).attr('id')+"";
idlist[index++] = parentid+","+thisid;
var find = false;
for(var i=0;i<rootDiv.length;++i){
if(parentid==rootDiv[i]){
find = true;
break;
}
}
if(find){
var dd = document.getElementById(thisid);
dd.style.display='';
}else{
}
});
}
</script>
<%
String key = request.getParameter("key");
String result = "";
boolean hasValue = false;
try{
if(key!=null&&!key.equals("")){
key = key.toLowerCase();
File file = new File(GCONST.getRootPath()+"/profiler/threadlog");
String[] tempList = file.list();
File temp = null;
List<String> findThreads = new ArrayList<String>();
if(tempList.length>0){
String fileName = GCONST.getRootPath()+"/profiler/threadlog";
temp = new File(fileName);
findThreads = getContainKeyThreadId(temp,key);
}
if(findThreads.size()==0){
result = "没有找到包含关键字的线程,请确认关键字是否正确";
}else{
hasValue = true;
result = getResult(findThreads,key);
}
}else{
result = "没有找到包含关键字的线程,请确认关键字是否正确";
}
}catch (Exception ew){
System.out.println("关闭文件流出错!");
System.out.println(ew);
}
%>
<%!
private boolean lineInFindDetails(List<String> findThreads,String line){
for(String threadId:findThreads){
String threadIdStr = threadId.split("\\|\\|")[0];
String threadDetail = threadId;
if(line.indexOf(threadIdStr)!=-1&&threadDetail.indexOf(line.split("\\|\\|")[2])!=-1
&&!(line.trim().indexOf("weaver")==-1&&line.trim().indexOf("__jsp")==-1||(line.trim().indexOf("weaver.conn")!=-1))
){
return true;
}
}
return false;
}
%>
<%!
private boolean lineInFindThreads(List<String> findThreads,String line){
for(String threadId:findThreads){
String threadIdStr = threadId.split("\\|\\|")[0];
String threadDetail = threadId;
if(line.indexOf(threadIdStr)!=-1
&&!(line.trim().indexOf("weaver")==-1&&line.trim().indexOf("__jsp")==-1||(line.trim().indexOf("weaver.conn")!=-1))
){
return true;
}
}
return false;
}
%>
<%!
private String getResult(List<String> findThreads,String find) throws IOException{
StringBuffer result = new StringBuffer();
int len = 200;
String[] buffer = new String[len];
int index = 0;
HashMap<String, Integer> countMap = new LinkedHashMap<String, Integer>();
countMap.put("0",0);
HashMap<String,String> childrenToParent = new HashMap<String,String>();
HashMap<String,String> parentToChildren = new HashMap<String,String>();
ArrayList<String> lineList = new ArrayList<String>();
int lineIndex = 0;
lineList.add(lineIndex,"ROOT");
File root = new File(GCONST.getRootPath()+"/profiler/threadlog");
File[] files = root.listFiles();
int count = 0;
int countFile = 0;
for (int i = 0; i < files.length; i++)
{
File f = files[i];
BufferedReader bfr = new BufferedReader(new FileReader(f));
String line = null;
while ((line = bfr.readLine()) != null)
{
buffer[index] = line.toLowerCase();
line = line.toLowerCase();
if (line.indexOf(find) != -1&&(lineInFindDetails(findThreads,line)))
{
String threadId = line.split("\\|\\|")[0];
String parent = null;
String key = "";
boolean recordFist = true;
for (int j = index; j >=0; j--){
String current = buffer[j];
if(current.indexOf(threadId)==-1)break;
boolean linein = lineInFindThreads(findThreads,current);
if(linein || recordFist){
current = current.split("\\|\\|")[2];
//22:12此处必须有父子结构关系 否则输出的时候 无法进行判断 此处
if(j==index){
count++;
}
Integer thisLineIndex = lineList.indexOf(current);
if(thisLineIndex==-1){
thisLineIndex = ++lineIndex;
lineList.add(thisLineIndex,current);
}
if(parent==null){
key = thisLineIndex+"<0";
if(countMap.get(key)==null){
countMap.put(key,1);
}else{
countMap.put(key,countMap.get(key)+1);
}
countMap.put("0",countMap.get("0")+1);
}else{
key = thisLineIndex+"<"+key;
if(countMap.get(key)==null){
countMap.put(key,1);
}else{
countMap.put(key,countMap.get(key)+1);
}
}
parent = current;
if(!linein)recordFist = false;
if(linein)recordFist = true;
}
}
index = 0;
}
else
{
index++;
if (index == len) {
for(int j=0;j<100;j++){
buffer[j]=buffer[j+100];
}
index = 100;
}
}
}
bfr.close();
}
if(countMap.size()==0||lineList.size()==1)
return "没有找到包含关键字的线程,请确认关键字是否正确";
StringBuffer returnBuffer = new StringBuffer();
HashMap<String,String> perMap = new HashMap<String,String>();
for (Map.Entry<String,Integer> entry:countMap.entrySet()) {
if(entry.getKey().equals("0")){
continue;
}
List<String> parentChildrens = new ArrayList<String>();
String parentKey = entry.getKey().replace(entry.getKey().split("<")[0],"");
int parentCount = 0;
for (Map.Entry<String,Integer> children:countMap.entrySet()) {
String currentKey = children.getKey();
if(currentKey.equals(currentKey.split("<")[0]+parentKey)){
parentChildrens.add(children.getKey());
parentCount+=children.getValue();
}
}
double currentChildrenPer = 1 * 100.0D / parentChildrens.size();
double currentPer = entry.getValue()*100.0D / parentCount;
double currentRootPer = entry.getValue()*100.0D / countMap.get("0");
perMap.put(entry.getKey(),currentChildrenPer+"||"+currentPer+"||"+currentRootPer);
}
String currentKey = null;
for (Map.Entry<String,Integer> entry:countMap.entrySet()) {
if(currentKey==null)
currentKey = entry.getKey();
}
final HashMap<String,String> cperMap = perMap;
Comparator c = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
Double per1 = Double.valueOf(cperMap.get(o1).split("\\|\\|")[1]);
Double per2 = Double.valueOf(cperMap.get(o2).split("\\|\\|")[1]);;
if(per1<per2)
return 1;
else return -1;
}
};
return getTreeInfo(currentKey,perMap,countMap,lineList,0,"ROOT",c);
}
%>
<%!
//不匹配节点占比 直接返回true 后面可调整
private boolean canFix(String key,HashMap<String,String> perMap){
String str = perMap.get(key);
if(str==null) return false;
else{
String currentChildrenPer = str.split("\\|\\|")[0];
String currentPer = str.split("\\|\\|")[1];
if(Double.valueOf(currentChildrenPer)<=Double.valueOf(currentPer))
return true;
else
return false;
}
}
%>
<%!
private String getTreeInfo(String key,HashMap<String,String> perMap,HashMap<String, Integer> countMap,ArrayList<String> lineList,int tab,String parentId,Comparator c){
List<String> childrens = new ArrayList<String>();
String returnKey = null;
Random rd = new Random();
String id = parentId.equals("ROOT")?"ROOT":(rd.nextInt()+"");
if(!key.equals("0")){
returnKey = lineList.get(Integer.valueOf(key.split("<")[0]));
}
for (Map.Entry<String,Integer> children:countMap.entrySet()) {
if(children.getKey().equals(children.getKey().split("<")[0]+"<"+key)
&&canFix(children.getKey(),perMap)){
childrens.add(children.getKey());
}
}
if(childrens.size()==0){
return returnKey+"||"+perMap.get(key)+"||"+tab+"||"+parentId+","+"id_"+id;
}else{
String str = "";
if(childrens.size()==1){
if(!key.equals("0")){
return returnKey+"||"+perMap.get(key)+"||"+tab+"||"+parentId+","+"id_"+id+"!"+getTreeInfo(childrens.get(0),perMap,countMap,lineList,tab+1,"id_"+id,c);
}else{
return getTreeInfo(childrens.get(0),perMap,countMap,lineList,1,"id_"+id,c);
}
}else{
Collections.sort(childrens,c);
for(int i=0;i<childrens.size();++i){
str = str+getTreeInfo(childrens.get(i),perMap,countMap,lineList,tab+1,"id_"+id,c)+"!";
}
if(!key.equals("0")){
return returnKey+"||"+perMap.get(key)+"||"+tab+"||"+parentId+","+"id_"+id+"!"+str;
}else{
return str;
}
}
}
}
%>
<%!
private ArrayList<String> getContainKeyThreadId(File firstFile,String find) throws IOException{
ArrayList<String> list = new ArrayList<String>();
HashMap<String,String> map = new HashMap<String,String>();
File[] files = firstFile.listFiles();
int count = 0;
for (int i = 0; i < files.length; i++)
{
File f = files[i];
BufferedReader bfr = new BufferedReader(new FileReader(f));
String line = null;
while ((line = bfr.readLine()) != null)
{
line = line.toLowerCase();
if (line.indexOf(find) != -1) {
map.put(line.split("\\|\\|")[0],line);
}
}
bfr.close();
for(Map.Entry<String,String> entry:map.entrySet()){
if(!list.contains(entry.getValue())){
list.add(entry.getValue());
}
}
map = new HashMap<String,String>();
}
return list;
}
%>
<%
DecimalFormat df = new DecimalFormat("#0.00");
if(result.indexOf("!")!=-1){
String[] strs = result.split("\\!");
for(String str:strs){
String[] strP = str.split("\\|\\|");
if(strP.length<6)continue;
int tabCount = 0;
if(!strP[4].equals("")){
tabCount = Integer.valueOf(strP[4])-1;
}else{
continue;
}
%>
<div style='display:none' parentid="<%=strP[5].split(",")[0]%>" id="<%=strP[5].split(",")[1]%>" onclick="closeThisDiv('<%=strP[5].split(",")[1]%>')">
<a style='white-space:nowrap;padding-left:<%=tabCount*25%>px'></a>
<%
%>
<a><a style='white-space:nowrap;padding-left:10px'><%="[占比 :"+df.format(Double.valueOf(strP[3]))+"%]"%></a><%=strP[0]%></a>
<br/>
</div>
<%
}
}else{
if(hasValue){
%>
<a style='white-space:nowrap;padding-left:10px'><%="[占比 :100%]"%></a><a><%=result.split("\\|\\|")[0]%></a>
<br/>
<%
}else{
%>
<a><%=result%></a>
<br/>
<%
}
}
%>