import java.io.File;
import java.rmi.ConnectException;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.tizen.dynamicanalyzer.project.PackageInfo;
import org.tizen.dynamicanalyzer.setting.PrimitiveFeature;
import org.tizen.dynamicanalyzer.setting.SettingDataManager;
+import org.tizen.dynamicanalyzer.setting.TargetData;
import org.tizen.dynamicanalyzer.setting.Template;
+import org.tizen.dynamicanalyzer.setting.UILayoutDataManager;
import org.tizen.dynamicanalyzer.util.InternalLogger;
import org.tizen.dynamicanalyzer.util.Logger;
import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
}
/**
- * Selects features to be used for tracing by given list of
- * {@link PrimitiveFeature}
+ * Enables all selected features.
*
- * @param template
- * Template instance
- * @return <code>true</code> on success
+ * @param features set of features to be enabled.
+ * @return was operation successful or not.
*/
- private static boolean selectFeatureList(List<PrimitiveFeature> features) {
- if (features.isEmpty())
- return false;
+ private static boolean selectFeatures(Set<PrimitiveFeature> features) {
+ TargetData target = SettingDataManager.INSTANCE.getTarget(null);
+ Set<String> selectedChartSet = new HashSet<String>();
+
+ for (PrimitiveFeature feature : features) {
+ target.addSelectedFlatFeature(feature.getName());
+ selectedChartSet.add(feature.getChart());
+ }
- /*
- * TODO Implement selected features usage in DACLI
- *
- * TargetData target = SettingDataManager.INSTANCE.getTarget(null);
- * target.setSelectedTemplate(template);
- * target.changeSelectedFeatureList(template);
- *
- * Set<String> selectedChartSet = new HashSet<String>();
- *
- * for (FeatureValueData feature : template.getData().getFeatureList())
- * { if (feature.getKey().getData().getChartList().size() > 0) {
- * selectedChartSet.addAll(feature.getKey().getData() .getChartList());
- * } } Logger.debug(selectedChartSet);
- *
- * UILayoutDataManager.INSTANCE.setSelectedChartSet(selectedChartSet);
- */
- return false; // true;
+ UILayoutDataManager.INSTANCE.setSelectedChartSet(selectedChartSet);
+ return true;
}
/**
*/
public static TracingProcessContext getContext(String device) throws ConnectException {
ProcessManagerMBean pmProxy = getPMProxyInstance();
-
return pmProxy.getContext(device);
}
}
Logger.debug("Set current app: " + args.getApplication());
- if (!selectFeatureList(args.getFeaturesList())) {
+ if (!selectFeatures(args.getFeatures())) {
Logger.debug("Failed to select features");
return ErrorCode.ERR_EXCEPTION_OCCURRED;
}
+ Logger.debug("Set features: "
+ + Arrays.asList(args.getFeatures().toArray()));
// Create all needed data managers before
UIActionHolder.getUIAction().setUIElementsBySetting();
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
SYNC("Y", "synchronization"),
// Options for single features selection
- UIEVENT("U", PrimitiveFeature.UI_EVENT), PERIPHERAL("P",
- PrimitiveFeature.PERIPHERAL_STATUS), POWER("E",
- PrimitiveFeature.POWER_ESTIMATION);
+ UIEVENT("U", PrimitiveFeature.UI_EVENT),
+ PERIPHERAL("P", PrimitiveFeature.PERIPHERAL_STATUS),
+ POWER("E", PrimitiveFeature.POWER_ESTIMATION);
static {
CPU.addDefaultFeatureValue("usage", PrimitiveFeature.CPU_USAGE);
CPU.addDefaultFeatureValue("core", PrimitiveFeature.CPU_USAGE_PER_CORE);
- CPU.addDefaultFeatureValue("frequency",
- PrimitiveFeature.CPU_FREQ_PER_CORE);
+ CPU.addDefaultFeatureValue("frequency", PrimitiveFeature.CPU_FREQ_PER_CORE);
MEMORY.addDefaultFeatureValue("system", PrimitiveFeature.SYSTEM_MEMORY);
- MEMORY.addDefaultFeatureValue("process",
- PrimitiveFeature.PROCESS_MEMORY);
+ MEMORY.addDefaultFeatureValue("process", PrimitiveFeature.PROCESS_MEMORY);
MEMORY.addFeatureValue("heap", PrimitiveFeature.MEMORY_ALLOC);
FILE.addDefaultFeatureValue("io", PrimitiveFeature.DISK_IO);
FILE.addDefaultFeatureValue("analysis", PrimitiveFeature.FILE_ANALYSIS);
- GRAPHICS.addDefaultFeatureValue("opengl",
- PrimitiveFeature.OPENGLES_ANALYSIS);
+ GRAPHICS.addDefaultFeatureValue("opengl", PrimitiveFeature.OPENGLES_ANALYSIS);
NETWORK.addDefaultFeatureValue("io", PrimitiveFeature.NETWORK_IO);
- NETWORK.addDefaultFeatureValue("analysis",
- PrimitiveFeature.NETWORK_ANALYSIS);
+ NETWORK.addDefaultFeatureValue("analysis", PrimitiveFeature.NETWORK_ANALYSIS);
SYNC.addDefaultFeatureValue("thread", PrimitiveFeature.THREAD_ANALYSIS);
SYNC.addDefaultFeatureValue("sync", PrimitiveFeature.SYNC_ANALYSIS);
opt.parseFeatureOption(result, cmdline);
}
- if (result.getFeaturesList().isEmpty())
+ if (result.getFeatures().isEmpty())
throw new ParseException("No tracing features seleted: at least one feature is required.");
}
*/
public static ArrayList<String> toStringArrayList(TracingArguments args) {
ArrayList<String> result = new ArrayList<String>();
- List<PrimitiveFeature> features = args.getFeaturesList();
+ Set<PrimitiveFeature> features = args.getFeatures();
if (features.isEmpty())
return result;
private final static String device = "device";
private final static String application = "application";
private final static String applicationOpt = "-a";
- private final static PrimitiveFeature feature = PrimitiveFeature.CPU_USAGE;
- private final static String featureOpt = "-C=usage";
+ private final static PrimitiveFeature cpu = PrimitiveFeature.CPU_USAGE;
+ private final static String featureOptCPU = "-C=usage";
+ private final static PrimitiveFeature memory1 = PrimitiveFeature.SYSTEM_MEMORY;
+ private final static PrimitiveFeature memory2 = PrimitiveFeature.PROCESS_MEMORY;
+ private final static String featureOptMEMORY = "-M";
+ private final static PrimitiveFeature file1 = PrimitiveFeature.DISK_IO;
+ private final static PrimitiveFeature file2 = PrimitiveFeature.FILE_ANALYSIS;
+ private final static String featureOptFILE = "-F=all";
+ private final static PrimitiveFeature power = PrimitiveFeature.POWER_ESTIMATION;
+ private final static String featureOptPOWER = "-E";
private final static File output = new File("output.out");
private final static String outputOpt = "-o";
private final static long duration = 12345;
device,
applicationOpt, application,
outputOpt, output.getPath(),
- featureOpt
+ featureOptCPU
// TODO duration option is not supported yet
// durationOpt, Long.toString(duration)
});
assertEquals(device, result.getDevice());
assertEquals(application, result.getApplication());
assertEquals(output, result.getOutput());
- assertEquals(1, result.getFeaturesList().size());
- assertEquals(feature, result.getFeaturesList().get(0));
+ assertEquals(1, result.getFeatures().size());
+ assertTrue(result.getFeatures().contains(cpu));
// TODO duration option is not supported yet
// assertEquals(duration, result.getDuration());
}
TracingArguments result = TracingArgumentsParser.parse(new String[] {
device,
applicationOpt, application,
- featureOpt });
+ featureOptCPU });
assertNotNull(result);
assertTrue(result.isValid());
assertNull(result.getOutput());
TracingArguments result = TracingArgumentsParser.parse(new String[] {
applicationOpt, application,
device,
- featureOpt });
+ featureOptCPU });
assertNull(result);
}
TracingArguments result = TracingArgumentsParser.parse(new String[] {
device,
application, applicationOpt,
- featureOpt });
+ featureOptCPU });
assertNull(result);
}
TracingArguments result = TracingArgumentsParser.parse(new String[] {
device,
applicationOpt,
- featureOpt });
+ featureOptCPU });
assertNull(result);
}
TracingArguments result = TracingArgumentsParser.parse(new String[] {
device,
applicationOpt, application,
- featureOpt,
+ featureOptCPU,
"--option", "value" });
assertNull(result);
}
TracingArguments result = TracingArgumentsParser.parse(new String[] {
device,
applicationOpt, application,
- featureOpt,
+ featureOptCPU,
outputOpt, output.getPath(),
durationOpt, Long.toString(duration),
"--", "value"});
TracingArguments args = new TracingArguments()
.setDevice(device)
.setApplication(application)
- .addFeature(feature);
+ .addFeature(cpu);
String[] result = TracingArgumentsParser.toStringArray(args);
assertNotNull(result);
assertEquals(5, result.length);
TracingArguments args = new TracingArguments()
.setDevice(device)
.setApplication(application)
- .addFeature(feature)
+ .addFeature(cpu)
.setDuration(-10);
String[] result = TracingArgumentsParser.toStringArray(args);
assertNull(result);
TracingArguments args = new TracingArguments()
.setDevice(device)
.setApplication(application)
- .addFeature(feature)
+ .addFeature(cpu)
.setOutput(output);
String[] result = TracingArgumentsParser.toStringArray(args);
assertNotNull(result);
String[] result = TracingArgumentsParser.toStringArray(null);
assertNull(result);
}
+
+ @Test
+ public void parse_AllFeaturesfromGroup() throws Exception {
+ TracingArguments result = TracingArgumentsParser.parse(new String[] {
+ device,
+ applicationOpt, application,
+ outputOpt, output.getPath(),
+ featureOptFILE
+ // TODO duration option is not supported yet
+ // durationOpt, Long.toString(duration)
+ });
+
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertEquals(device, result.getDevice());
+ assertEquals(application, result.getApplication());
+ assertEquals(output, result.getOutput());
+ assertEquals(2, result.getFeatures().size());
+ assertTrue(result.getFeatures().contains(file1));
+ assertTrue(result.getFeatures().contains(file2));
+ }
+
+ @Test
+ public void parse_DefaultFeaturesfromGroup() throws Exception {
+ TracingArguments result = TracingArgumentsParser.parse(new String[] {
+ device,
+ applicationOpt, application,
+ outputOpt, output.getPath(),
+ featureOptMEMORY
+ // TODO duration option is not supported yet
+ // durationOpt, Long.toString(duration)
+ });
+
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertEquals(device, result.getDevice());
+ assertEquals(application, result.getApplication());
+ assertEquals(output, result.getOutput());
+ assertEquals(2, result.getFeatures().size());
+ assertTrue(result.getFeatures().contains(memory1));
+ assertTrue(result.getFeatures().contains(memory2));
+ }
+
+ @Test
+ public void parse_OneFeaturenotFromGroup() throws Exception {
+ TracingArguments result = TracingArgumentsParser.parse(new String[] {
+ device,
+ applicationOpt, application,
+ outputOpt, output.getPath(),
+ featureOptPOWER
+ // TODO duration option is not supported yet
+ // durationOpt, Long.toString(duration)
+ });
+
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertEquals(device, result.getDevice());
+ assertEquals(application, result.getApplication());
+ assertEquals(output, result.getOutput());
+ assertEquals(1, result.getFeatures().size());
+ assertTrue(result.getFeatures().contains(power));
+ }
+
+ @Test
+ public void parse_LotsOfFeatures() throws Exception {
+ TracingArguments result = TracingArgumentsParser.parse(new String[] {
+ device,
+ applicationOpt, application,
+ outputOpt, output.getPath(),
+ featureOptPOWER,
+ featureOptCPU,
+ featureOptFILE,
+ featureOptMEMORY
+ // TODO duration option is not supported yet
+ // durationOpt, Long.toString(duration)
+ });
+
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertEquals(device, result.getDevice());
+ assertEquals(application, result.getApplication());
+ assertEquals(output, result.getOutput());
+ assertEquals(6, result.getFeatures().size());
+ }
+
+ @Test
+ public void toStringArray_TwoFeatures() {
+ TracingArguments args = new TracingArguments()
+ .setDevice(device)
+ .setApplication(application)
+ .addFeature(cpu)
+ .addFeature(file2);
+ String[] result = TracingArgumentsParser.toStringArray(args);
+ assertNotNull(result);
+ assertEquals(7, result.length);
+ }
+
+ @Test
+ public void toStringArray_ThreeFeatures() {
+ TracingArguments args = new TracingArguments()
+ .setDevice(device)
+ .setApplication(application)
+ .addFeature(cpu)
+ .addFeature(file1)
+ .addFeature(file2);
+ String[] result = TracingArgumentsParser.toStringArray(args);
+ assertNotNull(result);
+ assertEquals(8, result.length);
+ assertEquals("-C", result[3]);
+ assertEquals("usage", result[4]);
+ assertEquals("-F", result[5]);
+ assertEquals("analysis", result[6]);
+ assertEquals("io", result[7]);
+ }
}