Skip to content

Commit

Permalink
Merge pull request #92 from scouter-project/master
Browse files Browse the repository at this point in the history
Merge for release
  • Loading branch information
bill23-kim committed Jan 4, 2016
2 parents cc1a64d + b7eaa07 commit fa169d0
Show file tree
Hide file tree
Showing 76 changed files with 2,994 additions and 2,468 deletions.
Empty file modified build_client.sh
100755 → 100644
Empty file.
Empty file modified build_package.sh
100755 → 100644
Empty file.
Empty file modified scouter.agent.host/scripts/readlink.sh
100755 → 100644
Empty file.
Empty file modified scouter.agent.host/scripts/sample2.host.sh
100755 → 100644
Empty file.
Empty file modified scouter.agent.host/scripts/sample2.stop.sh
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions scouter.agent.java/src/scouter/agent/AgentTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public byte[] transform(ClassLoader loader, String className, Class classBeingRe
public void visit(int version, int access, String name, String signature, String superName,
String[] interfaces) {
classDesc.set(version, access, name, signature, superName, interfaces);
super.visit(version, access, name, signature, superName, interfaces);
}

@Override
Expand Down
29 changes: 8 additions & 21 deletions scouter.agent.java/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
*/
package scouter.agent;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import scouter.Version;
import scouter.agent.netio.data.DataProxy;
import scouter.lang.conf.ConfObserver;
Expand All @@ -35,16 +24,10 @@
import scouter.lang.value.ListValue;
import scouter.lang.value.MapValue;
import scouter.net.NetConstants;
import scouter.util.DateUtil;
import scouter.util.FileUtil;
import scouter.util.HashUtil;
import scouter.util.StringEnumer;
import scouter.util.StringKeyLinkedMap;
import scouter.util.StringSet;
import scouter.util.StringUtil;
import scouter.util.SysJMX;
import scouter.util.SystemUtil;
import scouter.util.ThreadUtil;
import scouter.util.*;

import java.io.*;
import java.util.*;
public class Configure extends Thread {
public static boolean JDBC_REDEFINED = false;
private static Configure instance = null;
Expand Down Expand Up @@ -162,6 +145,8 @@ public final static synchronized Configure getInstance() {
public String log_dir ="";
public boolean log_rotation_enabled =true;
public int log_keep_days =7;
public boolean _log_trace_enabled = false;
public boolean _log_trace_use_logger = false;

//Hook
public String hook_args_patterns = "";
Expand Down Expand Up @@ -490,6 +475,8 @@ private void apply() {
this.log_dir = getValue("log_dir", "");
this.log_rotation_enabled = getBoolean("log_rotation_enabled", true);
this.log_keep_days = getInt("log_keep_days", 7);
this._log_trace_enabled = getBoolean("_log_trace_enabled", false);
this._log_trace_use_logger = getBoolean("_log_trace_use_logger", false);

this.enduser_trace_endpoint_url = getValue("enduser_trace_endpoint_url", "_scouter_browser.jsp");
this.enduser_perf_endpoint_hash = HashUtil.hash(this.enduser_trace_endpoint_url);
Expand Down
46 changes: 23 additions & 23 deletions scouter.agent.java/src/scouter/agent/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@
*/
package scouter.agent;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import scouter.util.CompareUtil;
import scouter.util.DateUtil;
import scouter.util.FileUtil;
import scouter.util.IClose;
import scouter.util.StringLongLinkedMap;
import scouter.util.StringUtil;
import scouter.util.ThreadUtil;
import scouter.util.*;

import java.io.*;

public class Logger {

private static StringLongLinkedMap lastLog = new StringLongLinkedMap().setMax(1000);
static Configure conf = Configure.getInstance();

public static void println(Object message) {
public static void println(Object message) {
println(build("SCOUTER", toString(message)), true);
}

Expand All @@ -45,6 +36,24 @@ public static void println(String id, Object message) {
println(build(id, toString(message)), true);
}

public static void println(String id, String message, Throwable t) {
if (checkOk(id, 10) == false) {
return;
}
println(build(id, message), true);
println(ThreadUtil.getStackTrace(t), true);
}

public static void trace(Object message) {
if(conf._log_trace_enabled) {
if(conf._log_trace_use_logger) {
println(build("SCOUTER-TRC", toString(message)), true);
} else {
System.out.println(build("SCOUTER-TRC", toString(message)));
}
}
}

private static String toString(Object message) {
return message == null ? "null" : message.toString();
}
Expand All @@ -55,14 +64,6 @@ private static String build(String id, String message) {
.append(message).toString();
}

public static void println(String id, String message, Throwable t) {
if (checkOk(id, 10) == false) {
return;
}
println(build(id, message), true);
println(ThreadUtil.getStackTrace(t), true);
}

public static String getCallStack(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Expand Down Expand Up @@ -133,7 +134,6 @@ private static synchronized void openFile(String prefix) throws IOException {
}
}

static Configure conf = Configure.getInstance();
static Runnable initializer = new Runnable() {
long last = System.currentTimeMillis();
long lastDataUnit = DateUtil.getDateUnit();
Expand Down
13 changes: 5 additions & 8 deletions scouter.agent.java/src/scouter/agent/asm/JDBCDriverASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
* limitations under the License.
*/
package scouter.agent.asm;
import java.util.Map;
import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.trace.TraceSQL;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.Label;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.*;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

import java.util.Map;
public class JDBCDriverASM implements IASM, Opcodes {
//user can define driver.connect()
private Map<String, HookingSet> reserved =HookingSet.getHookingSet(Configure.getInstance().hook_jdbc_wrapping_driver_patterns);
Expand All @@ -43,7 +40,7 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class
if (mset != null){
return new JDBCDriverCV(cv, mset, className);
}

return cv;
}
}
Expand All @@ -64,7 +61,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
if (AsmUtil.isSpecial(name)) {
return mv;
}
String fullname = AsmUtil.add(className, name, desc);
String fullname = AsmUtil.makeMethodFullName(className, name, desc);

Logger.println("A105", "jdbc db2 driver loaded: " + fullname);
return new JDBCDriverMV(access, desc, mv, fullname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
* limitations under the License.
*/
package scouter.agent.asm;
import java.util.HashSet;
import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.asm.jdbc.PsClearParametersMV;
import scouter.agent.asm.jdbc.PsExecuteMV;
import scouter.agent.asm.jdbc.PsInitMV;
import scouter.agent.asm.jdbc.PsSetMV;
import scouter.agent.asm.jdbc.StExecuteMV;
import scouter.agent.asm.jdbc.*;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.trace.SqlParameter;
import scouter.agent.trace.TraceSQL;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;

import java.util.HashSet;
public class JDBCPreparedStatementASM implements IASM, Opcodes {
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_pstmt_classes);
public final HashSet<String> noField = new HashSet<String>();
Expand Down Expand Up @@ -85,6 +82,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if ("<init>".equals(name)) {
return new PsInitMV(access, desc, mv, owner);

} else {
String targetDesc = PsSetMV.getSetSignature(name);
if (targetDesc != null) {
Expand All @@ -93,13 +91,16 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
}
} else if (PsExecuteMV.isTarget(name)) {
if (desc.startsWith("()")) {
return new PsExecuteMV(access, desc, mv, owner);
return new PsExecuteMV(access, desc, mv, owner, name);
} else if (desc.startsWith("(Ljava/lang/String;)")) {
return new StExecuteMV(access, desc, mv, owner);
return new StExecuteMV(access, desc, mv, owner, name);
}
} else if ("clearParameters".equals(name) && "()V".equals(desc)) {
return new PsClearParametersMV(access, desc, mv, owner);
}

} else if ("getUpdateCount".equals(name) && "()I".equals(desc)) {
return new PsUpdateCountMV(mv);
}
}
return mv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
* limitations under the License.
*/
package scouter.agent.asm;
import java.util.HashSet;
import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.asm.jdbc.PsUpdateCountMV;
import scouter.agent.asm.jdbc.StExecuteMV;
import scouter.agent.asm.util.HookingSet;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;

import java.util.HashSet;
public class JDBCStatementASM implements IASM, Opcodes {
public final HashSet<String> target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_stmt_classes);
public JDBCStatementASM() {
Expand Down Expand Up @@ -65,8 +67,10 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if (StExecuteMV.isTarget(name)) {
if (desc.startsWith("(Ljava/lang/String;)")) {
return new StExecuteMV(access, desc, mv, owner);
return new StExecuteMV(access, desc, mv, owner, name);
}
} else if ("getUpdateCount".equals(name) && "()I".equals(desc)) {
return new PsUpdateCountMV(mv);
}
return mv;
}
Expand Down
12 changes: 4 additions & 8 deletions scouter.agent.java/src/scouter/agent/asm/MethodASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@

package scouter.agent.asm;

import java.util.List;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.netio.data.DataProxy;
import scouter.agent.trace.TraceMain;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.Label;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.*;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

import java.util.List;

public class MethodASM implements IASM, Opcodes {

private List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_method_patterns);
Expand Down Expand Up @@ -106,7 +102,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
if (conf.isIgnoreMethodPrefix(name))
return mv;

String fullname = AsmUtil.add(className, name, desc);
String fullname = AsmUtil.makeMethodFullName(className, name, desc);
int fullname_hash = DataProxy.sendMethodName(fullname);

return new MethodMV(access, desc, mv, fullname, fullname_hash);
Expand Down
30 changes: 21 additions & 9 deletions scouter.agent.java/src/scouter/agent/asm/ServiceASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@

package scouter.agent.asm;

import java.util.List;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.trace.TraceMain;
import scouter.lang.pack.XLogTypes;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.Label;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.*;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

import java.util.List;

public class ServiceASM implements IASM, Opcodes {
private List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_service_patterns);

Expand Down Expand Up @@ -67,8 +63,24 @@ public ServiceCV(ClassVisitor cv, HookingSet mset, String className,byte xType)
this.xType=xType;
}

@Override
/**
* @param access the method's access flags (see {@link Opcodes}). This
* parameter also indicates if the method is synthetic and/or
* deprecated.
* @param name the method's name.
* @param desc the method's descriptor (see {@link Type Type}). (ex) (Ljava/lang/String;)Lorg/mybatis/jpetstore/domain/Category;
* @param signature the method's signature. May be <tt>null</tt> if the method
* parameters, return type and exceptions do not use generic
* types.
* @param exceptions the internal names of the method's exception classes (see
* {@link Type#getInternalName() getInternalName}). May be
* <tt>null</tt>.
* @return
*/
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
//System.out.println("access = [" + access + "], name = [" + name + "], desc = [" + desc + "], signature = [" + signature + "], exceptions = [" + exceptions + "]");

MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if (mv == null || mset.isA(name, desc) == false) {
return mv;
Expand All @@ -77,7 +89,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
return mv;
}

String fullname = AsmUtil.add(className, name, desc);
String fullname = AsmUtil.makeMethodFullName(className, name, desc);
return new ServiceMV(access, desc, mv, fullname,Type.getArgumentTypes(desc),(access & ACC_STATIC) != 0,xType,className,
name, desc);
}
Expand Down
Loading

0 comments on commit fa169d0

Please sign in to comment.