Skip to content

Commit

Permalink
增加flushmethod命令,可以在需要的时候刷出tmethod.log
Browse files Browse the repository at this point in the history
  • Loading branch information
丁宇 committed Apr 23, 2012
1 parent 9bc396a commit f2a9f6d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 69 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/taobao/profile/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class Manager {
* 获取状态命令
*/
public static final String STATUS = "status";
/**
* 远程刷出方法数据
*/
public static final String FLUSHMETHOD = "flushmethod";
/**
* 是否用纳秒采集
*/
Expand Down Expand Up @@ -97,7 +101,7 @@ public class Manager {
* 将性能分析数据写出到磁盘
*/
private final DataDumpThread dumpThread;

/**
* 采样线程
*/
Expand Down Expand Up @@ -168,11 +172,11 @@ public void setSwitchProfile(boolean switchProfile) {
}

/**
* @return the switchProfile
*/
public boolean getSwitchProfile() {
return switchProfile.get();
}
* @return the switchProfile
*/
public boolean getSwitchProfile() {
return switchProfile.get();
}

/**
* @param canProfile
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/taobao/profile/client/TProfilerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public static String status(String server) {
return getStatus("status", server);
}

/**
* 远程刷出方法数据
*
* @param server
* ip
*/
public static void flushMethod(String server) {
doSend("flushmethod", server);
}

/**
* 建立远程连接并发送命令
*
Expand Down Expand Up @@ -150,6 +160,8 @@ public static void main(String[] args) {
start(args[0]);
} else if (args[1].toLowerCase().equals("stop")) {
stop(args[0]);
} else if (args[1].toLowerCase().equals("flushmethod")) {
flushMethod(args[0]);
} else {
System.out.println(status(args[0]));
}
Expand Down
37 changes: 29 additions & 8 deletions src/main/java/com/taobao/profile/runtime/MethodCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import java.util.Vector;

import com.taobao.profile.Manager;
import com.taobao.profile.Profiler;
import com.taobao.profile.utils.DailyRollingFileWriter;

/**
* 方法名缓存,用ID代替方法名进行剖析,提升性能
*
Expand Down Expand Up @@ -70,14 +74,31 @@ public synchronized static void UpdateMethodName(int id, String className, Strin
}

/**
* 取得方法名
*
* @param id
* @return
* 写出方法信息
*/
public static String getClasssMethodInfo(int id) {
MethodInfo method = mCacheMethods.get(id);
return method.toString();
}
public synchronized static void flushMethodData() {
DailyRollingFileWriter fileWriter = new DailyRollingFileWriter(Manager.METHOD_LOG_PATH);

fileWriter.append("instrumentclass:");
fileWriter.append(String.valueOf(Profiler.instrumentClassCount));
fileWriter.append(" instrumentmethod:");
fileWriter.append(String.valueOf(Profiler.instrumentMethodCount));
fileWriter.append("\n");

Vector<MethodInfo> vector = MethodCache.mCacheMethods;
int size = vector.size();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
sb.append(i);
sb.append(' ');
sb.append(vector.get(i).toString());
sb.append('\n');
fileWriter.append(sb.toString());
sb.setLength(0);
if ((i % 50) == 0) {
fileWriter.flushAppend();
}
}
fileWriter.closeFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.SocketException;

import com.taobao.profile.Manager;
import com.taobao.profile.runtime.MethodCache;

/**
* 对外提供Socket开关
Expand Down Expand Up @@ -50,6 +51,8 @@ public void run() {
Manager.instance().setSwitchProfile(true);
} else if (Manager.STATUS.equals(command)) {
write(child.getOutputStream());
} else if (Manager.FLUSHMETHOD.equals(command)) {
MethodCache.flushMethodData();
} else {
Manager.instance().setSwitchProfile(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.taobao.profile.Manager;
import com.taobao.profile.config.ProfConfig;
import com.taobao.profile.utils.MethodDump;
import com.taobao.profile.runtime.MethodCache;

/**
* 开始时间结束时间控制线程
Expand Down Expand Up @@ -115,7 +115,7 @@ public void run() {
} else {
Manager.instance().setCanProfile(false);
Manager.instance().setPauseProfile(true);
MethodDump.flushMethodData();
MethodCache.flushMethodData();
time = nextStartTime(startTime);
await(time);
}
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/com/taobao/profile/utils/MethodDump.java

This file was deleted.

0 comments on commit f2a9f6d

Please sign in to comment.