mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 16:56:15 +10:00
[유치수] [ARCUS-127] refactoring sender.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@482 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -23,9 +23,9 @@ public class TomcatProfilerConstant {
|
||||
// public static final int DATA_TYPE_HEAP_MEMORY_STAT=1510;
|
||||
// public static final int DATA_TYPE_NON_HEAP_MEMORY_STAT=1520;
|
||||
|
||||
public static final String CLASS_NAME_REQUEST_TRACER = "com.profiler.trace.RequestTransactionTracer";
|
||||
// public static final String CLASS_NAME_REQUEST_TRACER = "com.profiler.trace.RequestTransactionTracer";
|
||||
public static final String CLASS_NAME_REQUEST_THRIFT_DTO = "com.profiler.dto.RequestThriftDTO";
|
||||
public static final String CLASS_NAME_REQUEST_DATA_TRACER = "com.profiler.trace.RequestDataTracer";
|
||||
// public static final String CLASS_NAME_REQUEST_DATA_TRACER = "com.profiler.trace.RequestDataTracer";
|
||||
public static final String CLASS_NAME_AGENT_STATE_MANAGER = "com.profiler.thread.AgentStateManager";
|
||||
|
||||
public static final int REQ_DATA_TYPE_DB_GET_CONNECTION = 1;
|
||||
|
||||
@@ -7,6 +7,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -55,7 +56,7 @@ public class CubridPreparedStatementModifier extends AbstractModifier {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append("if($2 instanceof cubrid.jdbc.jci.UStatement) { ");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2.getQuery());");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2.getQuery());");
|
||||
sb.append("}}");
|
||||
|
||||
constructor.insertBefore(sb.toString());
|
||||
@@ -65,6 +66,6 @@ public class CubridPreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -46,11 +46,11 @@ public class CubridResultSetModifier extends AbstractModifier {
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".updateFetchCount(); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".addResultSetData(); } ");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); } ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -50,8 +51,8 @@ public class CubridStatementModifier extends AbstractModifier {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
method.insertAfter(sb.toString());
|
||||
|
||||
@@ -4,8 +4,8 @@ import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -50,6 +50,6 @@ public class CubridUStatementModifier extends AbstractModifier {
|
||||
params1[2] = classPool.getCtClass("java.lang.Object");
|
||||
CtMethod method = cc.getDeclaredMethod("bindValue", params1);
|
||||
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlParam($1,$3); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$3); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -45,6 +46,6 @@ public class DBCPBasicDataSourceModifier extends AbstractModifier {
|
||||
|
||||
private void updateGetConnectionMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("getConnection", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putConnection(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$0.getUrl()); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putConnection(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$0.getUrl()); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -45,6 +46,6 @@ public class DBCPPoolModifier extends AbstractModifier {
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -50,11 +51,11 @@ public class MSSQLConnectionModifier extends AbstractModifier {
|
||||
params[1] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("createStatement", params);
|
||||
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -55,7 +56,7 @@ public class MSSQLPreparedStatementModifier extends AbstractModifier {
|
||||
params1[4] = classPool.getCtClass("int");
|
||||
CtMethod method = cc.getDeclaredMethod("setParameter", params1);
|
||||
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlParam($1,$2);} ");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2);} ");
|
||||
}
|
||||
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
@@ -63,12 +64,12 @@ public class MSSQLPreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
if (constructorList.length == 1) {
|
||||
CtConstructor constructor = constructorList[0];
|
||||
constructor.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
constructor.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod = cc.getDeclaredMethod("execute", null);
|
||||
serviceMethod.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
serviceMethod.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -47,11 +47,11 @@ public class MSSQLResultSetModifier extends AbstractModifier {
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("next", null);
|
||||
serviceMethod1.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".updateFetchCount(); }");
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("close", null);
|
||||
serviceMethod1.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".addResultSetData(); }");
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -49,8 +50,8 @@ public class MSSQLStatementModifier extends AbstractModifier {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -47,7 +48,7 @@ public class MySQLConnectionImplModifier extends AbstractModifier {
|
||||
|
||||
private void updateCreateStatementMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("createStatement", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CREATE_STATEMENT + "); }");
|
||||
}
|
||||
|
||||
private void updateGetInstanceMethod(CtClass cc) throws Exception {
|
||||
@@ -59,11 +60,11 @@ public class MySQLConnectionImplModifier extends AbstractModifier {
|
||||
params[4] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod method = cc.getDeclaredMethod("getInstance", params);
|
||||
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putConnection(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$5); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".putConnection(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_GET_CONNECTION + ",$5); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_CLOSE_CONNECTION + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -51,14 +52,14 @@ public class MySQLPreparedStatementModifier extends AbstractModifier {
|
||||
params1[1] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod method1 = cc.getDeclaredMethod("setInternal", params1);
|
||||
|
||||
method1.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlParam($1,$2); }");
|
||||
method1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2); }");
|
||||
|
||||
CtClass[] params2 = new CtClass[2];
|
||||
params2[0] = classPool.getCtClass("int");
|
||||
params2[1] = classPool.getCtClass("byte[]");
|
||||
CtMethod method2 = cc.getDeclaredMethod("setInternal", params2);
|
||||
|
||||
method2.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlParam($1,$2); }");
|
||||
method2.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2); }");
|
||||
}
|
||||
|
||||
private void updateConstructor(CtClass cc) throws Exception {
|
||||
@@ -67,7 +68,7 @@ public class MySQLPreparedStatementModifier extends AbstractModifier {
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
if (params.length == 3) {
|
||||
constructor.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
constructor.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +76,6 @@ public class MySQLPreparedStatementModifier extends AbstractModifier {
|
||||
|
||||
private void updateExecuteQueryMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("executeQuery", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -46,11 +46,11 @@ public class MySQLResultSetModifier extends AbstractModifier {
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".updateFetchCount(); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".addResultSetData(); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -50,8 +51,8 @@ public class MySQLStatementModifier extends AbstractModifier {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
method.insertAfter(sb.toString());
|
||||
|
||||
@@ -8,6 +8,7 @@ import javassist.CtMethod;
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -53,7 +54,7 @@ public class OraclePreparedStatementModifier extends AbstractModifier {
|
||||
params1[1] = classPool.getCtClass("java.lang.String");
|
||||
CtMethod serviceMethod1 = cc.getDeclaredMethod("setStringInternal", params1);
|
||||
|
||||
serviceMethod1.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlParam($1,$2); }");
|
||||
serviceMethod1.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlParam($1,$2); }");
|
||||
|
||||
// CtClass[] params2 = new CtClass[2];
|
||||
// params2[0] = classPool.getCtClass("int");
|
||||
@@ -62,7 +63,7 @@ public class OraclePreparedStatementModifier extends AbstractModifier {
|
||||
// params2);
|
||||
//
|
||||
// serviceMethod2.insertBefore("{" +
|
||||
// TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER +
|
||||
// RequestDataTracer.FQCN +
|
||||
// ".putSqlParam($1,$2); {");
|
||||
}
|
||||
|
||||
@@ -72,13 +73,13 @@ public class OraclePreparedStatementModifier extends AbstractModifier {
|
||||
for (CtConstructor constructor : constructorList) {
|
||||
CtClass params[] = constructor.getParameterTypes();
|
||||
if (params.length == 6) {
|
||||
constructor.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
constructor.insertBefore("{" + DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$2); }");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExecuteMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("execute", null);
|
||||
method.insertAfter("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
method.insertAfter("{" + DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + "); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -46,11 +46,11 @@ public class OracleResultSetModifier extends AbstractModifier {
|
||||
|
||||
private void updateNextMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("next", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".updateFetchCount(); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".updateFetchCount(); }");
|
||||
}
|
||||
|
||||
private void updateCloseMethod(CtClass cc) throws Exception {
|
||||
CtMethod method = cc.getDeclaredMethod("close", null);
|
||||
method.insertBefore("{" + TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".addResultSetData(); }");
|
||||
method.insertBefore("{" + DatabaseRequestTracer.FQCN + ".addResultSetData(); }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javassist.CtMethod;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.DatabaseRequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -50,8 +51,8 @@ public class OracleStatementModifier extends AbstractModifier {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(TomcatProfilerConstant.CLASS_NAME_REQUEST_DATA_TRACER + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".putSqlQuery(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_QUERY + ",$1);");
|
||||
sb.append(DatabaseRequestTracer.FQCN + ".put(" + TomcatProfilerConstant.REQ_DATA_TYPE_DB_EXECUTE_QUERY + ");");
|
||||
sb.append("}");
|
||||
|
||||
serviceMethod.insertAfter(sb.toString());
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.profiler.modifier.tomcat;
|
||||
|
||||
import static com.profiler.config.TomcatProfilerConstant.CLASS_NAME_REQUEST_THRIFT_DTO;
|
||||
import static com.profiler.config.TomcatProfilerConstant.CLASS_NAME_REQUEST_TRACER;
|
||||
import javassist.ByteArrayClassPath;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
import com.profiler.modifier.AbstractModifier;
|
||||
import com.profiler.trace.RequestTracer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -71,7 +71,7 @@ public class EntryPointStandardHostValveModifier extends AbstractModifier {
|
||||
insertCode.append("String requestURL=tempRequest.getRequestURI();");
|
||||
insertCode.append("String clientIP=tempRequest.getRemoteAddr();");
|
||||
insertCode.append(getParameterValues());
|
||||
insertCode.append(CLASS_NAME_REQUEST_TRACER).append(".startTransaction(requestURL,clientIP,requestTime,params);");
|
||||
insertCode.append(RequestTracer.FQCN).append(".startTransaction(requestURL,clientIP,requestTime,params);");
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
insertCode.append("System.out.println(\"--- ApplicationFilterChain.doFilter() is started.\");");
|
||||
@@ -109,7 +109,7 @@ public class EntryPointStandardHostValveModifier extends AbstractModifier {
|
||||
private String getInvokeMethodAfterInsertCode() {
|
||||
StringBuilder insertCode = new StringBuilder();
|
||||
insertCode.append("{");
|
||||
insertCode.append(CLASS_NAME_REQUEST_TRACER).append(".endTransaction();");
|
||||
insertCode.append(RequestTracer.FQCN).append(".endTransaction();");
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
insertCode.append("System.out.println(\"--- ApplicationFilterChain.doFilter() is ended.\");");
|
||||
@@ -129,7 +129,7 @@ public class EntryPointStandardHostValveModifier extends AbstractModifier {
|
||||
insertCode.append("System.out.println(\"--- \"+$e.getMessage()+\" is occured !!!\");");
|
||||
}
|
||||
|
||||
insertCode.append(CLASS_NAME_REQUEST_TRACER).append(".exceptionTransaction($e);");
|
||||
insertCode.append(RequestTracer.FQCN).append(".exceptionTransaction($e);");
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
insertCode.append("System.out.println(\"------------------------------------------------\");");
|
||||
@@ -146,7 +146,7 @@ public class EntryPointStandardHostValveModifier extends AbstractModifier {
|
||||
|
||||
private void addRequestTracerToCurrentClassLoader(ClassLoader classLoader) {
|
||||
try {
|
||||
classLoader.loadClass(CLASS_NAME_REQUEST_TRACER);
|
||||
classLoader.loadClass(RequestTracer.FQCN);
|
||||
classLoader.loadClass(CLASS_NAME_REQUEST_THRIFT_DTO);
|
||||
classLoader.loadClass("org.apache.thrift.TBase");
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -14,10 +14,8 @@ public class TCPSocketManager extends Thread {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
serverSocket = new ServerSocket(
|
||||
TomcatProfilerConfig.AGENT_TCP_LISTEN_PORT, 100);
|
||||
System.out
|
||||
.println("*** Start TomcatProfiler TCP Listen Thread ***");
|
||||
serverSocket = new ServerSocket(TomcatProfilerConfig.AGENT_TCP_LISTEN_PORT, 100);
|
||||
System.out.println("*** Start TomcatProfiler TCP Listen Thread ***");
|
||||
while (true) {
|
||||
Socket socket = serverSocket.accept();
|
||||
InputStream stream = socket.getInputStream();
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.profiler.sender;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public abstract class AbstractDataSender {
|
||||
public void send() {
|
||||
try {
|
||||
byte[] sendData = getSendData();
|
||||
int sendDataLength = sendData.length;
|
||||
|
||||
// System.out.println("sendDataLength="+sendDataLength);
|
||||
|
||||
InetSocketAddress address = getAddress();
|
||||
DatagramPacket packet = new DatagramPacket(sendData,
|
||||
sendDataLength, address);
|
||||
|
||||
DatagramSocket udpSocket = new DatagramSocket();
|
||||
// System.out.println("sendBufferSize="+udpSocket.getSendBufferSize());
|
||||
udpSocket.send(packet);
|
||||
// if(this instanceof RequestDataSender || this instanceof
|
||||
// RequestTransactionDataSender ) {
|
||||
// System.out.println(this.getClass().getName()+" Send bufferSize="+udpSocket.getSendBufferSize()+" dataLength="+sendDataLength);
|
||||
// }
|
||||
udpSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract byte[] getSendData() throws Exception;
|
||||
|
||||
protected abstract InetSocketAddress getAddress() throws Exception;
|
||||
|
||||
public void log(String message) {
|
||||
// System.out.println("[AbstractDataSenderThread] "+message);
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,18 @@ public class AgentInfoSender extends Thread {
|
||||
|
||||
private final Logger logger = Logger.getLogger(AgentInfoSender.class.getName());
|
||||
|
||||
boolean isAgentStart;
|
||||
private boolean isAgentStart;
|
||||
private Socket requestSocket = null;
|
||||
|
||||
public AgentInfoSender(boolean isAgentStart) {
|
||||
this.isAgentStart = isAgentStart;
|
||||
}
|
||||
|
||||
Socket requestSocket = null;
|
||||
|
||||
public void run() {
|
||||
System.out.println("\n\n\n\n\n");
|
||||
System.out.println("send agent info");
|
||||
System.out.println("\n\n\n\n\n");
|
||||
|
||||
if (isAgentStart) {
|
||||
sendAgentStartInfo();
|
||||
} else {
|
||||
@@ -56,7 +59,6 @@ public class AgentInfoSender extends Thread {
|
||||
}
|
||||
|
||||
private void sendAgentStartInfo() {
|
||||
|
||||
while (connectToServer()) {
|
||||
try {
|
||||
Thread.sleep(TomcatProfilerConfig.SERVER_CONNECT_RETRY_GAP);
|
||||
@@ -64,13 +66,9 @@ public class AgentInfoSender extends Thread {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ObjectOutputStream stream = new ObjectOutputStream(requestSocket.getOutputStream());
|
||||
|
||||
// stream.write(("AGENT_HASH="+JVMInfoDTO.hostHashCode).getBytes());
|
||||
// stream.write(("AGENT_IP="+JVMInfoDTO.hostIP).getBytes());
|
||||
// stream.write(("AGENT_PORT="+JVMInfoDTO.portNumber).getBytes());
|
||||
|
||||
AgentInfoDTO dto = new AgentInfoDTO();
|
||||
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
@@ -83,6 +81,7 @@ public class AgentInfoSender extends Thread {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (requestSocket != null) {
|
||||
closeSocket();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.profiler.sender;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.dto.JVMInfoThriftDTO;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
import com.profiler.dto.RequestThriftDTO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class DataSender extends Thread {
|
||||
|
||||
private final LinkedBlockingQueue<TBase<?, ?>> addedQueue = new LinkedBlockingQueue<TBase<?, ?>>();
|
||||
|
||||
private final InetSocketAddress requestDataAddr = new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.REQUEST_DATA_LISTEN_PORT);
|
||||
private final InetSocketAddress requestTransactionDataAddr = new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.REQUEST_TRANSACTION_DATA_LISTEN_PORT);
|
||||
private final InetSocketAddress jvmDataAddr = new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.JVM_DATA_LISTEN_PORT);
|
||||
|
||||
private static class SingletonHolder {
|
||||
public static final DataSender INSTANCE = new DataSender();
|
||||
}
|
||||
|
||||
public static DataSender getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private DataSender() {
|
||||
setName("Data Sender");
|
||||
setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
public boolean addDataToSend(TBase<?, ?> data) {
|
||||
return addedQueue.add(data);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
DatagramSocket udpSocket = null;
|
||||
try {
|
||||
TBase<?, ?> dto = addedQueue.take();
|
||||
|
||||
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
|
||||
byte[] sendData = serializer.serialize(dto);
|
||||
|
||||
// TODO: 포트 하나로 통일 시켜야 함. 일단 임시로 이렇게..
|
||||
InetSocketAddress address = null;
|
||||
if (dto instanceof RequestDataListThriftDTO) {
|
||||
address = requestDataAddr;
|
||||
} else if (dto instanceof RequestThriftDTO) {
|
||||
address = requestTransactionDataAddr;
|
||||
} else if (dto instanceof JVMInfoThriftDTO) {
|
||||
address = jvmDataAddr;
|
||||
}
|
||||
|
||||
if (address == null) {
|
||||
throw new IllegalArgumentException("Can't resolve receiver address.");
|
||||
}
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(sendData, sendData.length, address);
|
||||
|
||||
udpSocket = new DatagramSocket();
|
||||
udpSocket.send(packet);
|
||||
|
||||
System.out.println("data sent.");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (udpSocket != null) {
|
||||
udpSocket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.profiler.sender;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.dto.JVMInfoThriftDTO;
|
||||
|
||||
public class JVMDataSender extends AbstractDataSender{
|
||||
JVMInfoThriftDTO dto;
|
||||
public JVMDataSender(JVMInfoThriftDTO dto) {
|
||||
this.dto=dto;
|
||||
log(dto.toString());
|
||||
}
|
||||
protected byte[] getSendData() throws Exception {
|
||||
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
|
||||
return serializer.serialize(dto);
|
||||
}
|
||||
protected InetSocketAddress getAddress() throws Exception {
|
||||
return new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.JVM_DATA_LISTEN_PORT);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.profiler.sender;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
|
||||
public class RequestDataSender extends AbstractDataSender{
|
||||
RequestDataListThriftDTO dto;
|
||||
public RequestDataSender(RequestDataListThriftDTO dto) {
|
||||
this.dto=dto;
|
||||
// log(dto.toString());
|
||||
}
|
||||
@Override
|
||||
protected byte[] getSendData() throws Exception {
|
||||
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
|
||||
// byte[] serializedBytes=serializer.serialize(dto);
|
||||
// System.out.println("-----Request Data size="+serializedBytes.length);
|
||||
// return serializedBytes;
|
||||
return serializer.serialize(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InetSocketAddress getAddress() throws Exception {
|
||||
return new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.REQUEST_DATA_LISTEN_PORT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.profiler.sender;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.dto.RequestThriftDTO;
|
||||
|
||||
public class RequestTransactionDataSender extends AbstractDataSender{
|
||||
RequestThriftDTO dto;
|
||||
public RequestTransactionDataSender(RequestThriftDTO dto) {
|
||||
this.dto=dto;
|
||||
// log(dto.toString());
|
||||
}
|
||||
@Override
|
||||
protected byte[] getSendData() throws Exception {
|
||||
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
|
||||
// byte[] serializedBytes=serializer.serialize(dto);
|
||||
// System.out.println("-----Request Transaction Data size="+serializedBytes.length);
|
||||
// return serializedBytes;
|
||||
return serializer.serialize(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InetSocketAddress getAddress() throws Exception {
|
||||
return new InetSocketAddress(TomcatProfilerConfig.SERVER_IP, TomcatProfilerConfig.REQUEST_TRANSACTION_DATA_LISTEN_PORT);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,15 @@ package com.profiler.thread;
|
||||
import com.profiler.sender.AgentInfoSender;
|
||||
|
||||
public class AgentStateManager {
|
||||
public static void startJVMTraceThread() {
|
||||
CurrentJVMStateCheckThread tracer = new CurrentJVMStateCheckThread();
|
||||
tracer.setDaemon(true);
|
||||
tracer.start();
|
||||
}
|
||||
public static void sendJVMStoppedInfo() throws Exception {
|
||||
AgentInfoSender sender = new AgentInfoSender(false);
|
||||
sender.start();
|
||||
}
|
||||
|
||||
public static void startJVMTraceThread() {
|
||||
CurrentJVMStateCheckThread tracer = new CurrentJVMStateCheckThread();
|
||||
tracer.setDaemon(true);
|
||||
tracer.start();
|
||||
}
|
||||
|
||||
public static void sendJVMStoppedInfo() throws Exception {
|
||||
AgentInfoSender sender = new AgentInfoSender(false);
|
||||
sender.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.profiler.thread;
|
||||
|
||||
import static com.profiler.config.TomcatProfilerConfig.JVM_STAT_GAP;
|
||||
|
||||
import java.lang.management.GarbageCollectorMXBean;
|
||||
@@ -11,137 +12,144 @@ import java.util.List;
|
||||
import com.profiler.dto.AgentInfoDTO;
|
||||
import com.profiler.dto.JVMInfoThriftDTO;
|
||||
import com.profiler.sender.AgentInfoSender;
|
||||
import com.profiler.sender.JVMDataSender;
|
||||
import com.profiler.trace.RequestTransactionTracer;
|
||||
import com.profiler.sender.DataSender;
|
||||
import com.profiler.trace.RequestTracer;
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class CurrentJVMStateCheckThread extends Thread {
|
||||
JVMInfoThriftDTO currentDto=new JVMInfoThriftDTO();
|
||||
|
||||
private JVMInfoThriftDTO currentDto = new JVMInfoThriftDTO();
|
||||
|
||||
public void run() {
|
||||
setHostIPandPort();
|
||||
|
||||
long gap=0;
|
||||
while(true) {
|
||||
|
||||
long gap = 0;
|
||||
while (true) {
|
||||
try {
|
||||
if(JVM_STAT_GAP>=gap) {
|
||||
long currentMod=System.currentTimeMillis()%1000;
|
||||
Thread.sleep(JVM_STAT_GAP-gap-currentMod+1);
|
||||
}
|
||||
long startTime=System.currentTimeMillis();
|
||||
|
||||
if (JVM_STAT_GAP >= gap) {
|
||||
long currentMod = System.currentTimeMillis() % 1000;
|
||||
Thread.sleep(JVM_STAT_GAP - gap - currentMod + 1);
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
sendJVMState();
|
||||
|
||||
long endTime=System.currentTimeMillis();
|
||||
gap=endTime-startTime;
|
||||
// System.out.println(gap);
|
||||
} catch(java.util.concurrent.RejectedExecutionException ree) {
|
||||
// System.out.println(ree.getMessage());
|
||||
// ree.printStackTrace();
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
gap = endTime - startTime;
|
||||
} catch (java.util.concurrent.RejectedExecutionException ree) {
|
||||
System.out.println("RejectedExecutionException when sending JVM State info ");
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method run only one time and send current agent's information.
|
||||
*
|
||||
* It check's host IP and port.
|
||||
* After then make hashCode of IP+Port string.
|
||||
* This hashCode is always different with others.
|
||||
* It check's host IP and port. After then make hashCode of IP+Port string.
|
||||
* This hashCode is always different with others.
|
||||
*/
|
||||
private void setHostIPandPort() {
|
||||
AgentInfoDTO.staticPortNumber=AgentInfoDTO.getPortNumberString();
|
||||
String hostIP=null;
|
||||
try {
|
||||
InetAddress thisIp =InetAddress.getLocalHost();
|
||||
hostIP=thisIp.getHostAddress();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
hostIP="127.0.0.1";
|
||||
}
|
||||
AgentInfoDTO.staticHostIP=hostIP;
|
||||
System.out.println("*** TomcatProfiler : HostIP="+hostIP+" PortNumbers="+AgentInfoDTO.staticPortNumber);
|
||||
AgentInfoDTO.staticHostHashCode=(hostIP+AgentInfoDTO.staticPortNumber).hashCode();
|
||||
AgentInfoDTO.staticPortNumber = AgentInfoDTO.getPortNumberString();
|
||||
|
||||
AgentInfoSender sender=new AgentInfoSender(true);
|
||||
String hostIP = null;
|
||||
|
||||
try {
|
||||
InetAddress thisIp = InetAddress.getLocalHost();
|
||||
hostIP = thisIp.getHostAddress();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
hostIP = "127.0.0.1";
|
||||
}
|
||||
|
||||
AgentInfoDTO.staticHostIP = hostIP;
|
||||
|
||||
System.out.println("*** TomcatProfiler : HostIP=" + hostIP + " PortNumbers=" + AgentInfoDTO.staticPortNumber);
|
||||
|
||||
AgentInfoDTO.staticHostHashCode = (hostIP + AgentInfoDTO.staticPortNumber).hashCode();
|
||||
|
||||
AgentInfoSender sender = new AgentInfoSender(true);
|
||||
sender.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every JVM_STAT_GAP time, this method is called
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void sendJVMState() throws Exception {
|
||||
currentDto=new JVMInfoThriftDTO();
|
||||
currentDto = new JVMInfoThriftDTO();
|
||||
currentDto.setAgentHashCode(AgentInfoDTO.staticHostHashCode);
|
||||
currentDto.setDataTime(System.currentTimeMillis());
|
||||
|
||||
getActiveThreadCount();
|
||||
getGCState();
|
||||
getMemoryState();
|
||||
getProcessCPUUsage();
|
||||
JVMDataSender sender=new JVMDataSender(currentDto);
|
||||
sender.send();
|
||||
|
||||
DataSender.getInstance().addDataToSend(currentDto);
|
||||
}
|
||||
|
||||
private void getActiveThreadCount() throws Exception {
|
||||
int currentSize=RequestTransactionTracer.getActiveThreadCount();
|
||||
int currentSize = RequestTracer.getActiveThreadCount();
|
||||
currentDto.setActiveThreadCount(currentSize);
|
||||
// JVMDataSender sender=new JVMDataSender(dto);
|
||||
// sender.send();
|
||||
// JVMDataSender sender=new JVMDataSender(dto);
|
||||
// sender.send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void getGCState() throws Exception {
|
||||
List<GarbageCollectorMXBean> list=ManagementFactory.getGarbageCollectorMXBeans();
|
||||
if(list.size()==2) {
|
||||
GarbageCollectorMXBean bean1=list.get(0);
|
||||
List<GarbageCollectorMXBean> list = ManagementFactory.getGarbageCollectorMXBeans();
|
||||
if (list.size() == 2) {
|
||||
GarbageCollectorMXBean bean1 = list.get(0);
|
||||
currentDto.setGc1Count(bean1.getCollectionCount());
|
||||
currentDto.setGc1Time(bean1.getCollectionTime());
|
||||
GarbageCollectorMXBean bean2=list.get(1);
|
||||
GarbageCollectorMXBean bean2 = list.get(1);
|
||||
currentDto.setGc2Count(bean2.getCollectionCount());
|
||||
currentDto.setGc2Time(bean2.getCollectionTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void getMemoryState() throws Exception {
|
||||
MemoryMXBean bean=ManagementFactory.getMemoryMXBean();
|
||||
MemoryUsage heap=bean.getHeapMemoryUsage();
|
||||
MemoryUsage nonHeap=bean.getNonHeapMemoryUsage();
|
||||
|
||||
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
|
||||
MemoryUsage heap = bean.getHeapMemoryUsage();
|
||||
MemoryUsage nonHeap = bean.getNonHeapMemoryUsage();
|
||||
|
||||
currentDto.setHeapUsed(heap.getUsed());
|
||||
currentDto.setHeapCommitted(heap.getCommitted());
|
||||
currentDto.setNonHeapUsed(nonHeap.getUsed());
|
||||
currentDto.setNonHeapCommitted(nonHeap.getCommitted());
|
||||
}
|
||||
long previousCpuTime=0;
|
||||
int processorCount=-1;
|
||||
boolean processCPUAvailable=true;
|
||||
|
||||
long previousCpuTime = 0;
|
||||
int processorCount = -1;
|
||||
boolean processCPUAvailable = true;
|
||||
|
||||
/**
|
||||
* I don't know why should I divide by 10 in this result.
|
||||
* But it works. - -;
|
||||
* I don't know why should I divide by 10 in this result. But it works. - -;
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private void getProcessCPUUsage() throws Exception {
|
||||
try {
|
||||
if(processCPUAvailable) {
|
||||
OperatingSystemMXBean sunOSMBean = ManagementFactory.newPlatformMXBeanProxy(
|
||||
ManagementFactory.getPlatformMBeanServer(),
|
||||
ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
|
||||
OperatingSystemMXBean.class);
|
||||
long cpuTime=sunOSMBean.getProcessCpuTime();
|
||||
if(processorCount==-1) {
|
||||
processorCount=sunOSMBean.getAvailableProcessors();
|
||||
if (processCPUAvailable) {
|
||||
OperatingSystemMXBean sunOSMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
|
||||
long cpuTime = sunOSMBean.getProcessCpuTime();
|
||||
if (processorCount == -1) {
|
||||
processorCount = sunOSMBean.getAvailableProcessors();
|
||||
}
|
||||
// System.out.println(cpuTime);
|
||||
if(previousCpuTime!=0) {
|
||||
long usedCPUTotal=(cpuTime-previousCpuTime)/1000000;
|
||||
double usedCPU=(0.1D*usedCPUTotal)/(processorCount*JVM_STAT_GAP/1000.0);
|
||||
// System.out.println(cpuTime);
|
||||
if (previousCpuTime != 0) {
|
||||
long usedCPUTotal = (cpuTime - previousCpuTime) / 1000000;
|
||||
double usedCPU = (0.1D * usedCPUTotal) / (processorCount * JVM_STAT_GAP / 1000.0);
|
||||
currentDto.setProcessCPUTime(usedCPU);
|
||||
}
|
||||
previousCpuTime=cpuTime;
|
||||
previousCpuTime = cpuTime;
|
||||
}
|
||||
} catch(Exception e) {
|
||||
// e.printStackTrace();
|
||||
processCPUAvailable=false;
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
processCPUAvailable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.profiler.trace;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class AbstractTracer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AbstractTracer.class.getName());
|
||||
|
||||
public static void printStackTrace() {
|
||||
log("#################################################");
|
||||
StackTraceElement[] stackList=Thread.currentThread().getStackTrace();
|
||||
int length=stackList.length;
|
||||
for(int loop=2;loop<length;loop++) {
|
||||
log(stackList[loop].toString());
|
||||
StackTraceElement[] stackList = Thread.currentThread().getStackTrace();
|
||||
|
||||
int length = stackList.length;
|
||||
|
||||
for (int loop = 2; loop < length; loop++) {
|
||||
logger.info("***" + stackList[loop].toString());
|
||||
}
|
||||
}
|
||||
protected static void log(String message) {
|
||||
System.out.println("*** "+message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
package com.profiler.trace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.dto.AgentInfoDTO;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
import com.profiler.dto.RequestDataThriftDTO;
|
||||
import com.profiler.util.QueryStringUtil;
|
||||
|
||||
public class DatabaseRequestTracer {
|
||||
|
||||
public static final String FQCN = DatabaseRequestTracer.class.getName();
|
||||
|
||||
private static Hashtable<Integer, String> dbConnectionURL = new Hashtable<Integer, String>();
|
||||
|
||||
private static Set<Integer> sqlSet = null;
|
||||
static {
|
||||
if (TomcatProfilerConfig.QUERY_COUNT_OVER_10000) {
|
||||
sqlSet = new CopyOnWriteArraySet<Integer>();
|
||||
} else {
|
||||
sqlSet = new HashSet<Integer>(1024);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ThreadLocal<RequestDataListThriftDTO> requestDataThreadLocal = new ThreadLocal<RequestDataListThriftDTO>();
|
||||
private static final ThreadLocal<HashMap<Integer, String>> sqlParamMapThreadLocal = new ThreadLocal<HashMap<Integer, String>>();
|
||||
|
||||
/**
|
||||
* These two variables are used counting "ResultSet.next()" times.
|
||||
*/
|
||||
private static final ThreadLocal<Integer> fetchCountThreadLocal = new ThreadLocal<Integer>();
|
||||
private static final ThreadLocal<Integer> totalFetchCountThreadLocal = new ThreadLocal<Integer>();
|
||||
|
||||
public static RequestDataListThriftDTO getRequestDataList() {
|
||||
return requestDataThreadLocal.get();
|
||||
}
|
||||
|
||||
public static void removeRequestDataList() {
|
||||
requestDataThreadLocal.remove();
|
||||
}
|
||||
|
||||
private static boolean isRequestData() {
|
||||
Integer reqHashCode = RequestTracer.getCurrentRequestHash();
|
||||
if (reqHashCode == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data to requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void put(int dataType) {
|
||||
// System.out.println(dataType+"-----RequestHashCode="+RequestTransactionTracer.getRequestHashCode());
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put Connection data to requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void putConnection(int dataType, String url) {
|
||||
// System.out.println(dataType+"-----RequestHashCode="+RequestTransactionTracer.getRequestHashCode());
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
if (url != null) {
|
||||
int hashCode = url.hashCode();
|
||||
if (!dbConnectionURL.containsKey(hashCode)) {
|
||||
dbConnectionURL.put(hashCode, url);
|
||||
dataDto.setDataString(url);
|
||||
// System.out.println(url);
|
||||
}
|
||||
dataDto.setDataHashCode(hashCode);
|
||||
}
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put SQL Query data into requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void putSqlQuery(int dataType, String data) {
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
int dataHashCode = data.hashCode();
|
||||
dataDto.setDataHashCode(dataHashCode);
|
||||
boolean isAlreadySent = checkHashCode(dataHashCode);
|
||||
if (!isAlreadySent) {
|
||||
if (data != null) {
|
||||
dataDto.setDataString(QueryStringUtil.removeAllMultiSpace(data));
|
||||
}
|
||||
}
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check SQL Query HashCode set. If Query count is over 10000, it can make
|
||||
* memory problem. So this method removes 100 hashCode.
|
||||
*
|
||||
* If you use HashSet this remove code will not run.
|
||||
*
|
||||
* @param dataHashCode
|
||||
* @return
|
||||
*/
|
||||
private static boolean checkHashCode(int dataHashCode) {
|
||||
if (TomcatProfilerConfig.QUERY_COUNT_OVER_10000) {
|
||||
// If sqlSet is CopyOnWriteArraySet, it removes data.
|
||||
if (sqlSet.size() > 10000) {
|
||||
Iterator<Integer> iterator = sqlSet.iterator();
|
||||
for (int loop = 0; loop < 100; loop++) {
|
||||
sqlSet.remove(iterator.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sqlSet.contains(dataHashCode)) {
|
||||
return true;
|
||||
} else {
|
||||
sqlSet.add(dataHashCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage sql param list
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
private static void checkSqlParamMap(List<RequestDataThriftDTO> list) {
|
||||
if (isRequestData()) {
|
||||
HashMap<Integer, String> map = sqlParamMapThreadLocal.get();
|
||||
if (map != null) {
|
||||
int mapSize = map.size();
|
||||
StringBuilder params = new StringBuilder();
|
||||
for (int loop = 1; loop <= mapSize; loop++) {
|
||||
params.append(map.get(loop)).append(",");
|
||||
}
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(TomcatProfilerConstant.REQ_DATA_TYPE_DB_PREPARED_STATEMENT_PARAM, System.currentTimeMillis());
|
||||
dataDto.setDataString(params.toString());
|
||||
list.add(dataDto);
|
||||
}
|
||||
sqlParamMapThreadLocal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sql parameter
|
||||
*
|
||||
* @param sequence
|
||||
* @param data
|
||||
*/
|
||||
public static void putSqlParam(int sequence, String data) {
|
||||
if (isRequestData()) {
|
||||
HashMap<Integer, String> map = sqlParamMapThreadLocal.get();
|
||||
if (map == null) {
|
||||
map = new HashMap<Integer, String>();
|
||||
}
|
||||
// if(data!=null) {
|
||||
// try {
|
||||
// System.out.print("Before="+data);
|
||||
// String afterData1=new String(data.getBytes("MS949"),
|
||||
// "ISO-8859-1");;
|
||||
// System.out.print(" After1="+afterData1);
|
||||
// String afterData1_1=new String(afterData1.getBytes("ISO-8859-1"),
|
||||
// "EUC-KR");;
|
||||
// System.out.print(" After1_1="+afterData1_1);
|
||||
//
|
||||
//
|
||||
// String afterData3=new
|
||||
// String(data.getBytes("ISO-8859-1"),"MS949");
|
||||
// System.out.print(" After3="+afterData3);
|
||||
// String afterData3_1=new
|
||||
// String(afterData3.getBytes("MS949"),"EUC-KR");
|
||||
// System.out.print(" After3_1="+afterData3_1);
|
||||
//
|
||||
// String afterData5=new
|
||||
// String(data.getBytes("ISO-8859-1"),"EUC-KR");
|
||||
// System.out.print(" After5="+afterData5);
|
||||
// String afterData6=new String(data.getBytes("MS949"),"EUC-KR");
|
||||
// System.out.print(" After6="+afterData6);
|
||||
//
|
||||
// String afterData7=new String(data.getBytes(),"ISO-8859-1");
|
||||
// System.out.print(" After7="+afterData7);
|
||||
//
|
||||
// System.out.println();
|
||||
// } catch(Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
map.put(sequence, data);
|
||||
sqlParamMapThreadLocal.set(map);
|
||||
}
|
||||
}
|
||||
|
||||
public static void putSqlParam(int sequence, byte[] data) {
|
||||
putSqlParam(sequence, new String(data));
|
||||
}
|
||||
|
||||
public static void putSqlParam(int sequence, Object data) {
|
||||
if (data != null) {
|
||||
putSqlParam(sequence, data.toString());
|
||||
} else {
|
||||
putSqlParam(sequence, "null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check RequestDataListThriftDTO is null. If this object is null, current
|
||||
* request called this Class first time. So it make RequestDataListThriftDTO
|
||||
* object.
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
private static RequestDataListThriftDTO checkDTO(RequestDataListThriftDTO dto) {
|
||||
if (dto == null) {
|
||||
// System.out.println("dto=null");
|
||||
dto = new RequestDataListThriftDTO(AgentInfoDTO.staticHostHashCode, RequestTracer.getCurrentRequestHash(), new ArrayList<RequestDataThriftDTO>());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* add ResultSet.next() method call count.
|
||||
*/
|
||||
public static void updateFetchCount() {
|
||||
Integer totalFetchCount = totalFetchCountThreadLocal.get();
|
||||
Integer fetchCount = fetchCountThreadLocal.get();
|
||||
if (totalFetchCount == null) {
|
||||
totalFetchCountThreadLocal.set(0);
|
||||
}
|
||||
if (fetchCount == null) {
|
||||
fetchCountThreadLocal.set(0);
|
||||
}
|
||||
totalFetchCountThreadLocal.set(totalFetchCountThreadLocal.get() + 1);
|
||||
fetchCountThreadLocal.set(fetchCountThreadLocal.get() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before transaction end, removes current thread's fetch count data.
|
||||
*/
|
||||
public static void removeFetchCount() {
|
||||
totalFetchCountThreadLocal.remove();
|
||||
fetchCountThreadLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* If ResultSet.close() method is called, this method is called.
|
||||
*/
|
||||
public static void addResultSetData() {
|
||||
if (isRequestData()) {
|
||||
// set data fetch count
|
||||
Integer fetchCount = fetchCountThreadLocal.get();
|
||||
if (fetchCount != null) {
|
||||
Integer totalFetchCount = totalFetchCountThreadLocal.get();
|
||||
fetchCountThreadLocal.remove();
|
||||
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
int listSize = list.size();
|
||||
RequestDataThriftDTO previousDTO = list.get(listSize - 1);
|
||||
if (previousDTO.getDataType() != TomcatProfilerConstant.REQ_DATA_TYPE_DB_FETCH) {
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(TomcatProfilerConstant.REQ_DATA_TYPE_DB_FETCH, System.currentTimeMillis());
|
||||
dataDto.setExtraInt1(fetchCount);
|
||||
dataDto.setExtraInt2(totalFetchCount);
|
||||
list.add(dataDto);
|
||||
} else {
|
||||
// Because of MS SQL.
|
||||
int previousTotalFetchCount = previousDTO.getExtraInt2();
|
||||
totalFetchCountThreadLocal.set(previousTotalFetchCount);
|
||||
}
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
package com.profiler.trace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConfig;
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.dto.AgentInfoDTO;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
import com.profiler.dto.RequestDataThriftDTO;
|
||||
import com.profiler.util.QueryStringUtil;
|
||||
|
||||
public class RequestDataTracer {
|
||||
private static Set<Integer> sqlSet = null;
|
||||
private static Hashtable<Integer, String> dbConnectionURL = new Hashtable<Integer, String>();
|
||||
|
||||
static {
|
||||
if (TomcatProfilerConfig.QUERY_COUNT_OVER_10000) {
|
||||
sqlSet = new CopyOnWriteArraySet<Integer>();
|
||||
} else {
|
||||
sqlSet = new HashSet<Integer>(1024);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ThreadLocal<RequestDataListThriftDTO> requestDataThreadLocal = new ThreadLocal<RequestDataListThriftDTO>();
|
||||
private static final ThreadLocal<HashMap<Integer, String>> sqlParamMapThreadLocal = new ThreadLocal<HashMap<Integer, String>>();
|
||||
|
||||
/**
|
||||
* These two variables are used counting "ResultSet.next()" times.
|
||||
*/
|
||||
private static final ThreadLocal<Integer> fetchCountThreadLocal = new ThreadLocal<Integer>();
|
||||
private static final ThreadLocal<Integer> totalFetchCountThreadLocal = new ThreadLocal<Integer>();
|
||||
|
||||
public static RequestDataListThriftDTO getRequestDataList() {
|
||||
return requestDataThreadLocal.get();
|
||||
}
|
||||
|
||||
public static void removeRequestDataList() {
|
||||
requestDataThreadLocal.remove();
|
||||
}
|
||||
|
||||
private static boolean isRequestData() {
|
||||
Integer reqHashCode = RequestTransactionTracer.getRequestHashCode();
|
||||
if (reqHashCode == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data to requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void put(int dataType) {
|
||||
// System.out.println(dataType+"-----RequestHashCode="+RequestTransactionTracer.getRequestHashCode());
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put Connection data to requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void putConnection(int dataType, String url) {
|
||||
// System.out.println(dataType+"-----RequestHashCode="+RequestTransactionTracer.getRequestHashCode());
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
if (url != null) {
|
||||
int hashCode = url.hashCode();
|
||||
if (!dbConnectionURL.containsKey(hashCode)) {
|
||||
dbConnectionURL.put(hashCode, url);
|
||||
dataDto.setDataString(url);
|
||||
// System.out.println(url);
|
||||
}
|
||||
dataDto.setDataHashCode(hashCode);
|
||||
}
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put SQL Query data into requestDataThreadLocal.
|
||||
*
|
||||
* @param dataType
|
||||
*/
|
||||
public static void putSqlQuery(int dataType, String data) {
|
||||
if (isRequestData()) {
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
// System.out.println("-----RequestDataListThriftDTO list size="+list.size());
|
||||
|
||||
checkSqlParamMap(list);
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(dataType, System.currentTimeMillis());
|
||||
int dataHashCode = data.hashCode();
|
||||
dataDto.setDataHashCode(dataHashCode);
|
||||
boolean isAlreadySent = checkHashCode(dataHashCode);
|
||||
if (!isAlreadySent) {
|
||||
if (data != null) {
|
||||
dataDto.setDataString(QueryStringUtil.removeAllMultiSpace(data));
|
||||
}
|
||||
}
|
||||
list.add(dataDto);
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check SQL Query HashCode set.
|
||||
* If Query count is over 10000, it can make memory problem.
|
||||
* So this method removes 100 hashCode.
|
||||
* <p/>
|
||||
* If you use HashSet this remove code will not run.
|
||||
*
|
||||
* @param dataHashCode
|
||||
* @return
|
||||
*/
|
||||
private static boolean checkHashCode(int dataHashCode) {
|
||||
if (TomcatProfilerConfig.QUERY_COUNT_OVER_10000) {
|
||||
//If sqlSet is CopyOnWriteArraySet, it removes data.
|
||||
if (sqlSet.size() > 10000) {
|
||||
Iterator<Integer> iterator = sqlSet.iterator();
|
||||
for (int loop = 0; loop < 100; loop++) {
|
||||
sqlSet.remove(iterator.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sqlSet.contains(dataHashCode)) {
|
||||
return true;
|
||||
} else {
|
||||
sqlSet.add(dataHashCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage sql param list
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
private static void checkSqlParamMap(List<RequestDataThriftDTO> list) {
|
||||
if (isRequestData()) {
|
||||
HashMap<Integer, String> map = sqlParamMapThreadLocal.get();
|
||||
if (map != null) {
|
||||
int mapSize = map.size();
|
||||
StringBuilder params = new StringBuilder();
|
||||
for (int loop = 1; loop <= mapSize; loop++) {
|
||||
params.append(map.get(loop)).append(",");
|
||||
}
|
||||
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(TomcatProfilerConstant.REQ_DATA_TYPE_DB_PREPARED_STATEMENT_PARAM, System.currentTimeMillis());
|
||||
dataDto.setDataString(params.toString());
|
||||
list.add(dataDto);
|
||||
}
|
||||
sqlParamMapThreadLocal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sql parameter
|
||||
*
|
||||
* @param sequence
|
||||
* @param data
|
||||
*/
|
||||
public static void putSqlParam(int sequence, String data) {
|
||||
if (isRequestData()) {
|
||||
HashMap<Integer, String> map = sqlParamMapThreadLocal.get();
|
||||
if (map == null) {
|
||||
map = new HashMap<Integer, String>();
|
||||
}
|
||||
// if(data!=null) {
|
||||
// try {
|
||||
// System.out.print("Before="+data);
|
||||
// String afterData1=new String(data.getBytes("MS949"), "ISO-8859-1");;
|
||||
// System.out.print(" After1="+afterData1);
|
||||
// String afterData1_1=new String(afterData1.getBytes("ISO-8859-1"), "EUC-KR");;
|
||||
// System.out.print(" After1_1="+afterData1_1);
|
||||
//
|
||||
//
|
||||
// String afterData3=new String(data.getBytes("ISO-8859-1"),"MS949");
|
||||
// System.out.print(" After3="+afterData3);
|
||||
// String afterData3_1=new String(afterData3.getBytes("MS949"),"EUC-KR");
|
||||
// System.out.print(" After3_1="+afterData3_1);
|
||||
//
|
||||
// String afterData5=new String(data.getBytes("ISO-8859-1"),"EUC-KR");
|
||||
// System.out.print(" After5="+afterData5);
|
||||
// String afterData6=new String(data.getBytes("MS949"),"EUC-KR");
|
||||
// System.out.print(" After6="+afterData6);
|
||||
//
|
||||
// String afterData7=new String(data.getBytes(),"ISO-8859-1");
|
||||
// System.out.print(" After7="+afterData7);
|
||||
//
|
||||
// System.out.println();
|
||||
// } catch(Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
map.put(sequence, data);
|
||||
sqlParamMapThreadLocal.set(map);
|
||||
}
|
||||
}
|
||||
|
||||
public static void putSqlParam(int sequence, byte[] data) {
|
||||
putSqlParam(sequence, new String(data));
|
||||
}
|
||||
|
||||
public static void putSqlParam(int sequence, Object data) {
|
||||
if (data != null) {
|
||||
putSqlParam(sequence, data.toString());
|
||||
} else {
|
||||
putSqlParam(sequence, "null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check RequestDataListThriftDTO is null.
|
||||
* If this object is null, current request called this Class first time.
|
||||
* So it make RequestDataListThriftDTO object.
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
private static RequestDataListThriftDTO checkDTO(RequestDataListThriftDTO dto) {
|
||||
if (dto == null) {
|
||||
// System.out.println("dto=null");
|
||||
dto = new RequestDataListThriftDTO(AgentInfoDTO.staticHostHashCode, RequestTransactionTracer.getRequestHashCode(), new ArrayList<RequestDataThriftDTO>());
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* add ResultSet.next() method call count.
|
||||
*/
|
||||
public static void updateFetchCount() {
|
||||
Integer totalFetchCount = totalFetchCountThreadLocal.get();
|
||||
Integer fetchCount = fetchCountThreadLocal.get();
|
||||
if (totalFetchCount == null) {
|
||||
totalFetchCountThreadLocal.set(0);
|
||||
}
|
||||
if (fetchCount == null) {
|
||||
fetchCountThreadLocal.set(0);
|
||||
}
|
||||
totalFetchCountThreadLocal.set(totalFetchCountThreadLocal.get() + 1);
|
||||
fetchCountThreadLocal.set(fetchCountThreadLocal.get() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before transaction end, removes current thread's fetch count data.
|
||||
*/
|
||||
public static void removeFetchCount() {
|
||||
totalFetchCountThreadLocal.remove();
|
||||
fetchCountThreadLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* If ResultSet.close() method is called,
|
||||
* this method is called.
|
||||
*/
|
||||
public static void addResultSetData() {
|
||||
if (isRequestData()) {
|
||||
//set data fetch count
|
||||
Integer fetchCount = fetchCountThreadLocal.get();
|
||||
if (fetchCount != null) {
|
||||
Integer totalFetchCount = totalFetchCountThreadLocal.get();
|
||||
fetchCountThreadLocal.remove();
|
||||
|
||||
RequestDataListThriftDTO dto = requestDataThreadLocal.get();
|
||||
dto = checkDTO(dto);
|
||||
List<RequestDataThriftDTO> list = dto.getRequestDataList();
|
||||
int listSize = list.size();
|
||||
RequestDataThriftDTO previousDTO = list.get(listSize - 1);
|
||||
if (previousDTO.getDataType() != TomcatProfilerConstant.REQ_DATA_TYPE_DB_FETCH) {
|
||||
RequestDataThriftDTO dataDto = new RequestDataThriftDTO(TomcatProfilerConstant.REQ_DATA_TYPE_DB_FETCH, System.currentTimeMillis());
|
||||
dataDto.setExtraInt1(fetchCount);
|
||||
dataDto.setExtraInt2(totalFetchCount);
|
||||
list.add(dataDto);
|
||||
} else {
|
||||
//Because of MS SQL.
|
||||
int previousTotalFetchCount = previousDTO.getExtraInt2();
|
||||
totalFetchCountThreadLocal.set(previousTotalFetchCount);
|
||||
}
|
||||
requestDataThreadLocal.set(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.profiler.trace;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.dto.AgentInfoDTO;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
import com.profiler.dto.RequestThriftDTO;
|
||||
import com.profiler.sender.DataSender;
|
||||
|
||||
public class RequestTracer extends AbstractTracer {
|
||||
|
||||
public static final String FQCN = RequestTracer.class.getName();
|
||||
|
||||
private static final ThreadLocal<String> currentRequestID = new ThreadLocal<String>();
|
||||
private static final ThreadLocal<Integer> currentRequestHash = new ThreadLocal<Integer>();
|
||||
private static final Set<String> requestSet = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
public static void startTransaction(String requestURL, String clientIP, long requestTime, StringBuilder params) {
|
||||
long cpuUserTime[] = getThreadTime();
|
||||
|
||||
String tempRequestID = Thread.currentThread().getName() + "_" + System.nanoTime();
|
||||
int tempRequestHashCode = tempRequestID.hashCode();
|
||||
|
||||
currentRequestID.set(tempRequestID);
|
||||
currentRequestHash.set(tempRequestHashCode);
|
||||
requestSet.add(tempRequestID);
|
||||
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, tempRequestHashCode, TomcatProfilerConstant.DATA_TYPE_REQUEST, requestTime, cpuUserTime[0], cpuUserTime[1]);
|
||||
dto.setClientIP(clientIP);
|
||||
dto.setRequestURL(requestURL);
|
||||
|
||||
int paramsLength = params.length();
|
||||
if (paramsLength > 0) {
|
||||
params.deleteCharAt(paramsLength - 1);
|
||||
dto.setExtraData1(params.toString());
|
||||
}
|
||||
|
||||
DataSender.getInstance().addDataToSend(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction is successfully ended.
|
||||
*/
|
||||
public static void endTransaction() {
|
||||
long cpuUserTime[] = getThreadTime();
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, currentRequestHash.get(), TomcatProfilerConstant.DATA_TYPE_RESPONSE, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
|
||||
finishTransaction(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* There was an Exception processing transaction.
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
public static void exceptionTransaction(Throwable throwable) {
|
||||
long cpuUserTime[] = getThreadTime();
|
||||
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, currentRequestHash.get(), TomcatProfilerConstant.DATA_TYPE_UNCAUGHT_EXCEPTION, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
|
||||
dto.setExtraData1(throwable.getMessage());
|
||||
|
||||
StackTraceElement[] tempElement = throwable.getStackTrace();
|
||||
dto.setExtraData2(tempElement[0].toString());
|
||||
|
||||
finishTransaction(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction is ended and send request end data
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
private static void finishTransaction(RequestThriftDTO dto) {
|
||||
RequestDataListThriftDTO dataListDto = DatabaseRequestTracer.getRequestDataList();
|
||||
|
||||
if (dataListDto != null) {
|
||||
DataSender.getInstance().addDataToSend(dataListDto);
|
||||
}
|
||||
|
||||
DataSender.getInstance().addDataToSend(dto);
|
||||
|
||||
requestSet.remove(currentRequestID.get());
|
||||
DatabaseRequestTracer.removeRequestDataList();
|
||||
DatabaseRequestTracer.removeFetchCount();
|
||||
}
|
||||
|
||||
public static int getActiveThreadCount() {
|
||||
return requestSet.size();
|
||||
}
|
||||
|
||||
public static Integer getCurrentRequestHash() {
|
||||
return currentRequestHash.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* If every time call Thread's CPU time it affect to TPS and CPU usage. It
|
||||
* is one of bottle neck.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static long[] getThreadTime() {
|
||||
long result[] = new long[2];
|
||||
|
||||
// ThreadMXBean bean = ManagementFactory.getThreadMXBean();
|
||||
//
|
||||
// System.out.println(Thread.currentThread().getName() + " CPU:" +
|
||||
// bean.getCurrentThreadCpuTime() + " User:" +
|
||||
// bean.getCurrentThreadUserTime());
|
||||
//
|
||||
// result[0] = bean.getCurrentThreadCpuTime();
|
||||
// result[1] = bean.getCurrentThreadUserTime();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.profiler.trace;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.profiler.config.TomcatProfilerConstant;
|
||||
import com.profiler.dto.AgentInfoDTO;
|
||||
import com.profiler.dto.RequestDataListThriftDTO;
|
||||
import com.profiler.dto.RequestThriftDTO;
|
||||
import com.profiler.sender.RequestDataSender;
|
||||
import com.profiler.sender.RequestTransactionDataSender;
|
||||
|
||||
public class RequestTransactionTracer extends AbstractTracer {
|
||||
// private static Hashtable<String,RequestThriftDTO> requestTable=new Hashtable<String,RequestThriftDTO>();
|
||||
private static Set<String> requestSet = null;
|
||||
|
||||
static {
|
||||
|
||||
requestSet = Collections.synchronizedSet(new HashSet<String>());
|
||||
}
|
||||
|
||||
public RequestTransactionTracer() {
|
||||
}
|
||||
|
||||
private static final ThreadLocal<String> requestID = new ThreadLocal<String>();
|
||||
private static final ThreadLocal<Integer> requestHashCode = new ThreadLocal<Integer>();
|
||||
|
||||
public static Integer getRequestHashCode() {
|
||||
return requestHashCode.get();
|
||||
}
|
||||
|
||||
public static void startTransaction(String requestURL, String clientIP, long requestTime, StringBuilder params) {
|
||||
// printStackTrace();
|
||||
// long cpuUserTime[]=getThreadTime();
|
||||
long cpuUserTime[] = new long[2];
|
||||
|
||||
String currentThreadName = Thread.currentThread().getName();
|
||||
//### set Thread id with thread local
|
||||
String tempRequestID = currentThreadName + "_" + System.nanoTime();
|
||||
requestID.set(tempRequestID);
|
||||
int tempRequestHashCode = tempRequestID.hashCode();
|
||||
requestHashCode.set(tempRequestHashCode);
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, tempRequestHashCode, TomcatProfilerConstant.DATA_TYPE_REQUEST, requestTime, cpuUserTime[0], cpuUserTime[1]);
|
||||
dto.setClientIP(clientIP);
|
||||
dto.setRequestURL(requestURL);
|
||||
int paramsLength = params.length();
|
||||
if (paramsLength > 0) {
|
||||
params.deleteCharAt(paramsLength - 1);
|
||||
dto.setExtraData1(params.toString());
|
||||
}
|
||||
requestSet.add(requestID.get());
|
||||
RequestTransactionDataSender sender = new RequestTransactionDataSender(dto);
|
||||
sender.send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction is successfully ended.
|
||||
*/
|
||||
public static void endTransaction() {
|
||||
// long cpuUserTime[]=getThreadTime();
|
||||
long cpuUserTime[] = new long[2];
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, requestHashCode.get(), TomcatProfilerConstant.DATA_TYPE_RESPONSE, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
|
||||
finishTransaction(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* There was an Exception processing transaction.
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
public static void exceptionTransaction(Throwable throwable) {
|
||||
// long cpuUserTime[]=getThreadTime();
|
||||
long cpuUserTime[] = new long[2];
|
||||
RequestThriftDTO dto = new RequestThriftDTO(AgentInfoDTO.staticHostHashCode, requestHashCode.get(), TomcatProfilerConstant.DATA_TYPE_UNCAUGHT_EXCEPTION, System.currentTimeMillis(), cpuUserTime[0], cpuUserTime[1]);
|
||||
dto.setExtraData1(throwable.getMessage());
|
||||
StackTraceElement[] tempElement = throwable.getStackTrace();
|
||||
dto.setExtraData2(tempElement[0].toString());
|
||||
|
||||
finishTransaction(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction is ended and send request end data
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
public static void finishTransaction(RequestThriftDTO dto) {
|
||||
RequestDataListThriftDTO dataListDto = RequestDataTracer.getRequestDataList();
|
||||
if (dataListDto != null) {
|
||||
RequestDataSender dSender = new RequestDataSender(dataListDto);
|
||||
dSender.send();
|
||||
}
|
||||
RequestTransactionDataSender tSender = new RequestTransactionDataSender(dto);
|
||||
tSender.send();
|
||||
|
||||
requestSet.remove(requestID.get());
|
||||
RequestDataTracer.removeRequestDataList();
|
||||
|
||||
RequestDataTracer.removeFetchCount();
|
||||
}
|
||||
|
||||
public static int getActiveThreadCount() {
|
||||
return requestSet.size();
|
||||
}
|
||||
/* If every time call Thread's CPU time
|
||||
* it affect to TPS and CPU usage.
|
||||
* It is one of bottle neck.
|
||||
public static long[] getThreadTime() {
|
||||
long result[]=new long[2];
|
||||
|
||||
ThreadMXBean bean=ManagementFactory.getThreadMXBean();
|
||||
// System.out.println(Thread.currentThread().getName()+" CPU:"+bean.getCurrentThreadCpuTime()+" User:"+bean.getCurrentThreadUserTime());
|
||||
result[0]=bean.getCurrentThreadCpuTime();
|
||||
result[1]=bean.getCurrentThreadUserTime();
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user