Skip to content

Commit 9d2c180

Browse files
committed
Merge pull request #102 from scouter-project/master
Merge for release
2 parents 21e2b7e + f21a922 commit 9d2c180

File tree

24 files changed

+175
-59
lines changed

24 files changed

+175
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Englsh](https://img.shields.io/badge/language-English-red.svg) [![Korean](https://img.shields.io/badge/language-Korean-blue.svg)](README_kr.md)
44

5-
## Open Source S/W Applicaiton Performance Monitoring
5+
## Open Source S/W Application Performance Monitoring
66

77
SCOUTER is an open source APM and a database monitoring tool.
88
APM means application performance monitoring or application performance management.

scouter.agent.java/src/scouter/agent/Configure.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public final static synchronized Configure getInstance() {
145145
public int xlog_lower_bound_time_ms = 0;
146146
public int xlog_error_jdbc_fetch_max = 10000;
147147
public int xlog_error_sql_time_max_ms = 30000;
148+
public boolean xlog_error_check_user_transaction_enabled = true;
148149

149150
//Alert
150151
public int alert_message_length = 3000;
@@ -493,6 +494,8 @@ private void apply() {
493494

494495
this.enduser_trace_endpoint_url = getValue("enduser_trace_endpoint_url", "_scouter_browser.jsp");
495496
this.enduser_perf_endpoint_hash = HashUtil.hash(this.enduser_trace_endpoint_url);
497+
498+
this.xlog_error_check_user_transaction_enabled = getBoolean("xlog_error_check_user_transaction_enabled", true);
496499

497500
resetObjInfo();
498501
setStaticContents();

scouter.agent.java/src/scouter/agent/ObjTypeDetector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ObjTypeDetector {
3434
bootClass.put("org/jboss/as/server/Main", CounterConstants.JBOSS); // jboss as 7.2.0 final
3535
bootClass.put("org/apache/catalina/startup/Bootstrap", CounterConstants.TOMCAT);
3636
bootClass.put("org/apache/catalina/startup/Tomcat", CounterConstants.TOMCAT);
37+
bootClass.put("com/caucho/server/resin/Resin", CounterConstants.RESIN); // resin 4.x
3738
}
3839

3940
public static String objType = null;

scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
import scouter.org.objectweb.asm.Type;
2929

3030
import java.util.HashSet;
31+
32+
/**
33+
* BCI for a JDBC PreparedStatement
34+
* @author @author Paul S.J. Kim(sjkim@whatap.io)
35+
* @author Gun Lee (gunlee01@gmail.com)
36+
*/
3137
public class JDBCPreparedStatementASM implements IASM, Opcodes {
3238
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_pstmt_classes);
3339
public final HashSet<String> noField = new HashSet<String>();
@@ -44,7 +50,9 @@ public JDBCPreparedStatementASM() {
4450
target.add("org/hsqldb/jdbc/JDBCPreparedStatement");
4551
target.add("com/mysql/jdbc/ServerPreparedStatement");
4652
target.add("com/mysql/jdbc/PreparedStatement");
47-
// @skyworker - MySQL ServerPreparedStatement는 특별히 필드를 추가하지 않음
53+
target.add("cubrid/jdbc/driver/CUBRIDPreparedStatement");
54+
55+
// @skyworker - MySQL ServerPreparedStatement는 특별히 필드를 추가하지 않음
4856
noField.add("com/mysql/jdbc/ServerPreparedStatement");
4957
noField.add("jdbc/FakePreparedStatement2");
5058
}
@@ -61,22 +69,26 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class
6169
}
6270
}
6371
class PreparedStatementCV extends ClassVisitor implements Opcodes {
72+
6473
HashSet<String> noField;
65-
public PreparedStatementCV(ClassVisitor cv, HashSet<String> noField) {
74+
private String owner;
75+
76+
public PreparedStatementCV(ClassVisitor cv, HashSet<String> noField) {
6677
super(ASM4, cv);
6778
this.noField = noField;
6879
}
69-
private String owner;
80+
7081
@Override
7182
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
7283
super.visit(version, access, name, signature, superName, interfaces);
7384
this.owner = name;
7485
if (noField.contains(name) == false) {
75-
// add trace field
86+
// add trace fields
7687
super.visitField(ACC_PUBLIC, TraceSQL.PSTMT_PARAM_FIELD, Type.getDescriptor(SqlParameter.class), null, null)
7788
.visitEnd();
7889
}
7990
}
91+
8092
@Override
8193
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
8294
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);

scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
import scouter.org.objectweb.asm.Opcodes;
2727

2828
import java.util.HashSet;
29+
30+
/**
31+
* BCI for a JDBC Statement
32+
* @author @author Paul S.J. Kim(sjkim@whatap.io)
33+
* @author Gun Lee (gunlee01@gmail.com)
34+
* @author Eunsu Kim
35+
*/
2936
public class JDBCStatementASM implements IASM, Opcodes {
3037
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_stmt_classes);
3138
public JDBCStatementASM() {
@@ -39,6 +46,7 @@ public JDBCStatementASM() {
3946
target.add("com/microsoft/sqlserver/jdbc/SQLServerStatement");
4047
target.add("com/tmax/tibero/jdbc/TbStatement");
4148
target.add("org/hsqldb/jdbc/JDBCStatement");
49+
target.add("cubrid/jdbc/driver/CUBRIDStatement");
4250
}
4351

4452
public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) {

scouter.agent.java/src/scouter/agent/asm/UserTxASM.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ public UserTxCV(ClassVisitor cv) {
5353
@Override
5454
public MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions) {
5555
MethodVisitor mv = super.visitMethod(access, methodName, desc, signature, exceptions);
56-
if ("begin".equals(methodName)) {
56+
if ("begin".equals(methodName) && "()V".equals(desc)) {
5757
return new UTXOpenMV(access, desc, mv);
5858
}
59-
if ("commit".equals(methodName) || "rollback".equals(methodName)) {
59+
if (("commit".equals(methodName) && "()V".equals(desc))
60+
|| ("rollback".equals(methodName) && "()V".equals(desc))) {
6061
return new UTXCloseMV(access, desc, mv, methodName);
6162
}
6263
return mv;

scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,62 @@
1-
/*
2-
* Copyright 2015 Scouter Project.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
/*
2+
* Copyright 2015 Scouter Project.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
1717
package scouter.agent.asm.jdbc;
1818

19-
import scouter.agent.asm.util.AsmUtil;
20-
import scouter.agent.trace.SqlParameter;
21-
import scouter.agent.trace.TraceSQL;
22-
import scouter.org.objectweb.asm.Label;
23-
import scouter.org.objectweb.asm.MethodVisitor;
24-
import scouter.org.objectweb.asm.Opcodes;
25-
import scouter.org.objectweb.asm.Type;
26-
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;
19+
import scouter.agent.Logger;
20+
import scouter.agent.asm.util.AsmUtil;
21+
import scouter.agent.trace.SqlParameter;
22+
import scouter.agent.trace.TraceSQL;
23+
import scouter.org.objectweb.asm.Label;
24+
import scouter.org.objectweb.asm.MethodVisitor;
25+
import scouter.org.objectweb.asm.Opcodes;
26+
import scouter.org.objectweb.asm.Type;
27+
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;
2728

29+
/**
30+
* BCI for a constructor of PreparedStatement
31+
* @author @author Paul S.J. Kim(sjkim@whatap.io)
32+
* @author Gun Lee (gunlee01@gmail.com)
33+
*/
2834
public class PsInitMV extends LocalVariablesSorter implements Opcodes {
2935

3036
private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/');
3137
private final static String METHOD = "prepare";
3238
private final static String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;Ljava/lang/String;)V";
3339

40+
private String owner;
41+
private int sqlIdx = -1;
42+
private boolean isUstatement = false;
43+
3444
public PsInitMV(int access, String desc, MethodVisitor mv, String owner) {
3545
super(ASM4,access, desc, mv);
3646
this.owner = owner;
37-
this.strArgIdx = AsmUtil.getStringIdx(access, desc);
47+
this.sqlIdx = AsmUtil.getStringIdx(access, desc);
3848

49+
if(this.sqlIdx < 0) {
50+
//CUBRID Case
51+
this.sqlIdx = AsmUtil.getIdxByType(access, desc, Type.getType("Lcubrid/jdbc/jci/UStatement;"));
52+
Logger.trace("CUBRID PSTMT LOAD - " + this.sqlIdx);
53+
this.isUstatement = true;
54+
}
3955
}
4056

41-
private String owner;
42-
private int strArgIdx = -1;
43-
4457
@Override
4558
public void visitInsn(int opcode) {
46-
if (strArgIdx >= 0 && (opcode >= IRETURN && opcode <= RETURN)) {
59+
if (sqlIdx >= 0 && (opcode >= IRETURN && opcode <= RETURN)) {
4760

4861
mv.visitVarInsn(ALOAD, 0);
4962
mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;");
@@ -60,7 +73,11 @@ public void visitInsn(int opcode) {
6073
mv.visitVarInsn(ALOAD, 0);
6174
mv.visitVarInsn(ALOAD, 0);
6275
mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;");
63-
mv.visitVarInsn(ALOAD, strArgIdx);
76+
mv.visitVarInsn(ALOAD, sqlIdx);
77+
78+
if(isUstatement) {
79+
mv.visitMethodInsn(INVOKEVIRTUAL, "cubrid/jdbc/jci/UStatement", "getQuery", "()Ljava/lang/String;", false);
80+
}
6481

6582
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false);
6683
}

scouter.agent.java/src/scouter/agent/asm/util/AsmUtil.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
import scouter.org.objectweb.asm.Opcodes;
2525
import scouter.org.objectweb.asm.Type;
2626

27-
27+
/**
28+
* BCI for a constructor of PreparedStatement
29+
* @author @author Paul S.J. Kim(sjkim@whatap.io)
30+
* @author Gun Lee (gunlee01@gmail.com)
31+
*/
2832
public class AsmUtil implements Opcodes {
2933
public static boolean isStatic(int access) {
3034
return (access & ACC_STATIC) != 0;
@@ -132,16 +136,30 @@ public static void PUSH(MethodVisitor mv, Boolean value) {
132136
}
133137

134138
public static int getStringIdx(int access, String desc) {
135-
Type[] t = Type.getArgumentTypes(desc);
139+
return getIdxByType(access, desc, AsmUtil.stringType);
140+
141+
/*Type[] t = Type.getArgumentTypes(desc);
136142
int sidx = (AsmUtil.isStatic(access) ? 0 : 1);
137143
for (int i = 0; t != null && i < t.length; i++) {
138144
if (AsmUtil.stringType.equals(t[i])) {
139145
return sidx;
140146
}
141147
sidx += t[i].getSize();
142148
}
143-
return -1;
144-
}
149+
return -1;*/
150+
}
151+
152+
public static int getIdxByType(int access, String desc, Type type) {
153+
Type[] t = Type.getArgumentTypes(desc);
154+
int sidx = (AsmUtil.isStatic(access) ? 0 : 1);
155+
for (int i = 0; t != null && i < t.length; i++) {
156+
if (type.equals(t[i])) {
157+
return sidx;
158+
}
159+
sidx += t[i].getSize();
160+
}
161+
return -1;
162+
}
145163

146164

147165
public static boolean isSpecial(String name) {

scouter.agent.java/src/scouter/agent/trace/TraceMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static void endHttpService(Object stat, Throwable thr) {
292292
pack.error = DataProxy.sendError(emsg);
293293
ServiceSummary.getInstance().process(thr, pack.error, ctx.serviceHash, ctx.txid, 0, 0);
294294
}
295-
} else if (ctx.userTransaction > 0) {
295+
} else if (ctx.userTransaction > 0 && conf.xlog_error_check_user_transaction_enabled) {
296296
pack.error = DataProxy.sendError("Missing Commit/Rollback Error");
297297
ServiceSummary.getInstance().process(userTxNotClose, pack.error, ctx.serviceHash, ctx.txid, 0, 0);
298298
}
@@ -476,7 +476,7 @@ private static int errorCheck(TraceContext ctx, Throwable thr) {
476476
}
477477
error = DataProxy.sendError(emsg);
478478
ServiceSummary.getInstance().process(thr, error, ctx.serviceHash, ctx.txid, 0, 0);
479-
} else if (ctx.userTransaction > 0) {
479+
} else if (ctx.userTransaction > 0 && conf.xlog_error_check_user_transaction_enabled) {
480480
error = DataProxy.sendError("Missing Commit/Rollback Error");
481481
ServiceSummary.getInstance().process(userTxNotClose, error, ctx.serviceHash, ctx.txid, 0, 0);
482482
}
2.48 KB
Loading

0 commit comments

Comments
 (0)