profile support & add license info

This commit is contained in:
wenshao
2012-10-09 10:52:29 +08:00
parent e80fac8f91
commit fcbdefa8fe
15 changed files with 294 additions and 52 deletions
@@ -122,6 +122,7 @@ public class WebStatFilter implements Filter {
if (isProfileEnable()) {
Profiler.initLocal();
Profiler.enter(requestURI, Profiler.PROFILE_TYPE_WEB);
}
// 第一次访问时,uriStat这里为null,是为了防止404攻击。
@@ -189,6 +190,8 @@ public class WebStatFilter implements Filter {
WebRequestStat.set(null);
if (isProfileEnable()) {
Profiler.release(nanos);
Map<ProfileEntryKey, ProfileEntryReqStat> requestStatsMap = Profiler.getStatsMap();
uriStat.getProfiletat().record(requestStatsMap);
Profiler.removeLocal();
@@ -143,8 +143,6 @@ public class WebURIStat {
if (requestStat != null) {
this.setLastAccessTimeMillis(requestStat.getStartMillis());
}
Profiler.enter(uri, Profiler.PROFILE_TYPE_WEB);
}
public void afterInvoke(Throwable error, long nanos) {
@@ -216,8 +214,6 @@ public class WebURIStat {
}
currentLocal.set(null);
Profiler.release(nanos);
}
public int getRunningCount() {
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.jconsole;
import java.awt.BorderLayout;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.jconsole.model;
import java.awt.Component;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.jconsole.model;
import java.awt.Color;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.jconsole.model;
import java.util.Enumeration;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.jconsole.model;
import java.awt.Component;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
public class ProfileEntry {
@@ -1,7 +1,21 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
public class ProfileEntryKey {
private final String parentName;
private final String name;
private final String type;
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
public class ProfileEntryReqStat {
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
@@ -1,14 +1,33 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class ProfileStat {
private ConcurrentHashMap<ProfileEntryKey, ProfileEntryStat> entries = new ConcurrentHashMap<ProfileEntryKey, ProfileEntryStat>(
4,
0.75f,
1);
private Map<ProfileEntryKey, ProfileEntryStat> entries = new LinkedHashMap<ProfileEntryKey, ProfileEntryStat>(4);
private ReadWriteLock lock = new ReentrantReadWriteLock();
public Map<ProfileEntryKey, ProfileEntryStat> getEntries() {
return entries;
@@ -23,35 +42,61 @@ public class ProfileStat {
ProfileEntryKey entryKey = entry.getKey();
ProfileEntryReqStat reqEntryStat = entry.getValue();
ProfileEntryStat entryStat = entries.get(entryKey);
if (entryStat == null) {
entries.putIfAbsent(entryKey, new ProfileEntryStat());
entryStat = entries.get(entryKey);
}
ProfileEntryStat entryStat = getProfileEntry(entryKey);
entryStat.addExecuteCount(reqEntryStat.getExecuteCount());
entryStat.addExecuteTimeNanos(reqEntryStat.getExecuteTimeNanos());
}
}
public Map<Map<String, Object>, Map<String, Object>> getStatData() {
Map<Map<String, Object>, Map<String, Object>> data = new LinkedHashMap<Map<String, Object>, Map<String, Object>>();
private ProfileEntryStat getProfileEntry(ProfileEntryKey entryKey) {
for (Map.Entry<ProfileEntryKey, ProfileEntryStat> entry : entries.entrySet()) {
Map<String, Object> key = new LinkedHashMap<String, Object>();
Map<String, Object> value = new LinkedHashMap<String, Object>();
key.put("Parent", entry.getKey().getParentName());
key.put("Name", entry.getKey().getName());
key.put("Type", entry.getKey().getType());
value.put("ExecuteCount", entry.getValue().getExecuteCount());
value.put("ExecuteTimeNanos", entry.getValue().getExecuteTimeNanos());
data.put(key, value);
lock.readLock().lock();
try {
ProfileEntryStat entryStat = entries.get(entryKey);
if (entryStat != null) {
return entryStat;
}
} finally {
lock.readLock().unlock();
}
return data;
lock.writeLock().lock();
try {
ProfileEntryStat entryStat = entries.get(entryKey);
if (entryStat == null) {
entries.put(entryKey, new ProfileEntryStat());
entryStat = entries.get(entryKey);
}
return entryStat;
} finally {
lock.writeLock().unlock();
}
}
public List<Map<String, Object>> getStatData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
lock.readLock().lock();
try {
for (Map.Entry<ProfileEntryKey, ProfileEntryStat> entry : entries.entrySet()) {
Map<String, Object> entryData = new LinkedHashMap<String, Object>();
entryData.put("Name", entry.getKey().getName());
entryData.put("Parent", entry.getKey().getParentName());
entryData.put("Type", entry.getKey().getType());
entryData.put("ExecuteCount", entry.getValue().getExecuteCount());
entryData.put("ExecuteTimeMillis", entry.getValue().getExecuteTimeNanos() / 1000 / 1000);
list.add(entryData);
}
} finally {
lock.readLock().unlock();
}
Collections.reverse(list);
return list;
}
}
@@ -1,6 +1,21 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.profile;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class Profiler {
@@ -64,7 +79,7 @@ public class Profiler {
}
public static void initLocal() {
statsMapLocal.set(new HashMap<ProfileEntryKey, ProfileEntryReqStat>());
statsMapLocal.set(new LinkedHashMap<ProfileEntryKey, ProfileEntryReqStat>());
}
public static void removeLocal() {
@@ -144,6 +144,10 @@ druid.common = function () {
},
subSqlString : function(sql, len) {
if (sql == undefined || sql == null) {
return '';
}
if (sql.length <= len)
return sql;
return sql.substr(0, len) + '...';
@@ -98,6 +98,21 @@
<td id="JdbcResultSetCloseCount"></td>
</tr>
</table>
<h3>Profiles</h3>
<table id="profileDataTable" class="table table-bordered table-striped responsive-utilities">
<thead>
<tr>
<th>N</th>
<th><a id="th-Name" >Name</a></th>
<th>ParentName</th>
<th>Type</th>
<th>ExecuteCount</th>
<th>ExecuteTimeMillis</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="container">
<a class="btn btn-primary" href="javascript:window.close();">Close</a>
</div>
@@ -122,26 +137,56 @@
success: function(data) {
if (data.Content == null)
return;
$("#URI").text(data.Content.URI)
$("#RequestCount").text(data.Content.RequestCount)
$("#RequestTimeMillis").text(data.Content.RequestTimeMillis)
$("#LastAccessTime").text(data.Content.LastAccessTime)
$("#RunningCount").text(data.Content.RunningCount)
$("#ConcurrentMax").text(data.Content.ConcurrentMax)
$("#JdbcExecuteCount").text(data.Content.JdbcExecuteCount)
$("#JdbcExecuteErrorCount").text(data.Content.JdbcExecuteErrorCount)
$("#JdbcExecutePeak").text(data.Content.JdbcExecutePeak)
$("#JdbcExecuteTimeMillis").text(data.Content.JdbcExecuteTimeMillis)
$("#JdbcCommitCount").text(data.Content.JdbcCommitCount)
$("#JdbcRollbackCount").text(data.Content.JdbcRollbackCount)
$("#JdbcFetchRowCount").text(data.Content.JdbcFetchRowCount)
$("#JdbcFetchRowPeak").text(data.Content.JdbcFetchRowPeak)
$("#JdbcUpdateCount").text(data.Content.JdbcUpdateCount)
$("#JdbcUpdatePeak").text(data.Content.JdbcUpdatePeak)
$("#JdbcPoolConnectionOpenCount").text(data.Content.JdbcPoolConnectionOpenCount)
$("#JdbcPoolConnectionCloseCount").text(data.Content.JdbcPoolConnectionCloseCount)
$("#JdbcResultSetOpenCount").text(data.Content.JdbcResultSetOpenCount)
$("#JdbcResultSetCloseCount").text(data.Content.JdbcResultSetCloseCount)
$("#URI").text(data.Content.URI);
$("#RequestCount").text(data.Content.RequestCount);
$("#RequestTimeMillis").text(data.Content.RequestTimeMillis);
$("#LastAccessTime").text(data.Content.LastAccessTime);
$("#RunningCount").text(data.Content.RunningCount);
$("#ConcurrentMax").text(data.Content.ConcurrentMax);
$("#JdbcExecuteCount").text(data.Content.JdbcExecuteCount);
$("#JdbcExecuteErrorCount").text(data.Content.JdbcExecuteErrorCount);
$("#JdbcExecutePeak").text(data.Content.JdbcExecutePeak);
$("#JdbcExecuteTimeMillis").text(data.Content.JdbcExecuteTimeMillis);
$("#JdbcCommitCount").text(data.Content.JdbcCommitCount);
$("#JdbcRollbackCount").text(data.Content.JdbcRollbackCount);
$("#JdbcFetchRowCount").text(data.Content.JdbcFetchRowCount);
$("#JdbcFetchRowPeak").text(data.Content.JdbcFetchRowPeak);
$("#JdbcUpdateCount").text(data.Content.JdbcUpdateCount);
$("#JdbcUpdatePeak").text(data.Content.JdbcUpdatePeak);
$("#JdbcPoolConnectionOpenCount").text(data.Content.JdbcPoolConnectionOpenCount);
$("#JdbcPoolConnectionCloseCount").text(data.Content.JdbcPoolConnectionCloseCount);
$("#JdbcResultSetOpenCount").text(data.Content.JdbcResultSetOpenCount);
$("#JdbcResultSetCloseCount").text(data.Content.JdbcResultSetCloseCount);
var profiles = data.Content.Profiles;
if (profiles == null) {
return;
}
var profileDataTable = document.getElementById("profileDataTable");
while (profileDataTable.rows.length > 1) {
profileDataTable.deleteRow(1);
}
var html = "";
for ( var i = 0; i < profiles.length; i++) {
var stat = profiles[i];
var newRow = profileDataTable.insertRow(-1);
html += "<tr>";
html += "<td>" + (i + 1) + "</td>";
html += "<td>" + stat.Name + "</td>";
if (stat.Parent == null) {
html += "<td> </td>";
} else {
html += "<td>" + stat.Parent + "</td>";
}
html += "<td>" + stat.Type + "</td>";
html += "<td>" + stat.ExecuteCount + "</td>";
html += "<td>" + stat.ExecuteTimeMillis + "</td>";
html += "</tr>";
}
$("#profileDataTable tbody").html(html);
},
dataType: "json"
});