Skip to content

Commit fe09440

Browse files
committed
reorg-log code
1 parent 32373c5 commit fe09440

44 files changed

Lines changed: 39 additions & 923 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scouter.agent.java/src/scouter/agent/AgentTransformer.java‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
* limitations under the License.
1616
*/
1717
package scouter.agent;
18-
1918
import java.lang.instrument.ClassFileTransformer;
2019
import java.lang.instrument.IllegalClassFormatException;
2120
import java.security.ProtectionDomain;
2221
import java.util.ArrayList;
2322
import java.util.List;
24-
2523
import scouter.agent.asm.AddFieldASM;
2624
import scouter.agent.asm.ApicallASM;
2725
import scouter.agent.asm.ApicallInfoASM;
@@ -54,14 +52,11 @@
5452
import scouter.org.objectweb.asm.Opcodes;
5553
import scouter.util.FileUtil;
5654
import scouter.util.IntSet;
57-
5855
public class AgentTransformer implements ClassFileTransformer {
5956
public static ThreadLocal<ClassLoader> hookingCtx = new ThreadLocal<ClassLoader>();
6057
private static List<IASM> asms = new ArrayList<IASM>();
61-
6258
// hook 관련 설정이 변경되면 자동으로 변경된다.
6359
private static int hook_signature;
64-
6560
static {
6661
final Configure conf = Configure.getInstance();
6762
reload();
@@ -74,77 +69,61 @@ public void run() {
7469
hook_signature = conf.getHookSignature();
7570
}
7671
});
77-
7872
}
79-
8073
public static void reload() {
8174
Configure conf = Configure.getInstance();
82-
8375
List<IASM> temp = new ArrayList<IASM>();
84-
8576
if (conf.enable_hook_service) {
8677
temp.add(new HttpServiceASM());
8778
temp.add(new ServiceASM());
8879
}
89-
9080
if (conf.enable_hook_dbsql) {
9181
temp.add(new JDBCPreparedStatementASM());
9282
temp.add(new JDBCResultSetASM());
9383
temp.add(new JDBCStatementASM());
9484
temp.add(new SqlMapASM());
9585
temp.add(new UserTxASM());
9686
}
97-
9887
if (conf.enable_hook_dbconn) {
9988
temp.add(new JDBCConnectionOpenASM());
10089
temp.add(new JDBCDriverASM());
10190
temp.add(new InitialContextASM());
10291
}
103-
10492
if (conf.enable_hook_cap) {
10593
temp.add(new CapArgsASM());
10694
temp.add(new CapReturnASM());
10795
temp.add(new CapThisASM());
10896
}
109-
11097
if (conf.enable_hook_methods) {
11198
temp.add(new MethodASM());
11299
temp.add(new ApicallASM());
113100
temp.add(new ApicallInfoASM());
114101
temp.add(new SpringReqMapASM());
115102
}
116-
117103
if (conf.enable_hook_socket) {
118104
temp.add(new SocketASM());
119105
}
120-
121106
if (conf.enable_hook_jsp) {
122107
temp.add(new JspServletASM());
123108
}
124109
if (conf.enable_hook_async) {
125110
temp.add(new AddFieldASM());
126111
}
127-
128112
asms = temp;
129113
}
130-
131114
// //////////////////////////////////////////////////////////////
132115
// boot class이지만 Hooking되어야하는 클래스를 등록한다.
133116
private static IntSet asynchook = new IntSet();
134-
135117
static {
136118
asynchook.add("sun/net/www/protocol/http/HttpURLConnection".hashCode());
137119
asynchook.add("sun/net/www/http/HttpClient".hashCode());
138120
asynchook.add("java/net/Socket".hashCode());
139121
asynchook.add("javax/naming/InitialContext".hashCode());
140122
}
141-
142123
private Configure conf = Configure.getInstance();
143124
private Logger.FileLog bciOut;
144-
145125
public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
146126
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
147-
148127
try {
149128
hookingCtx.set(loader);
150129
if (className == null)
@@ -163,31 +142,25 @@ public byte[] transform(ClassLoader loader, String className, Class classBeingRe
163142
}
164143
//
165144
classfileBuffer = DirectPatch.patch(className, classfileBuffer);
166-
167145
ObjTypeDetector.check(className);
168-
169146
final ClassDesc classDesc = new ClassDesc();
170147
ClassReader cr = new ClassReader(classfileBuffer);
171148
cr.accept(new ClassVisitor(Opcodes.ASM4) {
172149
public void visit(int version, int access, String name, String signature, String superName,
173150
String[] interfaces) {
174151
classDesc.set(version, access, name, signature, superName, interfaces);
175152
}
176-
177153
@Override
178154
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
179155
classDesc.anotation += desc;
180156
return super.visitAnnotation(desc, visible);
181157
}
182-
183158
}, 0);
184-
185159
if (AsmUtil.isInterface(classDesc.access)) {
186160
return null;
187161
}
188162
classDesc.classBeingRedefined = classBeingRedefined;
189163
ClassWriter cw = getClassWriter(classDesc);
190-
191164
ClassVisitor cv = cw;
192165
List<IASM> workAsms = asms;
193166
for (int i = 0, max = workAsms.size(); i < max; i++) {
@@ -197,7 +170,6 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
197170
cr.accept(cv, ClassReader.EXPAND_FRAMES);
198171
classfileBuffer = cw.toByteArray();
199172
cv = cw = getClassWriter(classDesc);
200-
201173
if (conf.debug_asm) {
202174
if (this.bciOut == null) {
203175
this.bciOut = new Logger.FileLog("./scouter.bci");
@@ -213,10 +185,8 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
213185
} finally {
214186
hookingCtx.set(null);
215187
}
216-
217188
return null;
218189
}
219-
220190
private ClassWriter getClassWriter(final ClassDesc classDesc) {
221191
ClassWriter cw;
222192
switch (classDesc.version) {
@@ -233,11 +203,8 @@ private ClassWriter getClassWriter(final ClassDesc classDesc) {
233203
}
234204
return cw;
235205
}
236-
237206
private void dump(String className, byte[] bytes) {
238207
String fname = "/tmp/" + className.replace('/', '_');
239208
FileUtil.save(fname, bytes);
240-
241209
}
242-
243210
}

‎scouter.agent.java/src/scouter/agent/BackJobs.java‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
* limitations under the License.
1616
*/
1717
package scouter.agent;
18-
1918
import scouter.util.StringEnumer;
2019
import scouter.util.StringKeyLinkedMap;
2120
import scouter.util.ThreadUtil;
22-
2321
public class BackJobs extends Thread {
24-
2522
private static BackJobs instance = null;
26-
2723
public final static synchronized BackJobs getInstance() {
2824
if (instance == null) {
2925
instance = new BackJobs();
@@ -33,23 +29,18 @@ public final static synchronized BackJobs getInstance() {
3329
}
3430
return instance;
3531
}
36-
3732
protected BackJobs() {
3833
}
39-
4034
public class JobW {
4135
Runnable job;
4236
long lastExTime;
4337
int interval;
44-
4538
public JobW(Runnable job, int interval) {
4639
this.job = job;
4740
this.interval = interval;
4841
}
4942
}
50-
5143
private StringKeyLinkedMap<JobW> jobs = new StringKeyLinkedMap<JobW>();
52-
5344
/**
5445
* 반복적으로 실행할 잡을 등록한다.
5546
*
@@ -65,15 +56,11 @@ public void put(String id, int interval, Runnable job) {
6556
public void remove(String id) {
6657
jobs.remove(id);
6758
}
68-
6959
public void shutdown() {
7060
running = false;
7161
}
72-
7362
private boolean running = true;
74-
7563
public void run() {
76-
7764
while (running) {
7865
ThreadUtil.sleep(1000);
7966
try {
@@ -82,9 +69,7 @@ public void run() {
8269
Logger.println("A109", t);
8370
}
8471
}
85-
8672
}
87-
8873
private void process() {
8974
StringEnumer en = jobs.keys();
9075
while (en.hasMoreElements()) {

0 commit comments

Comments
 (0)