Skip to content

Commit

Permalink
Fix issue alibaba#10
Browse files Browse the repository at this point in the history
@dengqiao
第二个问题,重传一下jar包
第三个问题,端口号加到配置文件中了。打开端口的目的是为了远程控制,如果一台物理机启动多个Java实例的话,远程控制会比较麻烦。所以这块修改了,远程控制时端口需要在命令行中指定,没有默认值
  • Loading branch information
jlusdy committed Oct 29, 2012
1 parent beca8d1 commit ccafab1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 53 deletions.
1 change: 1 addition & 0 deletions dist/profile.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ endProfTime = 11:00:00
eachProfUseTime = 5
eachProfIntervalTime = 50
samplerIntervalTime = 20
port = 50000
debugMode = false
needNanoTime = false
ignoreGetSetMethod = true
Expand Down
Binary file modified dist/tprofiler.jar
Binary file not shown.
12 changes: 6 additions & 6 deletions src/main/java/com/taobao/profile/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Manager {
/**
* 远程连接端口
*/
public static final int PORT = 50000;
public static int PORT;
/**
* 开始命令
*/
Expand Down Expand Up @@ -130,6 +130,7 @@ public void initialization() {
String now = df.format(new Date());
moreThanEndTime = (now.compareTo(profConfig.getEndProfTime()) > 0 ) ? true : false;
isDebugMode = profConfig.isDebugMode();
PORT = profConfig.getPort();

setProfFilter();
}
Expand All @@ -156,21 +157,21 @@ public static boolean isIgnoreGetSetMethod() {
}

/**
* @param timeFlag the timeFlag to set
* @param value the timeFlag to set
*/
public void setTimeFlag(boolean value) {
timeFlag = value;
}

/**
* @param switchFlag the switchFlag to set
* @param value the switchFlag to set
*/
public void setSwitchFlag(boolean value) {
switchFlag = value;
}

/**
* @param profileFlag the profileFlag to set
* @param value the profileFlag to set
*/
public void setProfileFlag(boolean value) {
profileFlag = value;
Expand Down Expand Up @@ -252,8 +253,7 @@ private void setProfFilter() {

/**
* 启动内部线程
*
* @param config
*
*/
public void startupThread() {
controlThread = new TimeControlThread(profConfig);
Expand Down
98 changes: 51 additions & 47 deletions src/main/java/com/taobao/profile/client/TProfilerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,58 @@
*/
public class TProfilerClient {

/**
/**
* 远程打开
*
* @param server
* ip
*/
public static void start(String server) {
doSend(Manager.START, server);
*
* @param server
* @param port
*/
public static void start(String server, int port) {
doSend(Manager.START, server, port);
}

/**
* 远程关闭
*
* @param server
* ip
*/
public static void stop(String server) {
doSend(Manager.STOP, server);
*
* @param server
* @param port
*/
public static void stop(String server, int port) {
doSend(Manager.STOP, server, port);
}

/**
* 获取状态
*
* @param server
* @return
*/
public static String status(String server) {
return getStatus(Manager.STATUS, server);
*
* @param server
* @param port
* @return
*/
public static String status(String server, int port) {
return getStatus(Manager.STATUS, server, port);
}

/**
* 远程刷出方法数据
*
* @param server
* ip
*/
public static void flushMethod(String server) {
doSend(Manager.FLUSHMETHOD, server);
*
* @param server
* @param port
*/
public static void flushMethod(String server, int port) {
doSend(Manager.FLUSHMETHOD, server, port);
}

/**
* 建立远程连接并发送命令
*
* @param command
* @param server
*/
private static void doSend(String command, String server) {
*
* @param command
* @param server
* @param port
*/
private static void doSend(String command, String server, int port) {
Socket socket = null;
try {
socket = new Socket(server, Manager.PORT);
socket = new Socket(server, port);
OutputStream os = socket.getOutputStream();
BufferedOutputStream out = new BufferedOutputStream(os);
out.write(command.getBytes());
Expand All @@ -98,15 +100,16 @@ private static void doSend(String command, String server) {

/**
* 建立远程连接并发送命令
*
* @param command
* @param server
* @return 0:运行状态 1:停止状态
*/
private static String getStatus(String command, String server) {
*
* @param command
* @param server
* @param port
* @return
*/
private static String getStatus(String command, String server, int port) {
Socket socket = null;
try {
socket = new Socket(server, Manager.PORT);
socket = new Socket(server, port);
OutputStream os = socket.getOutputStream();
BufferedOutputStream out = new BufferedOutputStream(os);
out.write(command.getBytes());
Expand Down Expand Up @@ -154,18 +157,19 @@ private static String read(InputStream in) throws IOException {
* @param args
*/
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("Usage: <server ip> <command[start/stop/status/flushmethod]>");
if (args.length != 3) {
System.err.println("Usage: <server ip> <server port> <command[start/stop/status/flushmethod]>");
return;
}
if (args[1].toLowerCase().equals(Manager.START)) {
start(args[0]);
} else if (args[1].toLowerCase().equals(Manager.STOP)) {
stop(args[0]);
} else if (args[1].toLowerCase().equals(Manager.FLUSHMETHOD)) {
flushMethod(args[0]);
int port = Integer.valueOf(args[1]);
if (args[2].toLowerCase().equals(Manager.START)) {
start(args[0], port);
} else if (args[2].toLowerCase().equals(Manager.STOP)) {
stop(args[0], port);
} else if (args[2].toLowerCase().equals(Manager.FLUSHMETHOD)) {
flushMethod(args[0], port);
} else {
System.out.println(status(args[0]));
System.out.println(status(args[0], port));
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/taobao/profile/config/ProfConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class ProfConfig {
*/
private boolean debugMode;

/**
* Socket端口号配置
*/
private int port;

/**
* 构造方法
*/
Expand Down Expand Up @@ -134,6 +139,8 @@ private void parseProperty(File path) {
String ignoreGetSetMethod = resource.getProperty("ignoreGetSetMethod");
String excludeClassLoader = resource.getProperty("excludeClassLoader");
String debugMode = resource.getProperty("debugMode");
String port = resource.getProperty("port");
setPort(port == null ? 50000 : Integer.valueOf(port));
setDebugMode("true".equals(debugMode));
setExcludeClassLoader(excludeClassLoader);
setExcludePackageStartsWith(excludePackageStartsWith);
Expand Down Expand Up @@ -189,6 +196,8 @@ private void parse(String configName) {
String ignoreGetSetMethod = resource.getString("ignoreGetSetMethod");
String excludeClassLoader = resource.getString("excludeClassLoader");
String debugMode = resource.getString("debugMode");
String port = resource.getString("port");
setPort(port == null ? 50000 : Integer.valueOf(port));
setDebugMode("true".equals(debugMode));
setExcludeClassLoader(excludeClassLoader);
setExcludePackageStartsWith(excludePackageStartsWith);
Expand Down Expand Up @@ -418,4 +427,12 @@ public boolean isDebugMode() {
public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}
}
1 change: 1 addition & 0 deletions src/main/resources/profile.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ endProfTime = 11:00:00
eachProfUseTime = 5
eachProfIntervalTime = 50
samplerIntervalTime = 20
port = 50000
debugMode = false
needNanoTime = false
ignoreGetSetMethod = true
Expand Down

0 comments on commit ccafab1

Please sign in to comment.