--- /dev/null
+package org.tizen.dynamicanalyzer.protocol;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.util.CommonUtil;
+import org.tizen.dynamicanalyzer.util.Logger;
+
+public class DebugLog {
+ private static boolean PRINT_DATA_LOG_TOFILE = true;
+
+ // for debugging
+ private static PrintWriter dataChannelWriter = null;
+
+ public static void openDataChannelWriter() {
+ dataChannelWriter = null;
+
+ if (PRINT_DATA_LOG_TOFILE) {
+ File logPath = new File(PathManager.DA_DEBUG_DATA_CHANNEL_LOG_FILE);
+ if (logPath.exists()) {
+ logPath.delete();
+ }
+
+ try {
+ dataChannelWriter = new PrintWriter(new BufferedWriter(new FileWriter(logPath)),
+ true);
+ } catch (IOException e) {
+ Logger.exception(e);
+ }
+ }
+ }
+
+ public static void closeDataChannelWriter() {
+ if (dataChannelWriter != null) {
+ CommonUtil.tryClose(dataChannelWriter);
+ dataChannelWriter = null;
+ }
+ }
+
+ public static void printData(int indent, String format, Object... objects) {
+ if (dataChannelWriter != null) {
+ switch (indent) {
+ case 0:
+ dataChannelWriter.printf(format, objects);
+ break;
+ case 1:
+ dataChannelWriter.printf("\t" + format, objects);
+ break;
+ case 2:
+ dataChannelWriter.printf("\t\t" + format, objects);
+ break;
+ default: // max indent is 2
+ dataChannelWriter.printf("\t\t" + format, objects);
+ break;
+ }
+ }
+ }
+
+ public static void printData0(String format, Object... objects) {
+ printData(0, format, objects);
+ }
+
+ public static void printData1(String format, Object... objects) {
+ printData(1, format, objects);
+ }
+
+ public static void printData2(String format, Object... objects) {
+ printData(2, format, objects);
+ }
+}
*/
package org.tizen.dynamicanalyzer.protocol;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import org.tizen.dynamicanalyzer.constant.CommonConstants;
import org.tizen.dynamicanalyzer.protocol.p30.ProtocolConfig30;
import org.tizen.dynamicanalyzer.protocol.p40.ProtocolConfig40;
// version names
private static final String[] versions = { "3.0", "4.0" };
+ // data channel message name map for printing debug info
+ private static final Map<Integer, String> dataMsgNameMap;
+
+ static {
+ Map<Integer, String> tempMap = new HashMap<Integer, String>();
+
+ // data message id
+ tempMap.put(0x0001, "MSG_DATA_PROCESS_INFO");
+ tempMap.put(0x0002, "MSG_DATA_TERMINATE");
+ tempMap.put(0x0003, "MSG_DATA_ERROR");
+ tempMap.put(0x0004, "MSG_DATA_SAMPLE");
+ tempMap.put(0x0005, "MSG_DATA_SYSTEM");
+ tempMap.put(0x0006, "MSG_DATA_IMAGE");
+ tempMap.put(0x0007, "MSG_DATA_RECORD");
+ tempMap.put(0x0008, "MSG_FUNCTION_ENTRY");
+ tempMap.put(0x0009, "MSG_FUNCTION_EXIT");
+ tempMap.put(0x0010, "MSG_CONTEXT_SWITCH_ENTRY");
+ tempMap.put(0x0011, "MSG_CONTEXT_SWITCH_EXIT");
+ tempMap.put(0x0012, "MSG_PROCESS_MAP");
+ tempMap.put(0x0013, "MSG_PROCESS_UNMAP");
+ tempMap.put(0x0014, "MSG_PROCESS_COMM");
+
+ // data probe message id
+ tempMap.put(0x0101, "MSG_PROBE_MIN");
+ tempMap.put(0x0101, "MSG_PROBE_MEMORY");
+ tempMap.put(0x0102, "MSG_PROBE_UICONTROL");
+ tempMap.put(0x0103, "MSG_PROBE_UIEVENT");
+ tempMap.put(0x0104, "MSG_PROBE_FILE");
+ tempMap.put(0x0105, "MSG_PROBE_LIFECYCLE");
+ tempMap.put(0x0106, "MSG_PROBE_SCREENSHOT");
+ tempMap.put(0x0107, "MSG_PROBE_SCENE");
+ tempMap.put(0x0108, "MSG_PROBE_THREAD");
+ tempMap.put(0x0109, "MSG_PROBE_CUSTOM");
+ tempMap.put(0x0110, "MSG_PROBE_SYNC");
+ tempMap.put(0x0111, "MSG_PROBE_NETWORK");
+ tempMap.put(0x0112, "MSG_PROBE_GLES20");
+
+ dataMsgNameMap = Collections.unmodifiableMap(tempMap);
+ }
+
// convert version string to specific integer value equal or greater than zero
// return negative value if version string is not found
public static int getVersionValue(String version) {
} else { // unknown protocol
throw new UnknownProtocolException();
}
-
+
return configs;
}
+
+ public static String getDataMessageName(int msgid) {
+ String name = dataMsgNameMap.get(Integer.valueOf(msgid));
+ if (name == null) {
+ return CommonConstants.EMPTY;
+ } else {
+ return name;
+ }
+ }
}
*/
package org.tizen.dynamicanalyzer.swap.logparser;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
import org.tizen.dynamicanalyzer.common.AnalyzerManager;
import org.tizen.dynamicanalyzer.common.Global;
-import org.tizen.dynamicanalyzer.common.path.PathManager;
import org.tizen.dynamicanalyzer.control.DataThread;
import org.tizen.dynamicanalyzer.project.BinaryInfo;
import org.tizen.dynamicanalyzer.project.LibraryObject;
import org.tizen.dynamicanalyzer.project.ProcessInformation;
import org.tizen.dynamicanalyzer.project.ProcessMemoryMap;
import org.tizen.dynamicanalyzer.project.Project;
+import org.tizen.dynamicanalyzer.protocol.DebugLog;
import org.tizen.dynamicanalyzer.protocol.ProtocolConstants;
-import org.tizen.dynamicanalyzer.swap.model.DATime;
import org.tizen.dynamicanalyzer.swap.model.data.LogData;
+import org.tizen.dynamicanalyzer.swap.model.data.MemoryMapData;
+import org.tizen.dynamicanalyzer.swap.model.data.ProcessAddInfoData;
+import org.tizen.dynamicanalyzer.swap.model.data.ProcessInfoData;
import org.tizen.dynamicanalyzer.ui.thread.data.ThreadDataManager;
-import org.tizen.dynamicanalyzer.util.CommonUtil;
import org.tizen.dynamicanalyzer.util.Logger;
public class MessageParser extends DataThread<LogData> {
private static MessageParser instance = new MessageParser();
- private static boolean PRINT_DATA_LOG_TOFILE = false;
-
/* Message Buffer max length */
private static final int MSG_BUFFER_MAX = 5000;
private static final int MSG_BUFFER_TIMER_DELAY = 5;
@Override
public void run() {
- PrintWriter printWriter = getDebugWriter();
+ DebugLog.openDataChannelWriter();
Thread curThread = Thread.currentThread();
try {
break;
}
- printLog(printWriter, log);
-
processMessage(log);
}
} finally {
sendDataToLogParser();
pushEOQ();
- if (printWriter != null) {
- CommonUtil.tryClose(printWriter);
- }
- }
- }
-
- private PrintWriter getDebugWriter() {
- PrintWriter printWriter = null;
-
- if (PRINT_DATA_LOG_TOFILE) {
- File logPath = new File(PathManager.DA_DEBUG_DATA_CHANNEL_LOG_FILE);
- if (logPath.exists()) {
- logPath.delete();
- }
-
- try {
- printWriter = new PrintWriter(new BufferedWriter(new FileWriter(logPath)), true);
- } catch (IOException e) {
- Logger.exception(e);
- }
- }
-
- return printWriter;
- }
-
- private void printLog(PrintWriter printWriter, LogData log) {
- if (printWriter != null) {
- int payloadSize = log.getPayloadSize();
- byte[] payload = log.getPayload();
- printWriter.printf("%d %d %d %d :", log.getMsgID(), log.getSeq(), log.getTime(),
- payloadSize);
- for (int i = 0; i < payloadSize; i++)
- printWriter.printf("%02x ", payload[i]);
- printWriter.printf("\n");
+ DebugLog.closeDataChannelWriter();
}
}
// return false if message id is unknown
private boolean processMessage(LogData log) {
- boolean bret = true;
+ boolean bret = log.parsePublic(Global.getProject().getProfilingStartTime());
int id = log.getMsgID();
+
switch (id) {
case ProtocolConstants.MSG_DATA_PROCESS_INFO:
// setting process info
- processProcessInfo(log);
+ if (bret) {
+ processProcessInfo(log);
+ }
break;
case ProtocolConstants.MSG_PROCESS_MAP:
case ProtocolConstants.MSG_PROCESS_UNMAP:
- memoryMapChanged(log);
+ if (bret) {
+ memoryMapChanged(log);
+ }
break;
case ProtocolConstants.MSG_DATA_TERMINATE:
- processTerminate();
+ if (bret) {
+ processTerminate();
+ }
break;
case ProtocolConstants.MSG_DATA_ERROR:
// process error message
case ProtocolConstants.MSG_CONTEXT_SWITCH_ENTRY:
case ProtocolConstants.MSG_CONTEXT_SWITCH_EXIT:
case ProtocolConstants.MSG_DATA_RECORD:
- if (AnalyzerManager.isProcessInfoArrived()) {
- if (log.parsePublic(Global.getProject().getProfilingStartTime())) {
- sendBuffer.add(log);
- }
+ if (AnalyzerManager.isProcessInfoArrived() && bret) {
+ sendBuffer.add(log);
}
break;
case ProtocolConstants.MSG_PROCESS_COMM:
- processAddInfo(log);
+ if (bret) {
+ processAddInfo(log);
+ }
break;
case ProtocolConstants.MSG_DATA_IMAGE:
// process image message
break;
default:
if (id >= ProtocolConstants.MSG_PROBE_MIN) { // MSG_PROBE
- if (AnalyzerManager.isProcessInfoArrived()) {
- if (log.parsePublic(Global.getProject().getProfilingStartTime())) {
- sendBuffer.add(log);
- }
+ if (AnalyzerManager.isProcessInfoArrived() && bret) {
+ sendBuffer.add(log);
}
} else {
// unknown message id
return bret;
}
- private void processProcessInfo(LogData log) {
+ private void processProcessInfo(LogData plog) {
Project project = Global.getProject();
+ ProcessInfoData log = (ProcessInfoData) plog;
- int pid = log.getInt();
- String commandLineName = log.getString();
- int ppid = log.getInt();
- int sec = log.getInt();
- int nano = log.getInt();
- long lowAddr = log.getLong();
- long highAddr = log.getLong();
- String targetBinaryPath = log.getString();
- int dependentLibCount = log.getInt();
-
- DATime capturedTime = new DATime(sec, nano);
- DATime profileStartTime = project.getProfilingStartTime();
- DATime subTime = capturedTime.subtract(profileStartTime);
+ int pid = log.getPid();
+ long starttime = log.getStartTime();
+ // get process info or make one if necessary
ProcessInformation pinfo = project.getProcessInformation(pid);
if (null == pinfo) {
pinfo = new ProcessInformation();
pinfo.setPid(pid);
- pinfo.setPpid(ppid);
- pinfo.setStartTime(subTime.getLongTime());
- pinfo.setProcessName(commandLineName);
+ pinfo.setPpid(log.getPpid());
+ pinfo.setStartTime(starttime);
+ pinfo.setProcessName(log.getCmdname());
project.putProcessInformation(pinfo);
pinfo.setDropLog(true);
}
pinfo.setMappingState(true);
- ProcessMemoryMap pMap = new ProcessMemoryMap(pinfo.getPid(), subTime.getLongTime());
+ // make process memory map of the moment
+ ProcessMemoryMap pMap = new ProcessMemoryMap(pinfo.getPid(), starttime);
pinfo.addProcessMemoryMap(pMap);
+ List<LibraryObject> libObjects = log.getLibObjects();
+ int dependentLibCount = libObjects.size();
for (int i = 0; i < dependentLibCount; i++) {
- long lowestAddr = log.getLong();
- long highestAddr = log.getLong();
- String libPath = log.getString();
-
- LibraryObject libObj = new LibraryObject(project.getDeviceStatusInfo()
- .getBinaryInfo(libPath).getID(), lowestAddr, highestAddr);
-
- pMap.addLibraryMap(libObj);
+ pMap.addLibraryMap(libObjects.get(i));
}
- Logger.debug("process info start time : " + capturedTime.getSec() + " "
- + capturedTime.getNano());
-
+ // set main binary of process
pMap.setMainBinary(new LibraryObject(project.getDeviceStatusInfo()
- .getBinaryInfo(targetBinaryPath).getID(), lowAddr, highAddr));
+ .getBinaryInfo(log.getBinaryPath()).getID(), log.getLowAddr(), log.getHighAddr()));
AnalyzerManager.setProcessInfoArrived(true);
+ // TODO : move this line to ThreadDataManager
// make main thread in thread chart
ThreadDataManager.getInstance().getThreadDataMaker().createMainThreadItem(pid);
}
- private void memoryMapChanged(LogData log) {
+ private void memoryMapChanged(LogData plog) {
Project project = Global.getProject();
+ MemoryMapData log = (MemoryMapData) plog;
- int msgID = log.getMsgID();
-
- /** parsing */
- int pid = log.getInt();
- long lowAddr = log.getLong();
- long highAddr = log.getLong();
-
+ int pid = log.getPid();
ProcessInformation pinfo = project.getProcessInformation(pid);
if (null == pinfo) {
// bug!!!
ProcessMemoryMap lastMap = pinfo.getLastProcessMemoryMap();
if (lastMap != null) {
+ int msgID = log.getMsgID();
+ long lowAddr = log.getLowAddr();
+ long highAddr = log.getHighAddr();
+
if (msgID == ProtocolConstants.MSG_PROCESS_MAP) {
// update to last memory map
- String libPath = log.getString();
+ String libPath = log.getLibPath();
BinaryInfo bininfo = project.getDeviceStatusInfo().getBinaryInfo(libPath);
LibraryObject libObj = new LibraryObject(bininfo.getID(), lowAddr, highAddr);
pinfo.setMappingState(true);
} else {
- DATime changeTime = new DATime(log.getSec(), log.getNano());
- DATime profileStartTime = project.getProfilingStartTime();
- DATime subTime = changeTime.subtract(profileStartTime);
-
if (pinfo.isMapping()) {
// make new memory map
- ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(),
- subTime.getLongTime());
+ ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(), log.getTime());
pinfo.addProcessMemoryMap(newMap);
newMap.copy(lastMap);
newMap.removeLibrary(lowAddr, highAddr);
} else {
// update captured time of last memory map
- pinfo.updateProcessMemoryMap(lastMap, subTime.getLongTime());
+ pinfo.updateProcessMemoryMap(lastMap, log.getTime());
// remove from map
lastMap.removeLibrary(lowAddr, highAddr);
}
}
- private void processAddInfo(LogData log) {
+ private void processAddInfo(LogData plog) {
// process command line name is changed (/proc/<pid>/cmdline)
Project project = Global.getProject();
+ ProcessAddInfoData log = (ProcessAddInfoData) plog;
- int pid = log.getInt();
- String name = log.getString();
-
+ int pid = log.getPid();
ProcessInformation process = project.getProcessInformation(pid);
if (null != process) {
- process.setProcessName(name);
+ process.setProcessName(log.getCmdname());
}
}