From 9a95eca7ef81c5322f6d4185a56f4960bb6a3339 Mon Sep 17 00:00:00 2001
From: "p.privalov"
Date: Tue, 5 Jul 2016 13:48:16 +0300
Subject: [PATCH] SRADA-827 Added Screenshots support from Cli
* Now it's possible to specify parameteres for screenshot period
with -S or --screenshot , where value is a positive integer number
of seconds in period between screenshots. If empty or 0 then
onSceneTransition option enables.
* Added CliInternals.selectScreenshotFeature(..) that enables screenshot
onSceneTransition or periodically.
* In CliInternals.selectFeatures(..) simplified.
Change-Id: I3d3e514b30f3b09a073703554e7e2d0dda78bf24
---
.../tizen/dynamicanalyzer/cli/CliInternals.java | 52 ++++++++++++++++++----
.../cli/tracing/TracingArguments.java | 35 +++++++++++++++
.../cli/tracing/TracingArgumentsParser.java | 30 +++++++++++++
.../cli/tracing/TracingArgumentsTest.java | 21 +++++++++
.../dynamicanalyzer/ui/page/PageInfoRegistry.java | 7 +--
5 files changed, 132 insertions(+), 13 deletions(-)
diff --git a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
index 286f98d..f2f5ef6 100644
--- a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
+++ b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
@@ -25,9 +25,13 @@ import org.tizen.dynamicanalyzer.communicator.DACommunicator;
import org.tizen.dynamicanalyzer.communicator.DeviceInfo;
import org.tizen.dynamicanalyzer.communicator.DeviceManager;
import org.tizen.dynamicanalyzer.handlers.CommandAction;
+import org.tizen.dynamicanalyzer.handlers.CommonAction;
import org.tizen.dynamicanalyzer.handlers.UIActionHolder;
+import org.tizen.dynamicanalyzer.nl.ConfigureLabels;
+import org.tizen.dynamicanalyzer.nl.TimelineChartLabels;
import org.tizen.dynamicanalyzer.project.AppInfo;
import org.tizen.dynamicanalyzer.project.PackageInfo;
+import org.tizen.dynamicanalyzer.setting.FlatPreferences;
import org.tizen.dynamicanalyzer.setting.PrimitiveFeature;
import org.tizen.dynamicanalyzer.setting.SettingDataManager;
import org.tizen.dynamicanalyzer.setting.TargetData;
@@ -266,20 +270,52 @@ public final class CliInternals {
* @param features set of features to be enabled.
* @return was operation successful or not.
*/
- private static boolean selectFeatures(Set features) {
+ private static boolean selectFeatures(TracingArguments args) {
+ selectScreenshotFeature(args.getScreenshotPeriod(),
+ args.isScreenshotPeriodSpecified());
+ args.getFeatures().remove(PrimitiveFeature.SCREENSHOT);//This feature added to target by selectScreenshotFeature().
+
TargetData target = SettingDataManager.INSTANCE.getTarget(null);
- Set selectedChartSet = new HashSet();
- for (PrimitiveFeature feature : features) {
+ for (PrimitiveFeature feature : args.getFeatures()) {
target.addSelectedFlatFeature(feature.getName());
- selectedChartSet.add(feature.getChart());
+ UILayoutDataManager.INSTANCE.addSelectedChart(feature.getChart());
}
- UILayoutDataManager.INSTANCE.setSelectedChartSet(selectedChartSet);
return true;
}
/**
+ * Enables screenshot onSceneTransition or periodically.
+ *
+ * @param period period in seconds, onSceneTransition if period == 0.
+ * @return was operation successful or not.
+ */
+ private static void selectScreenshotFeature(int period,
+ boolean isScreenshotsEnabled) {
+ // TODO move this to common place for CLI and GUI
+ if (!isScreenshotsEnabled) {
+ Logger.debug("Screenshots are not captured.");
+ return;
+ }
+
+ if (period == 0){
+ TargetData target = SettingDataManager.INSTANCE.getTarget(null);
+ target.addSelectedFlatFeature(ConfigureLabels.FEATURE_NAME_SCREENSHOT);
+ Logger.debug("Screenshots are captured on scene transition.");
+ }
+
+ if (period > 0){
+ SettingDataManager.INSTANCE.addOptionsSelectedPreference(
+ FlatPreferences.SCREENSHOT_PERIODICALLY, period);
+ Logger.debug("Screenshots are captured every " + period + " sec.");
+ }
+ UILayoutDataManager.INSTANCE
+ .addSelectedChart(TimelineChartLabels.SCREENSHOT_CHART_TITLE);
+ return;
+ }
+
+ /**
* Helper function for packages list extraction from selected device.
*
* @param dev IDevice object presenting selected device
@@ -396,15 +432,15 @@ public final class CliInternals {
}
Logger.debug("Set current app: " + args.getApplication());
- if (!selectFeatures(args.getFeatures())) {
+ if (!selectFeatures(args)) {
Logger.debug("Failed to select features");
return ErrorCode.ERR_EXCEPTION_OCCURRED;
}
- Logger.debug("Set features: "
- + Arrays.asList(args.getFeatures().toArray()));
+ Logger.debug("Set features: " + Arrays.asList(args.getFeatures().toArray()));
// Create all needed data managers before
UIActionHolder.getUIAction().setUIElementsBySetting();
+ CommonAction.configure(); // TODO move this to common place for CLI and GUI
CommandAction.startTrace(false);
Logger.debug("Tracing started");
diff --git a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArguments.java b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArguments.java
index ec1e74b..f1ad853 100644
--- a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArguments.java
+++ b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArguments.java
@@ -23,6 +23,9 @@ public class TracingArguments implements Cloneable, Serializable {
private File output; // file with tracing output
// TODO duration actually is not supported yet by CLI, always set to 0
private long durationSec; // tracing duration in seconds (0 is for unlimited duration)
+ private int screenshotPeriod = 0; // Screenshot period in s. If 0
+ // onSceneTransition else periodically
+ private boolean isScreenshotPeriodSpecified = false;
private String errMessage; // contains message about all found errors during validation ( isValid() )
@@ -71,6 +74,14 @@ public class TracingArguments implements Cloneable, Serializable {
msg += " * Duration is negative%n";
}
+ // Screenshot period check
+ if (isScreenshotPeriodSpecified) {
+ if (screenshotPeriod < 0) {
+ result = false;
+ msg += " * Screenshot period is negative%n";
+ }
+ }
+
// Features check
if (featuresSet.isEmpty()) {
result = false;
@@ -151,6 +162,30 @@ public class TracingArguments implements Cloneable, Serializable {
}
/**
+ * @return Screenshot period in seconds. If 0 it means onSceneTransition.
+ */
+ public int getScreenshotPeriod() {
+ return screenshotPeriod;
+ }
+
+ /**
+ * @return true
if screenshots enabled.
+ */
+ public boolean isScreenshotPeriodSpecified() {
+ return isScreenshotPeriodSpecified;
+ }
+
+ /**
+ * @param period The period in seconds to set. 0 for onSceneTransition.
+ * @return this object to allow chained methods execution
+ */
+ public TracingArguments setScreenshotPeriod(int period) {
+ this.screenshotPeriod = period;
+ this.isScreenshotPeriodSpecified = true;
+ return this;
+ }
+
+ /**
* @return the featuresList list of features selected for tracing
*/
public Set getFeatures() {
diff --git a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsParser.java b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsParser.java
index cd0fb4d..d1cdefa 100644
--- a/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsParser.java
+++ b/org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsParser.java
@@ -10,6 +10,7 @@ import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.tizen.dynamicanalyzer.setting.PrimitiveFeature;
import org.tizen.dynamicanalyzer.util.Logger;
/**
@@ -38,9 +39,18 @@ public class TracingArgumentsParser {
.desc("redirect tracing output to file")
.build();
+ private static Option screenshotPeriod = Option.builder("S")
+ .hasArg()
+ .optionalArg(true)
+ .longOpt("screenshot")
+ .argName("screenshot")
+ .desc("Enable screenshots capturing periodically or on scene transition if no argument set")
+ .build();
+
private static Options opts = new Options();
static {
+ // One of template options is required
opts.addOption(application)
// TODO duration option is not supported yet
// .addOption(duration)
@@ -48,6 +58,7 @@ public class TracingArgumentsParser {
for (TracingFeatureArgument featureOpt : TracingFeatureArgument.values()) {
opts.addOption(featureOpt.getOption());
}
+ opts.addOption(screenshotPeriod);
}
/**
@@ -100,6 +111,18 @@ public class TracingArgumentsParser {
result.setOutput(new File(outString));
}
+ // Get screenshot period
+ if (cmdline.hasOption(screenshotPeriod.getOpt())) {
+ String period = cmdline.getOptionValue(screenshotPeriod.getOpt());
+ if (period == null) {
+ result.setScreenshotPeriod(0);
+ } else {
+ int periodInt = Integer.parseInt(period);
+ result.setScreenshotPeriod(periodInt);
+ }
+ result.addFeature(PrimitiveFeature.SCREENSHOT);
+ }
+
// Get features
TracingFeatureArgument.parseFeatureOptions(result, cmdline);
@@ -151,6 +174,13 @@ public class TracingArgumentsParser {
result.add(out.getAbsolutePath());
}
+ int period = args.getScreenshotPeriod();
+ if (args.isScreenshotPeriodSpecified()) {
+ result.add('-' + screenshotPeriod.getOpt());
+ if (period > 0)
+ result.add(Integer.toString(period));
+ }
+
// Features
result.addAll(TracingFeatureArgument.toStringArrayList(args));
diff --git a/org.tizen.dynamicanalyzer.cli/test/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsTest.java b/org.tizen.dynamicanalyzer.cli/test/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsTest.java
index dc05c8c..f5271b1 100644
--- a/org.tizen.dynamicanalyzer.cli/test/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsTest.java
+++ b/org.tizen.dynamicanalyzer.cli/test/src/org/tizen/dynamicanalyzer/cli/tracing/TracingArgumentsTest.java
@@ -22,6 +22,7 @@ public class TracingArgumentsTest {
private final static File output = new File("output.out");
private final static PrimitiveFeature feature = PrimitiveFeature.CPU_USAGE;
private final static PrimitiveFeature feature2 = PrimitiveFeature.POWER_ESTIMATION;
+ private final static int period = 3;
@Before
public void setUp() {
@@ -111,4 +112,24 @@ public class TracingArgumentsTest {
TracingArguments args = new TracingArguments();
assertFalse(args.isValid());
}
+
+ @Test
+ public void isValid_withOkPeriod() {
+ TracingArguments args = new TracingArguments()
+ .setDevice(device)
+ .setApplication(application)
+ .addFeature(feature)
+ .setScreenshotPeriod(period);
+ assertTrue(args.isValid());
+ }
+
+ @Test
+ public void isValid_withBadPeriod() {
+ TracingArguments args = new TracingArguments()
+ .setDevice(device)
+ .setApplication(application)
+ .addFeature(feature)
+ .setScreenshotPeriod(-period);
+ assertFalse(args.isValid());
+ }
}
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/PageInfoRegistry.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/PageInfoRegistry.java
index 3671b56..1dc5482 100644
--- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/PageInfoRegistry.java
+++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/PageInfoRegistry.java
@@ -17,7 +17,6 @@ import org.eclipse.swt.widgets.Composite;
import org.tizen.dynamicanalyzer.common.Global;
import org.tizen.dynamicanalyzer.setting.SettingConstants;
import org.tizen.dynamicanalyzer.setting.SettingDataManager;
-import org.tizen.dynamicanalyzer.swap.logparser.DataManagerRegistry;
import org.tizen.dynamicanalyzer.swap.logparser.PageDataManager;
import org.tizen.dynamicanalyzer.ui.file.FilePage;
import org.tizen.dynamicanalyzer.ui.file.manager.FileDataManager;
@@ -27,10 +26,10 @@ import org.tizen.dynamicanalyzer.ui.info.screenshot.ScreenshotDataManager;
import org.tizen.dynamicanalyzer.ui.interactive.InteractivePage;
import org.tizen.dynamicanalyzer.ui.interactive.data.InteractiveDataManager;
import org.tizen.dynamicanalyzer.ui.kernel.KernelPage;
+import org.tizen.dynamicanalyzer.ui.kernel.data.KernelDataManager;
import org.tizen.dynamicanalyzer.ui.memory.MemoryPage;
import org.tizen.dynamicanalyzer.ui.memory.data.HeapDataManager;
import org.tizen.dynamicanalyzer.ui.memory.data.MemoryDataManager;
-import org.tizen.dynamicanalyzer.ui.kernel.data.KernelDataManager;
import org.tizen.dynamicanalyzer.ui.network.NetworkPage;
import org.tizen.dynamicanalyzer.ui.network.data.NetworkDataManager;
import org.tizen.dynamicanalyzer.ui.opengl.GLPage;
@@ -98,10 +97,8 @@ public class PageInfoRegistry {
// InteractiveDataManager is not supported in CLI mode
if (Global.isGUIMode()) {
timelinePageInfo.addDataManager(InteractiveDataManager.class);
- // Screenshots are not tested in CLI mode yet
- // TODO test and enable
- timelinePageInfo.addDataManager(ScreenshotDataManager.class);
}
+ timelinePageInfo.addDataManager(ScreenshotDataManager.class);
timelinePageInfo.addDataManager(MemoryDataManager.class);
timelinePageInfo.addDataManager(DLogDataManager.class);
timelinePageInfo.addDataManager(FunctionUsageProfiler.class);
--
2.7.4