import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
import org.tizen.dynamicanalyzer.common.AnalyzerManager;
import org.tizen.dynamicanalyzer.common.DAResult;
+import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
import org.tizen.dynamicanalyzer.common.Global;
import org.tizen.dynamicanalyzer.common.UIMode;
import org.tizen.dynamicanalyzer.common.path.PathManager;
import org.tizen.dynamicanalyzer.communicator.DeviceManager;
import org.tizen.dynamicanalyzer.project.PackageInfo;
import org.tizen.dynamicanalyzer.setting.SettingDataManager;
+import org.tizen.dynamicanalyzer.setting.TargetData;
import org.tizen.dynamicanalyzer.setting.Template;
import org.tizen.dynamicanalyzer.util.InternalLogger;
import org.tizen.dynamicanalyzer.util.Logger;
static {
// Initialize DA Logger
- Logger.init(InternalLogger.WARNING);
+ Logger.init(InternalLogger.DEBUG);
// Check if Platform IDE exists and if so make the native platform
// functionality available.
}
/**
+ * Make DA to check currently connected devices
+ */
+ private static void loadConnectedDevices() {
+ DeviceManager.addDeviceListener();
+ DeviceManager.loadDevices();
+ }
+
+ /**
* Selects device by its serial number.
*
* @param serial device serial number
}
/**
+ * Selects application by its name.
+ *
+ * @param application name
+ * @return <code>true</code> on success
+ */
+ public static boolean selectApp(String appName) {
+ DeviceInfo devInfo = Global.getCurrentDeviceInfo();
+ if (devInfo == null) {
+ Logger.warning("DA failed to set device for " + appName + " application");
+ return false;
+ }
+ DACommunicator.updateAppListFromTarget();
+ PackageInfo pkgInfo = devInfo.getPkgInfoByLabel(appName);
+ if (pkgInfo == null) {
+ Logger.warning("DA failed to set application " + appName);
+ return false;
+ }
+ Global.setCurrentApplication(pkgInfo);
+ List<String> binPaths = pkgInfo.getProcessInformation();
+ pkgInfo.getBinaryInformation(binPaths);
+ if (!pkgInfo.isPossibleToTrace()) {
+ Logger.warning("DA is not able to trace application " + appName);
+ return false;
+ }
+ devInfo.setSelectedPackageLabel(appName);
+ return true;
+ }
+
+ /**
+ * Selects non-custom template to be used for tracing by given Template
+ * value.
+ *
+ * @param template Template instance
+ * @return <code>true</code> on success
+ */
+ private static boolean selectTemplate(Template template) {
+ // TODO Support custom template selection or other way to select
+ // features instead of templates
+ if (template == Template.TEMPLATE_CUSTOM)
+ return false;
+ TargetData target = SettingDataManager.INSTANCE.getTarget(null);
+ target.setSelectedTemplate(template);
+ target.changeSelectedFeatureList(template);
+ return true;
+ }
+
+ /**
* Helper function for packages list extraction from selected device.
*
* @param dev IDevice object presenting selected device
* @return result of async start tracing task
* @throws ConnectException in case of connection error
*/
- public static DAResult startTracing(TracingArguments args) throws ConnectException {
+ public static DAResult startTracingProcess(TracingArguments args) throws ConnectException {
ProcessManagerMBean pmProxy = getPMProxyInstance();
return pmProxy.startTracing(args);
* @return result of stop tracing request
* @throws ConnectException in case of connection error
*/
- public static DAResult stopTracing(String device) throws ConnectException {
+ public static DAResult stopTracingProcess(String device) throws ConnectException {
ProcessManagerMBean pmProxy = getPMProxyInstance();
return pmProxy.stopTracing(device);
return pmProxy.getContext(device);
}
+ /**
+ * Start tracing with requested parameters: setup given data as selected in
+ * DA and run the StartTraceManager thread
+ *
+ * @param args tracing arguments
+ * @return {@link ErrorCode#SUCCESS} if tracing started successfully, <br/>
+ * {@link ErrorCode#ERR_NO_DEVICE} if couldn't select requested device, <br/>
+ * {@link ErrorCode#ERR_NO_APP} if couldn't select requested application, <br/>
+ * {@link ErrorCode#ERR_EXCEPTION_OCCURRED} if couldn't select requested template.
+ */
+ public static ErrorCode startTracing(TracingArguments args) {
+ Logger.info("Starting tracing...");
+ initDevices();
+ loadConnectedDevices();
+ if (!selectDevice(args.getDevice())) {
+ Logger.debug("Failed to select device");
+ return ErrorCode.ERR_NO_DEVICE;
+ }
+ Logger.debug("Set current device: " + args.getDevice());
+
+ if (!selectApp(args.getApplication())) {
+ Logger.debug("Failed to select application");
+ return ErrorCode.ERR_NO_APP;
+ }
+ Logger.debug("Set current app: " + args.getApplication());
+
+ if (!selectTemplate(args.getTemplate())) {
+ Logger.debug("Failed to select template");
+ return ErrorCode.ERR_EXCEPTION_OCCURRED;
+ }
+ Logger.debug("Set current template: " + args.getTemplate());
+
+ // TODO Implement main functionality via StartTraceManager thread
+ // invocation
+
+ return ErrorCode.SUCCESS;
+ }
+
}
import java.util.Arrays;
import org.apache.commons.cli.ParseException;
+import org.tizen.dynamicanalyzer.cli.CliInternals;
import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
import org.tizen.dynamicanalyzer.util.InternalLogger;
import org.tizen.dynamicanalyzer.util.Logger;
private volatile ErrorCode status;
/**
+ * Tracing arguments
+ */
+ private final TracingArguments args;
+
+ /**
* Public constructor.
*
* @param args tracing input arguments
*/
public TracingProcess(TracingArguments args) {
status = ErrorCode.ERR_UNKNOWN;
+ this.args = args;
}
/**
* Start tracing activities.
* This method should not block caller thread during tracing process itself.
*
- * @return {@link ErrorCode#SUCCESS} if tracing started successfully
- * TODO complete error codes documentation
+ * @return {@link ErrorCode#SUCCESS} if tracing started successfully, <br/>
+ * {@link ErrorCode#ERR_NO_DEVICE} if couldn't select requested device, <br/>
+ * {@link ErrorCode#ERR_NO_APP} if couldn't select requested application, <br/>
+ * {@link ErrorCode#ERR_EXCEPTION_OCCURRED} if couldn't select requested template.
*/
public synchronized ErrorCode startTrace() {
- // TODO stuff for start tracing
-
- // successfully started
- return ErrorCode.SUCCESS;
+ return CliInternals.startTracing(args);
}
/**