Skip to content

Commit 30b3680

Browse files
author
丁建水
committed
修改javaagent包结构为java项目默认包结构
1 parent dcb7248 commit 30b3680

File tree

241 files changed

+62385
-0
lines changed

Some content is hidden

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

241 files changed

+62385
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @(#)Agent.java 2015-7-24 上午09:49:34
3+
* javaagent
4+
* Copyright 2015 wenshuo, Inc. All rights reserved.
5+
* wenshuo PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6+
*/
7+
package com.wenshuo.agent;
8+
import java.lang.instrument.Instrumentation;
9+
import com.wenshuo.agent.log.ExecuteLogUtils;
10+
import com.wenshuo.agent.transformer.AgentLogClassFileTransformer;
11+
12+
/**
13+
* Agent
14+
*
15+
* @author dingjsh
16+
*/
17+
public class Agent {
18+
19+
public static void premain(String agentArs, Instrumentation inst) {
20+
System.out.println("javaagent启动成功,将自动记录方法的执行次数和时间");
21+
// 初始化配置
22+
ConfigUtils.initProperties(agentArs);
23+
ExecuteLogUtils.init();
24+
inst.addTransformer(new AgentLogClassFileTransformer());
25+
}
26+
27+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* @(#)AgentUtils.java 2015-7-27 下午05:26:24
3+
* javaagent
4+
* Copyright 2015 wenshuo, Inc. All rights reserved.
5+
* wenshuo PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6+
*/
7+
package com.wenshuo.agent;
8+
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.io.OutputStream;
14+
import java.io.Writer;
15+
16+
/**
17+
* AgentUtils
18+
*
19+
* @author dingjsh
20+
* @time 2015-7-27下午05:26:24
21+
*/
22+
public class AgentUtils {
23+
24+
/**
25+
* <p>
26+
* Checks if a String is whitespace, empty ("") or null.
27+
* </p>
28+
*
29+
* <pre>
30+
* StringUtils.isBlank(null) = true
31+
* StringUtils.isBlank("") = true
32+
* StringUtils.isBlank(" ") = true
33+
* StringUtils.isBlank("bob") = false
34+
* StringUtils.isBlank(" bob ") = false
35+
* </pre>
36+
*
37+
* @param str the String to check, may be null
38+
* @return <code>true</code> if the String is null, empty or whitespace
39+
* @since 2.0
40+
*/
41+
public static boolean isBlank(String str) {
42+
int strLen;
43+
if (str == null || (strLen = str.length()) == 0) {
44+
return true;
45+
}
46+
for (int i = 0; i < strLen; i++) {
47+
if (!Character.isWhitespace(str.charAt(i))) {
48+
return false;
49+
}
50+
}
51+
return true;
52+
}
53+
54+
/**
55+
* <p>
56+
* Checks if a String is not empty (""), not null and not whitespace only.
57+
* </p>
58+
*
59+
* <pre>
60+
* StringUtils.isNotBlank(null) = false
61+
* StringUtils.isNotBlank("") = false
62+
* StringUtils.isNotBlank(" ") = false
63+
* StringUtils.isNotBlank("bob") = true
64+
* StringUtils.isNotBlank(" bob ") = true
65+
* </pre>
66+
*
67+
* @param str the String to check, may be null
68+
* @return <code>true</code> if the String is not empty and not null and not
69+
* whitespace
70+
* @since 2.0
71+
*/
72+
static boolean isNotBlank(String str) {
73+
return !isBlank(str);
74+
}
75+
76+
/**
77+
* Unconditionally close an <code>InputStream</code>.
78+
* <p>
79+
* Equivalent to {@link InputStream#close()}, except any exceptions will be
80+
* ignored. This is typically used in finally blocks.
81+
*
82+
* @param input the InputStream to close, may be null or already closed
83+
*/
84+
static void closeQuietly(InputStream input) {
85+
try {
86+
if (input != null) {
87+
input.close();
88+
}
89+
} catch (IOException ioe) {
90+
// ignore
91+
}
92+
}
93+
94+
public static int copy(InputStream input, OutputStream output)
95+
throws IOException {
96+
long count = copyLarge(input, output);
97+
if (count > Integer.MAX_VALUE) {
98+
return -1;
99+
}
100+
return (int) count;
101+
}
102+
103+
private static long copyLarge(InputStream input, OutputStream output)
104+
throws IOException {
105+
byte[] buffer = new byte[4096];
106+
long count = 0;
107+
int n;
108+
while (-1 != (n = input.read(buffer))) {
109+
output.write(buffer, 0, n);
110+
count += n;
111+
}
112+
return count;
113+
}
114+
115+
// read toByteArray
116+
//-----------------------------------------------------------------------
117+
118+
/**
119+
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
120+
* <p>
121+
* This method buffers the input internally, so there is no need to use a
122+
* <code>BufferedInputStream</code>.
123+
*
124+
* @param input the <code>InputStream</code> to read from
125+
* @return the requested byte array
126+
* @throws NullPointerException if the input is null
127+
* @throws IOException if an I/O error occurs
128+
*/
129+
public static byte[] toByteArray(InputStream input) throws IOException {
130+
ByteArrayOutputStream output = new ByteArrayOutputStream();
131+
copy(input, output);
132+
return output.toByteArray();
133+
}
134+
135+
/**
136+
* Unconditionally close a <code>Writer</code>.
137+
* <p>
138+
* Equivalent to {@link Writer#close()}, except any exceptions will be ignored.
139+
* This is typically used in finally blocks.
140+
*
141+
* @param output the Writer to close, may be null or already closed
142+
*/
143+
public static void closeQuietly(Writer output) {
144+
try {
145+
if (output != null) {
146+
output.close();
147+
}
148+
} catch (IOException ioe) {
149+
// ignore
150+
}
151+
}
152+
153+
/**
154+
* Makes a directory, including any necessary but nonexistent parent
155+
* directories. If there already exists a file with specified name or
156+
* the directory cannot be created then an exception is thrown.
157+
*
158+
* @param directory directory to create, must not be <code>null</code>
159+
* @throws NullPointerException if the directory is <code>null</code>
160+
* @throws IOException if the directory cannot be created
161+
*/
162+
public static void forceMkdir(File directory) throws IOException {
163+
if (directory.exists()) {
164+
if (directory.isFile()) {
165+
String message =
166+
"File "
167+
+ directory
168+
+ " exists and is "
169+
+ "not a directory. Unable to create directory.";
170+
throw new IOException(message);
171+
}
172+
} else {
173+
if (!directory.mkdirs()) {
174+
String message =
175+
"Unable to create directory " + directory;
176+
throw new IOException(message);
177+
}
178+
}
179+
}
180+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* @(#)ConfigConsts.java 2015-7-27 下午06:06:23
3+
* javaagent
4+
* Copyright 2015 wenshuo, Inc. All rights reserved.
5+
* wenshuo PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6+
*/
7+
package com.wenshuo.agent;
8+
9+
/**
10+
* ConfigConsts
11+
*
12+
* @author dingjsh
13+
* @time 2015-7-27下午06:06:23
14+
*/
15+
public interface ConfigConsts {
16+
17+
String EXCLUDE_PACKAGE_DEFAULT = "agent.exclude.package.default";
18+
19+
String EXCLUDE_PACKAGE = "agent.exclude.package";
20+
21+
String INCLUDE_PACKAGE = "agent.include.package";
22+
23+
String LOG_FILE = "agent.log.file";
24+
25+
String LOG_INTERVAL_SECONDS = "agent.log.interval.seconds";
26+
27+
String EXCLUDE_CLASS_REGEX = "agent.exclude.class.regex";
28+
29+
String EXCLUDE_CLASS_REGEX_DEFAULT = "agent.exclude.class.regex.default";
30+
31+
String LOG_AVG_EXECUTE_TIME = "agent.log.avg.execute.time";
32+
33+
String POJO_MONITOR_OPEN = "agent.pojo.monitor.open";
34+
35+
String LOG_TIME_NANO = "agent.log.nano";
36+
37+
int DEFAULT_LOG_INTERVAL = 600;
38+
39+
}

0 commit comments

Comments
 (0)