Skip to content

Commit

Permalink
Merge pull request #31 from scouter-project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bill23-kim committed Sep 15, 2015
2 parents 9ca8b00 + ac068c1 commit fdf3d03
Show file tree
Hide file tree
Showing 58 changed files with 1,703 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hyperic.sigar.Swap;

import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.counter.CounterBasket;
import scouter.agent.counter.anotation.Counter;
import scouter.lang.TimeTypeEnum;
Expand All @@ -28,7 +29,7 @@ public void process(CounterBasket pw) {
netstat();
domain(pw);
} catch (Exception e) {
e.printStackTrace();
Logger.println("A140", 10, "HostPerf", e);
}
}

Expand Down
18 changes: 5 additions & 13 deletions scouter.agent.java/src/scouter/agent/asm/CapArgsASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public MethodVisitor visitMethod(int access, String methodName, String desc, Str
if (AsmUtil.isSpecial(methodName)) {
return mv;
}
// String fullname = AsmUtil.add(className, name, desc);
// int fullname_hash = HashUtil.hash(fullname);
return new CapArgsMV(access, desc, mv, Type.getArgumentTypes(desc), (access & ACC_STATIC) != 0, className,
methodName, desc);
}
Expand Down Expand Up @@ -115,19 +113,13 @@ public void visitCode() {
mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
mv.visitVarInsn(Opcodes.ASTORE, arrVarIdx);

// if (isStatic == false) {
// mv.visitVarInsn(Opcodes.ALOAD, arrVarIdx);
// AsmUtil.PUSH(mv, 0);
// mv.visitVarInsn(Opcodes.ALOAD, 0);
// mv.visitInsn(Opcodes.AASTORE);
// }

for (int i = 0; i < paramTypes.length; i++) {
Type tp = paramTypes[i];
Type type = paramTypes[i];
mv.visitVarInsn(Opcodes.ALOAD, arrVarIdx);
AsmUtil.PUSH(mv, i);

switch (tp.getSort()) {
switch (type.getSort()) {
case Type.BOOLEAN:
mv.visitVarInsn(Opcodes.ILOAD, sidx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;",false);
Expand Down Expand Up @@ -164,14 +156,14 @@ public void visitCode() {
mv.visitVarInsn(Opcodes.ALOAD, sidx);
}
mv.visitInsn(Opcodes.AASTORE);
sidx += tp.getSize();
sidx += type.getSize();
}
AsmUtil.PUSH(mv, className);
AsmUtil.PUSH(mv, methodName);
AsmUtil.PUSH(mv, methodDesc);
mv.visitVarInsn(Opcodes.ALOAD, arrVarIdx);

mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE);
super.visitCode();
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE,false);
mv.visitCode();
}
}
3 changes: 1 addition & 2 deletions scouter.agent.java/src/scouter/agent/asm/CapReturnASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;



public class CapReturnASM implements IASM, Opcodes {
private List< MethodSet> target = MethodSet.getHookingMethodSet(Configure.getInstance().hook_return);

Expand Down Expand Up @@ -122,7 +121,7 @@ private void capReturn() {
AsmUtil.PUSH(mv, methodName);
AsmUtil.PUSH(mv, methodDesc);
mv.visitInsn(ACONST_NULL);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE,false);
return;
}
int i = newLocal(tp);
Expand Down
4 changes: 2 additions & 2 deletions scouter.agent.java/src/scouter/agent/asm/jdbc/P0InitMV.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void visitInsn(int opcode) {
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, Type.getInternalName(SqlParameter.class));
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(SqlParameter.class), "<init>", "()V");
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(SqlParameter.class), "<init>", "()V",false);
mv.visitFieldInsn(PUTFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;");

mv.visitLabel(end);
Expand All @@ -62,7 +62,7 @@ public void visitInsn(int opcode) {
mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;");
mv.visitVarInsn(ALOAD, strArgIdx);

mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false);
}
mv.visitInsn(opcode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void visitInsn(int opcode) {
// mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD,
// "Lscouter/agent/trace/SqlParameter;");
mv.visitVarInsn(ALOAD, strArgIdx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false);
}
mv.visitInsn(opcode);
}
Expand Down
3 changes: 0 additions & 3 deletions scouter.agent.java/src/scouter/agent/asm/util/MethodSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ public static List<MethodSet> getHookingMethodSet(String arg) {

return list;
}

static String hook_subcall = "*.SapServiceImpl.getZ_SD_SHOP_STOCK_INFO , *.Sa1pServiceImpl.getZ_SD_SHOP_STOCK_INFO";


public static void setHookingMethod(Map<String, MethodSet> classSet, String cname, String mname) {

Expand Down
49 changes: 49 additions & 0 deletions scouter.agent.java/src/scouter/agent/counter/task/PermGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package scouter.agent.counter.task;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.util.List;

import scouter.agent.counter.CounterBasket;
import scouter.agent.counter.anotation.Counter;
import scouter.agent.counter.meter.MeterResource;
import scouter.lang.TimeTypeEnum;
import scouter.lang.counters.CounterConstants;
import scouter.lang.pack.PerfCounterPack;
import scouter.lang.value.FloatValue;

public class PermGen {

MemoryPoolMXBean permGenBean;
public MeterResource meter = new MeterResource();

@Counter
public void getPermGen(CounterBasket pw) {
if (permGenBean == null) {
try {
List<MemoryPoolMXBean> beans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean bean : beans) {
if (bean.getName().toUpperCase().contains("PERM GEN")) {
permGenBean = bean;
break;
}
}
} catch (Throwable th) { }
}
if (permGenBean == null) return;
MemoryUsage usage = permGenBean.getUsage();
long used = usage.getUsed();
meter.add(used);
float usedM = (used / 1024.f / 1024.f);
float max = (usage.getMax() / 1024.f / 1024.f);

PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
p.put(CounterConstants.JAVA_PERM_USED, new FloatValue(usedM));
p.put(CounterConstants.JAVA_PERM_PERCENT, new FloatValue(usedM * 100 / max));

p = pw.getPack(TimeTypeEnum.FIVE_MIN);
p.put(CounterConstants.JAVA_PERM_USED, new FloatValue((float)(meter.getAvg(300) / 1024.f / 1024.f)));
}

}
48 changes: 42 additions & 6 deletions scouter.agent.java/src/scouter/agent/netio/data/net/TcpWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ public void run() {
if (socket == null)
return;
try {
process(socket);
processV2(socket);
} catch (Throwable t) {
} finally {
close();
}
}
public void close(){
FileUtil.close(socket);
socket = null;

public void close() {
FileUtil.close(socket);
socket = null;
LIVE.remove(this.hashCode());
}
}

protected Socket socket = null;

public boolean prepare() {
Expand All @@ -56,7 +58,7 @@ public boolean prepare() {
if (localAddr == null) {
localAddr = socket.getLocalAddress().getHostAddress();
}
LIVE.put(this.hashCode(),this);
LIVE.put(this.hashCode(), this);
return true;
} catch (Exception e) {
return false;
Expand Down Expand Up @@ -91,4 +93,38 @@ private void process(Socket socket) throws IOException {
}
}

private void processV2(Socket socket) throws IOException {
DataInputX in = null;
DataOutputX out = null;
try {
in = new DataInputX(new BufferedInputStream(socket.getInputStream()));
out = new DataOutputX(new BufferedOutputStream(socket.getOutputStream()));

out.writeInt(NetCafe.TCP_AGENT_V2);
out.writeInt(objHash);
out.flush();

while (objHash == Configure.getInstance().objHash) {
byte[] buff = in.readIntBytes();

DataInputX in2 = new DataInputX(buff);
String cmd = in2.readText();
Pack parameter = (Pack) in2.readPack();

Pack res = ReqestHandlingProxy.process(cmd, parameter, in, out);
if (res != null) {
out.writeByte(TcpFlag.HasNEXT);

byte[] obuff = new DataOutputX().writePack(res).toByteArray();
out.writeIntBytes(obuff);
}
out.writeByte(TcpFlag.NoNEXT);
out.flush();
}
} finally {
FileUtil.close(in);
FileUtil.close(out);
}
}

}
Loading

0 comments on commit fdf3d03

Please sign in to comment.