android: introduce new System API for systrace functions

'systrace.py' was renamed to 'run_systrace.py' in catapult
and this breaks the android notebooks.
Add new Android::System API to start systrace and wait for
its completion. Modify Android_Workloads.ipynb and
Android_YouTube.ipynb to adopt the new API.

The commit in catapult is:

commit 8433261359496535812210677f059e54222631a9
Author: alexandermont <alexandermont@chromium.org>
Date:   Mon Apr 4 15:56:58 2016 -0700

    Rename systrace to run_systrace and agents to tracing_agents
[snip]

Signed-off-by: Ionela Voinescu <ionela.voinescu@arm.com>
diff --git a/ipynb/android/Android_Workloads.ipynb b/ipynb/android/Android_Workloads.ipynb
index 0314c69..af1b765 100644
--- a/ipynb/android/Android_Workloads.ipynb
+++ b/ipynb/android/Android_Workloads.ipynb
@@ -13,7 +13,16 @@
    "metadata": {
     "collapsed": false
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2016-12-06 19:28:40,088 INFO    : root         : Using LISA logging configuration:\n",
+      "2016-12-06 19:28:40,089 INFO    : root         :   /home/vagrant/lisa/logging.conf\n"
+     ]
+    }
+   ],
    "source": [
     "import logging\n",
     "from conf import LisaLogging\n",
@@ -42,7 +51,6 @@
     "import copy\n",
     "import json\n",
     "import os\n",
-    "import pexpect as pe\n",
     "from time import sleep\n",
     "\n",
     "# Support to access the remote target\n",
@@ -52,7 +60,7 @@
     "# from devlib.utils.android import adb_command\n",
     "\n",
     "# Import support for Android devices\n",
-    "from android import Screen, Workload\n",
+    "from android import Screen, Workload, System\n",
     "\n",
     "# Support for trace events analysis\n",
     "from trace import Trace\n",
@@ -74,45 +82,8 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "Devlib requires the ANDROID_HOME environment variable configured to point to your local installation of the Android SDK. If you have not this variable configured in the shell used to start the notebook server, you need to run the next cell to define where your Android SDK is installed."
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 3,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": [
-    "# Setup Androd SDK\n",
-    "os.environ['ANDROID_HOME'] = '/home/eas/Work/Android/android-sdk-linux/'\n",
-    "\n",
-    "# Setup Catapult for Systrace usage\n",
-    "CATAPULT_HOME = \"/home/eas/Work/Android/catapult\""
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 4,
-   "metadata": {
-    "collapsed": false
-   },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "adbd is already running as root\r\n"
-     ]
-    }
-   ],
-   "source": [
-    "# Android device to target\n",
-    "DEVICE = 'GA0113TP0178'\n",
-    "\n",
-    "# Ensure ADB is running as root\n",
-    "!adb -s {DEVICE} root"
+    "Devlib requires the ANDROID_HOME environment variable configured to point to your local installation of the Android SDK. If you have not this variable configured in the shell used to start the notebook server, you need to run an additional cell to define where your Android SDK is installed or add \"ANDROID_HOME\" in your target configuration.\n",
+    "CATAPULT_HOME is considered to be in LISA_HOME/tools/catapult."
    ]
   },
   {
@@ -124,7 +95,19 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 3,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "# Android device to target\n",
+    "DEVICE = 'HT6670300102'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
    "metadata": {
     "collapsed": false
    },
@@ -134,8 +117,9 @@
     "my_conf = {\n",
     "\n",
     "    # Target platform and board\n",
-    "    \"platform\"    : 'android',\n",
-    "    \"device\"      : DEVICE,\n",
+    "    \"platform\"      : 'android',\n",
+    "    \"device\"        : DEVICE,\n",
+    "    \"ANDROID_HOME\"  : '/home/vagrant/lisa/tools/android-sdk-linux/',\n",
     "\n",
     "#     \"emeter\" : {\n",
     "#         \"instrument\" : \"aep\",\n",
@@ -181,7 +165,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 5,
    "metadata": {
     "collapsed": false
    },
@@ -219,7 +203,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 6,
    "metadata": {
     "collapsed": true
    },
@@ -230,8 +214,8 @@
     "#  energy   - Use the my_conf's defined emeter to measure energy consumption across experiments\n",
     "#  ftrace   - Collect an execution trace using trace-cmd\n",
     "#  systrace - Collect an execution trace using Systrace/Atrace\n",
-    "# NOTE: energy is automatically enabled in case an \"emeter\" configuration is defined in my_conf\n",
-    "collect = ''"
+    "# NOTE: energy is automatically enabled in case an \"emeter\" confHT6670300102iguration is defined in my_conf\n",
+    "collect = 'systrace'"
    ]
   },
   {
@@ -250,7 +234,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 7,
    "metadata": {
     "collapsed": true
    },
@@ -282,7 +266,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 8,
    "metadata": {
     "collapsed": true
    },
@@ -310,14 +294,12 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 9,
    "metadata": {
     "collapsed": false
    },
    "outputs": [],
    "source": [
-    "SYSTRACE_CMD  = CATAPULT_HOME + \"/systrace/systrace/systrace.py -e {} -o {} gfx view sched freq idle -t {}\"\n",
-    "\n",
     "def experiment(wl, res_dir, conf_name, wload_name, iterations, collect=''):\n",
     "    \n",
     "    # Load workload params\n",
@@ -350,9 +332,7 @@
     "    elif 'systrace' in collect:\n",
     "        # Start systrace\n",
     "        trace_file = os.path.join(exp_dir, 'trace.html')\n",
-    "        trace_cmd = SYSTRACE_CMD.format(DEVICE, trace_file, 10 * iterations)\n",
-    "        logging.info('SysTrace: %s', trace_cmd)\n",
-    "        systrace_output = pe.spawn(trace_cmd)\n",
+    "        systrace_output = System.systrace_start(te, trace_file, 10 * iterations)\n",
     "    \n",
     "    ###########################\n",
     "    # Run the required workload\n",
@@ -376,8 +356,11 @@
     "        trace_file = os.path.join(exp_dir, 'trace.dat')\n",
     "        te.ftrace.get_trace(trace_file)\n",
     "    elif 'systrace' in collect:\n",
-    "        logging.info('Waiting systrace report [%s]...', trace_file)\n",
-    "        systrace_output.wait()\n",
+    "        if systrace_output:\n",
+    "            logging.info('Waiting systrace report [%s]...', trace_file)\n",
+    "            systrace_output.wait()\n",
+    "        else:\n",
+    "            logging.warning('Systrace is not running!')\n",
     "\n",
     "    # Reset screen brightness and auto dimming\n",
     "    Screen.set_defaults(target, )\n",
@@ -417,17 +400,45 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": 10,
    "metadata": {
     "collapsed": false
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "caiman: no process found\r\n"
+     ]
+    }
+   ],
    "source": [
     "# # Cleanup Caiman energy meter temporary folders\n",
     "# !rm -rf /tmp/eprobe-caiman-*\n",
     "# # Ensure there are not other \"caiman\" instanced running for the specified device\n",
     "# # my_conf['emeter']['conf']['device_entry']\n",
-    "# !killall caiman"
+    "!killall caiman"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "adbd is already running as root\r\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Ensure ADB is running as root\n",
+    "!adb -s {DEVICE} root"
    ]
   },
   {
@@ -442,40 +453,37 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "2016-05-10 18:11:10,176 INFO    :         Target - Using base path: /home/derkling/Code/lisa\n",
-      "2016-05-10 18:11:10,177 INFO    :         Target - Loading custom (inline) target configuration\n",
-      "2016-05-10 18:11:10,178 INFO    :         Target - Devlib modules to load: ['cpufreq']\n",
-      "2016-05-10 18:11:10,179 INFO    :         Target - Connecting Android target [GA0113TP0178]\n",
-      "2016-05-10 18:11:11,481 INFO    :         Target - Initializing target workdir:\n",
-      "2016-05-10 18:11:11,482 INFO    :         Target -    /data/local/tmp/devlib-target\n",
-      "2016-05-10 18:11:14,396 INFO    :         Target - Topology:\n",
-      "2016-05-10 18:11:14,397 INFO    :         Target -    [[0, 1], [2, 3]]\n",
-      "2016-05-10 18:11:15,643 WARNING : Event [sched_overutilized] not available for tracing\n",
-      "2016-05-10 18:11:15,645 WARNING : Event [sched_contrib_scale_f] not available for tracing\n",
-      "2016-05-10 18:11:15,647 WARNING : Event [sched_load_avg_cpu] not available for tracing\n",
-      "2016-05-10 18:11:15,648 WARNING : Event [sched_load_avg_task] not available for tracing\n",
-      "2016-05-10 18:11:15,649 WARNING : Event [sched_tune_tasks_update] not available for tracing\n",
-      "2016-05-10 18:11:15,651 WARNING : Event [sched_boost_cpu] not available for tracing\n",
-      "2016-05-10 18:11:15,652 WARNING : Event [sched_boost_task] not available for tracing\n",
-      "2016-05-10 18:11:15,654 WARNING : Event [sched_energy_diff] not available for tracing\n",
-      "2016-05-10 18:11:15,657 WARNING : Event [cpu_capacity] not available for tracing\n",
-      "2016-05-10 18:11:15,657 INFO    :         FTrace - Enabled tracepoints:\n",
-      "2016-05-10 18:11:15,658 INFO    :         FTrace -   sched_switch\n",
-      "2016-05-10 18:11:15,658 INFO    :         FTrace -   sched_overutilized\n",
-      "2016-05-10 18:11:15,659 INFO    :         FTrace -   sched_contrib_scale_f\n",
-      "2016-05-10 18:11:15,660 INFO    :         FTrace -   sched_load_avg_cpu\n",
-      "2016-05-10 18:11:15,660 INFO    :         FTrace -   sched_load_avg_task\n",
-      "2016-05-10 18:11:15,661 INFO    :         FTrace -   sched_tune_tasks_update\n",
-      "2016-05-10 18:11:15,661 INFO    :         FTrace -   sched_boost_cpu\n",
-      "2016-05-10 18:11:15,662 INFO    :         FTrace -   sched_boost_task\n",
-      "2016-05-10 18:11:15,662 INFO    :         FTrace -   sched_energy_diff\n",
-      "2016-05-10 18:11:15,663 INFO    :         FTrace -   cpu_frequency\n",
-      "2016-05-10 18:11:15,664 INFO    :         FTrace -   cpu_idle\n",
-      "2016-05-10 18:11:15,664 INFO    :         FTrace -   cpu_capacity\n",
-      "2016-05-10 18:11:15,665 INFO    :        TestEnv - Set results folder to:\n",
-      "2016-05-10 18:11:15,665 INFO    :        TestEnv -    /home/derkling/Code/lisa/results/Android_Workloads\n",
-      "2016-05-10 18:11:15,666 INFO    :        TestEnv - Experiment results available also in:\n",
-      "2016-05-10 18:11:15,666 INFO    :        TestEnv -    /home/derkling/Code/lisa/results_latest\n"
+      "2016-12-06 19:28:52,064 INFO    : TestEnv      : Using base path: /home/vagrant/lisa\n",
+      "2016-12-06 19:28:52,065 INFO    : TestEnv      : Loading custom (inline) target configuration\n",
+      "2016-12-06 19:28:52,065 INFO    : TestEnv      : External tools using:\n",
+      "2016-12-06 19:28:52,065 INFO    : TestEnv      :    ANDROID_HOME: /home/vagrant/lisa/tools/android-sdk-linux/\n",
+      "2016-12-06 19:28:52,066 INFO    : TestEnv      :    CATAPULT_HOME: /home/vagrant/lisa/tools/catapult\n",
+      "2016-12-06 19:28:52,066 INFO    : TestEnv      : Devlib modules to load: ['cpufreq']\n",
+      "2016-12-06 19:28:52,066 INFO    : TestEnv      : Connecting Android target [HT6670300102]\n",
+      "2016-12-06 19:28:52,067 INFO    : TestEnv      : Connection settings:\n",
+      "2016-12-06 19:28:52,067 INFO    : TestEnv      :    {'device': 'HT6670300102'}\n",
+      "2016-12-06 19:28:52,146 INFO    : android      : ls command is set to ls -1\n",
+      "2016-12-06 19:28:52,979 INFO    : TestEnv      : Initializing target workdir:\n",
+      "2016-12-06 19:28:52,982 INFO    : TestEnv      :    /data/local/tmp/devlib-target\n",
+      "2016-12-06 19:28:54,953 INFO    : TestEnv      : Topology:\n",
+      "2016-12-06 19:28:54,956 INFO    : TestEnv      :    [[0, 1], [2, 3]]\n",
+      "2016-12-06 19:28:55,857 INFO    : TestEnv      : Enabled tracepoints:\n",
+      "2016-12-06 19:28:55,857 INFO    : TestEnv      :    sched_switch\n",
+      "2016-12-06 19:28:55,858 INFO    : TestEnv      :    sched_overutilized\n",
+      "2016-12-06 19:28:55,858 INFO    : TestEnv      :    sched_contrib_scale_f\n",
+      "2016-12-06 19:28:55,859 INFO    : TestEnv      :    sched_load_avg_cpu\n",
+      "2016-12-06 19:28:55,859 INFO    : TestEnv      :    sched_load_avg_task\n",
+      "2016-12-06 19:28:55,860 INFO    : TestEnv      :    sched_tune_tasks_update\n",
+      "2016-12-06 19:28:55,860 INFO    : TestEnv      :    sched_boost_cpu\n",
+      "2016-12-06 19:28:55,861 INFO    : TestEnv      :    sched_boost_task\n",
+      "2016-12-06 19:28:55,861 INFO    : TestEnv      :    sched_energy_diff\n",
+      "2016-12-06 19:28:55,862 INFO    : TestEnv      :    cpu_frequency\n",
+      "2016-12-06 19:28:55,862 INFO    : TestEnv      :    cpu_idle\n",
+      "2016-12-06 19:28:55,863 INFO    : TestEnv      :    cpu_capacity\n",
+      "2016-12-06 19:28:55,863 INFO    : TestEnv      : Set results folder to:\n",
+      "2016-12-06 19:28:55,863 INFO    : TestEnv      :    /home/vagrant/lisa/results/Android_Workloads\n",
+      "2016-12-06 19:28:55,864 INFO    : TestEnv      : Experiment results available also in:\n",
+      "2016-12-06 19:28:55,864 INFO    : TestEnv      :    /home/vagrant/lisa/results_latest\n"
      ]
     }
    ],
@@ -504,41 +512,44 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "2016-05-10 18:11:17,190 INFO    :       Workload - Workloads available on target:\n",
-      "2016-05-10 18:11:17,192 INFO    :       Workload -   ['YouTube', 'Jankbench']\n",
-      "2016-05-10 18:11:17,193 INFO    : ------------------------\n",
-      "2016-05-10 18:11:17,194 INFO    : Test 1/2: YOUTUBE in STD configuration\n",
-      "2016-05-10 18:11:17,195 INFO    :       Workload - Workloads available on target:\n",
-      "2016-05-10 18:11:17,195 INFO    :       Workload -   ['YouTube', 'Jankbench']\n",
-      "2016-05-10 18:11:18,282 INFO    : Set brightness: 100%\n",
-      "2016-05-10 18:11:18,829 INFO    : Dim screen mode: OFF\n",
-      "2016-05-10 18:11:19,440 INFO    : Screen timeout: 36000 [s]\n",
-      "2016-05-10 18:11:20,631 INFO    : Force manual orientation\n",
-      "2016-05-10 18:11:20,632 INFO    : Set orientation: LANDSCAPE\n",
-      "2016-05-10 18:11:21,776 INFO    : am start -a android.intent.action.VIEW \"https://youtu.be/XSGBVzeBUbk?t=45s\"\n",
-      "2016-05-10 18:11:25,586 INFO    : Play video for 15 [s]\n",
-      "2016-05-10 18:11:42,883 INFO    : Set orientation: AUTO\n",
-      "2016-05-10 18:11:43,971 INFO    : Set orientation: AUTO\n",
-      "2016-05-10 18:11:45,581 INFO    : Set brightness: AUTO\n",
-      "2016-05-10 18:11:46,153 INFO    : Dim screen mode: ON\n",
-      "2016-05-10 18:11:46,705 INFO    : Screen timeout: 30 [s]\n",
-      "2016-05-10 18:11:46,707 INFO    : ------------------------\n",
-      "2016-05-10 18:11:46,708 INFO    : Test 2/2: JANKBENCH in STD configuration\n",
-      "2016-05-10 18:11:46,708 INFO    :       Workload - Workloads available on target:\n",
-      "2016-05-10 18:11:46,709 INFO    :       Workload -   ['YouTube', 'Jankbench']\n",
-      "2016-05-10 18:11:47,841 INFO    : Set brightness: 100%\n",
-      "2016-05-10 18:11:48,361 INFO    : Dim screen mode: OFF\n",
-      "2016-05-10 18:11:48,971 INFO    : Screen timeout: 36000 [s]\n",
-      "2016-05-10 18:11:51,289 INFO    : Force manual orientation\n",
-      "2016-05-10 18:11:51,290 INFO    : Set orientation: PORTRAIT\n",
-      "2016-05-10 18:11:52,543 INFO    : am start -n \"com.android.benchmark/.app.RunLocalBenchmarksActivity\" --eia \"com.android.benchmark.EXTRA_ENABLED_BENCHMARK_IDS\" 0 --ei \"com.android.benchmark.EXTRA_RUN_COUNT\" 1\n",
-      "2016-05-10 18:11:53,186 INFO    : adb -s GA0113TP0178 logcat ActivityManager:* System.out:I *:S BENCH:*\n",
-      "2016-05-10 18:12:28,308 INFO    :    Mean:  24.202 JankP:   0.061 StdDev:  21.430 Count Bad:    4 Count Jank:    1\n",
-      "2016-05-10 18:12:31,396 INFO    : Set orientation: AUTO\n",
-      "2016-05-10 18:12:32,452 INFO    : Set orientation: AUTO\n",
-      "2016-05-10 18:12:34,180 INFO    : Set brightness: AUTO\n",
-      "2016-05-10 18:12:34,750 INFO    : Dim screen mode: ON\n",
-      "2016-05-10 18:12:35,320 INFO    : Screen timeout: 30 [s]\n"
+      "2016-12-06 19:29:38,412 INFO    : Workload     : Workloads available on target:\n",
+      "2016-12-06 19:29:38,416 INFO    : Workload     :   ['YouTube', 'Jankbench']\n",
+      "2016-12-06 19:29:38,419 INFO    : root         : ------------------------\n",
+      "2016-12-06 19:29:38,420 INFO    : root         : Test 1/2: YOUTUBE in STD configuration\n",
+      "2016-12-06 19:29:38,421 INFO    : Workload     : Workloads available on target:\n",
+      "2016-12-06 19:29:38,423 INFO    : Workload     :   ['YouTube', 'Jankbench']\n",
+      "2016-12-06 19:29:39,389 INFO    : Screen       : Set brightness: 100%\n",
+      "2016-12-06 19:29:39,873 INFO    : Screen       : Dim screen mode: OFF\n",
+      "2016-12-06 19:29:40,333 INFO    : Screen       : Screen timeout: 36000 [s]\n",
+      "2016-12-06 19:29:40,336 INFO    : System       : SysTrace: /home/vagrant/lisa/tools/catapult/systrace/systrace/run_systrace.py -e HT6670300102 -o /home/vagrant/lisa/results/Android_Workloads/std/YouTube_XSGBVzeBUbk_45s/trace.html gfx view sched freq idle -t 10\n",
+      "2016-12-06 19:29:41,826 INFO    : Screen       : Force manual orientation\n",
+      "2016-12-06 19:29:41,829 INFO    : Screen       : Set orientation: LANDSCAPE\n",
+      "2016-12-06 19:29:45,347 INFO    : YouTube      : Play video for 15 [s]\n",
+      "2016-12-06 19:30:01,445 INFO    : Screen       : Set orientation: AUTO\n",
+      "2016-12-06 19:30:02,322 INFO    : root         : Waiting systrace report [/home/vagrant/lisa/results/Android_Workloads/std/YouTube_XSGBVzeBUbk_45s/trace.html]...\n",
+      "2016-12-06 19:30:02,323 INFO    : Screen       : Set orientation: AUTO\n",
+      "2016-12-06 19:30:03,628 INFO    : Screen       : Set brightness: AUTO\n",
+      "2016-12-06 19:30:04,065 INFO    : Screen       : Dim screen mode: ON\n",
+      "2016-12-06 19:30:04,500 INFO    : Screen       : Screen timeout: 30 [s]\n",
+      "2016-12-06 19:30:04,602 INFO    : root         : ------------------------\n",
+      "2016-12-06 19:30:04,603 INFO    : root         : Test 2/2: JANKBENCH in STD configuration\n",
+      "2016-12-06 19:30:04,604 INFO    : Workload     : Workloads available on target:\n",
+      "2016-12-06 19:30:04,604 INFO    : Workload     :   ['YouTube', 'Jankbench']\n",
+      "2016-12-06 19:30:05,629 INFO    : Screen       : Set brightness: 100%\n",
+      "2016-12-06 19:30:06,085 INFO    : Screen       : Dim screen mode: OFF\n",
+      "2016-12-06 19:30:06,559 INFO    : Screen       : Screen timeout: 36000 [s]\n",
+      "2016-12-06 19:30:06,562 INFO    : System       : SysTrace: /home/vagrant/lisa/tools/catapult/systrace/systrace/run_systrace.py -e HT6670300102 -o /home/vagrant/lisa/results/Android_Workloads/std/Jankbench_list_view/trace.html gfx view sched freq idle -t 10\n",
+      "2016-12-06 19:30:09,377 INFO    : Screen       : Force manual orientation\n",
+      "2016-12-06 19:30:09,378 INFO    : Screen       : Set orientation: PORTRAIT\n",
+      "2016-12-06 19:30:10,322 INFO    : Jankbench    : am start -n \"com.android.benchmark/.app.RunLocalBenchmarksActivity\" --eia \"com.android.benchmark.EXTRA_ENABLED_BENCHMARK_IDS\" 0 --ei \"com.android.benchmark.EXTRA_RUN_COUNT\" 1\n",
+      "2016-12-06 19:30:10,785 INFO    : Jankbench    : adb -s HT6670300102 logcat ActivityManager:* System.out:I *:S BENCH:*\n",
+      "2016-12-06 19:30:45,646 INFO    : Jankbench    :    Mean:  29.949 JankP:   0.061 StdDev:  24.786 Count Bad:    2 Count Jank:    1\n",
+      "2016-12-06 19:30:48,273 INFO    : Screen       : Set orientation: AUTO\n",
+      "2016-12-06 19:30:50,116 INFO    : root         : Waiting systrace report [/home/vagrant/lisa/results/Android_Workloads/std/Jankbench_list_view/trace.html]...\n",
+      "2016-12-06 19:30:50,117 INFO    : Screen       : Set orientation: AUTO\n",
+      "2016-12-06 19:30:51,516 INFO    : Screen       : Set brightness: AUTO\n",
+      "2016-12-06 19:30:51,946 INFO    : Screen       : Dim screen mode: ON\n",
+      "2016-12-06 19:30:52,340 INFO    : Screen       : Screen timeout: 30 [s]\n"
      ]
     }
    ],
@@ -586,7 +597,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 16,
+   "execution_count": 14,
    "metadata": {
     "collapsed": false
    },
@@ -627,7 +638,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython2",
-   "version": "2.7.9"
+   "version": "2.7.6"
   },
   "toc": {
    "toc_cell": false,
diff --git a/ipynb/android/workloads/Android_YouTube.ipynb b/ipynb/android/workloads/Android_YouTube.ipynb
index f430553..e03dfcb 100644
--- a/ipynb/android/workloads/Android_YouTube.ipynb
+++ b/ipynb/android/workloads/Android_YouTube.ipynb
@@ -25,7 +25,16 @@
    "metadata": {
     "collapsed": false
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2016-12-06 19:46:08,105 INFO    : root         : Using LISA logging configuration:\n",
+      "2016-12-06 19:46:08,106 INFO    : root         :   /home/vagrant/lisa/logging.conf\n"
+     ]
+    }
+   ],
    "source": [
     "import logging\n",
     "from conf import LisaLogging\n",
@@ -51,7 +60,6 @@
     "%pylab inline\n",
     "\n",
     "import os\n",
-    "import pexpect as pe\n",
     "from time import sleep\n",
     "\n",
     "# Support to access the remote target\n",
@@ -60,6 +68,9 @@
     "\n",
     "from devlib.utils.android import adb_command\n",
     "\n",
+    "# Import support for Android devices\n",
+    "from android import System\n",
+    "\n",
     "# Support for trace events analysis\n",
     "from trace import Trace\n",
     "\n",
@@ -68,18 +79,6 @@
    ]
   },
   {
-   "cell_type": "code",
-   "execution_count": 3,
-   "metadata": {
-    "collapsed": true
-   },
-   "outputs": [],
-   "source": [
-    "# Set it to your local CATAPULT home folder\n",
-    "CATAPULT_HOME = \"/home/pippo/work/catapult\""
-   ]
-  },
-  {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
@@ -95,7 +94,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 3,
    "metadata": {
     "collapsed": false
    },
@@ -108,10 +107,13 @@
     "    \"platform\"    : 'android',\n",
     "\n",
     "    # Add target support\n",
-    "    \"board\" : 'n5x',\n",
+    "    \"board\" : 'pixel',\n",
     "    \n",
     "    # Device ID\n",
-    "    #\"device\" : \"00b1346f0878ccb1\",\n",
+    "    \"device\" : \"HT6670300102\",\n",
+    "    \n",
+    "    # ANDROID_HOME\n",
+    "    \"ANDROID_HOME\"  : '/home/vagrant/lisa/tools/android-sdk-linux/',\n",
     "    \n",
     "    # Define devlib modules to load\n",
     "    \"modules\"     : [\n",
@@ -122,7 +124,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 4,
    "metadata": {
     "collapsed": false,
     "scrolled": false
@@ -162,7 +164,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 5,
    "metadata": {
     "collapsed": false
    },
@@ -182,7 +184,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 6,
    "metadata": {
     "collapsed": false,
     "scrolled": true
@@ -192,26 +194,36 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "2016-04-12 15:20:10,656 INFO    :         Target - Using base path: /home/pippo/work/lisa\n",
-      "2016-04-12 15:20:10,657 INFO    :         Target - Loading custom (inline) target configuration\n",
-      "2016-04-12 15:20:10,658 INFO    :         Target - Loading custom (inline) test configuration\n",
-      "2016-04-12 15:20:10,659 INFO    :         Target - Devlib modules to load: ['bl', 'cpufreq']\n",
-      "2016-04-12 15:20:10,660 INFO    :         Target - Connecting Android target [DEFAULT]\n",
-      "2016-04-12 15:20:11,142 INFO    :         Target - Initializing target workdir:\n",
-      "2016-04-12 15:20:11,144 INFO    :         Target -    /data/local/tmp/devlib-target\n",
-      "2016-04-12 15:20:13,757 INFO    :         Target - Topology:\n",
-      "2016-04-12 15:20:13,759 INFO    :         Target -    [[0, 1, 2, 3], [4, 5]]\n",
-      "2016-04-12 15:20:14,399 INFO    :         FTrace - Enabled tracepoints:\n",
-      "2016-04-12 15:20:14,400 INFO    :         FTrace -   sched_switch\n",
-      "2016-04-12 15:20:14,401 INFO    :         FTrace -   sched_load_avg_cpu\n",
-      "2016-04-12 15:20:14,402 INFO    :         FTrace -   cpu_frequency\n",
-      "2016-04-12 15:20:14,402 INFO    :         FTrace -   cpu_capacity\n",
-      "2016-04-12 15:20:14,403 WARNING :        TestEnv - Wipe previous contents of the results folder:\n",
-      "2016-04-12 15:20:14,404 WARNING :        TestEnv -    /home/pippo/work/lisa/results/Android_Youtube\n",
-      "2016-04-12 15:20:14,434 INFO    :        TestEnv - Set results folder to:\n",
-      "2016-04-12 15:20:14,435 INFO    :        TestEnv -    /home/pippo/work/lisa/results/Android_Youtube\n",
-      "2016-04-12 15:20:14,435 INFO    :        TestEnv - Experiment results available also in:\n",
-      "2016-04-12 15:20:14,435 INFO    :        TestEnv -    /home/pippo/work/lisa/results_latest\n"
+      "2016-12-06 19:46:11,262 INFO    : TestEnv      : Using base path: /home/vagrant/lisa\n",
+      "2016-12-06 19:46:11,263 INFO    : TestEnv      : Loading custom (inline) target configuration\n",
+      "2016-12-06 19:46:11,264 INFO    : TestEnv      : Loading custom (inline) test configuration\n",
+      "2016-12-06 19:46:11,264 INFO    : TestEnv      : External tools using:\n",
+      "2016-12-06 19:46:11,264 INFO    : TestEnv      :    ANDROID_HOME: /home/vagrant/lisa/tools/android-sdk-linux/\n",
+      "2016-12-06 19:46:11,265 INFO    : TestEnv      :    CATAPULT_HOME: /home/vagrant/lisa/tools/catapult\n",
+      "2016-12-06 19:46:11,265 INFO    : TestEnv      : Loading board:\n",
+      "2016-12-06 19:46:11,266 INFO    : TestEnv      :    /home/vagrant/lisa/libs/utils/platforms/pixel.json\n",
+      "2016-12-06 19:46:11,266 INFO    : TestEnv      : Devlib modules to load: [u'bl', u'cpufreq']\n",
+      "2016-12-06 19:46:11,267 INFO    : TestEnv      : Connecting Android target [HT6670300102]\n",
+      "2016-12-06 19:46:11,267 INFO    : TestEnv      : Connection settings:\n",
+      "2016-12-06 19:46:11,267 INFO    : TestEnv      :    {'device': 'HT6670300102'}\n",
+      "2016-12-06 19:46:11,355 INFO    : android      : ls command is set to ls -1\n",
+      "2016-12-06 19:46:12,105 INFO    : TestEnv      : Initializing target workdir:\n",
+      "2016-12-06 19:46:12,108 INFO    : TestEnv      :    /data/local/tmp/devlib-target\n",
+      "2016-12-06 19:46:14,169 INFO    : TestEnv      : Topology:\n",
+      "2016-12-06 19:46:14,171 INFO    : TestEnv      :    [[0, 1], [2, 3]]\n",
+      "2016-12-06 19:46:14,400 INFO    : TestEnv      : Loading default EM:\n",
+      "2016-12-06 19:46:14,400 INFO    : TestEnv      :    /home/vagrant/lisa/libs/utils/platforms/pixel.json\n",
+      "2016-12-06 19:46:15,115 INFO    : TestEnv      : Enabled tracepoints:\n",
+      "2016-12-06 19:46:15,116 INFO    : TestEnv      :    sched_switch\n",
+      "2016-12-06 19:46:15,116 INFO    : TestEnv      :    sched_load_avg_cpu\n",
+      "2016-12-06 19:46:15,117 INFO    : TestEnv      :    cpu_frequency\n",
+      "2016-12-06 19:46:15,117 INFO    : TestEnv      :    cpu_capacity\n",
+      "2016-12-06 19:46:15,118 WARNING : TestEnv      : Wipe previous contents of the results folder:\n",
+      "2016-12-06 19:46:15,118 WARNING : TestEnv      :    /home/vagrant/lisa/results/Android_Youtube\n",
+      "2016-12-06 19:46:15,129 INFO    : TestEnv      : Set results folder to:\n",
+      "2016-12-06 19:46:15,129 INFO    : TestEnv      :    /home/vagrant/lisa/results/Android_Youtube\n",
+      "2016-12-06 19:46:15,130 INFO    : TestEnv      : Experiment results available also in:\n",
+      "2016-12-06 19:46:15,130 INFO    : TestEnv      :    /home/vagrant/lisa/results_latest\n"
      ]
     }
    ],
@@ -239,7 +251,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 7,
    "metadata": {
     "collapsed": true
    },
@@ -271,7 +283,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 8,
    "metadata": {
     "collapsed": false
    },
@@ -307,7 +319,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 9,
    "metadata": {
     "collapsed": true
    },
@@ -345,14 +357,12 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": 10,
    "metadata": {
     "collapsed": false
    },
    "outputs": [],
    "source": [
-    "SYSTRACE_CMD  = CATAPULT_HOME + \"/systrace/systrace/systrace.py -o {} gfx view sched freq idle -t {}\"\n",
-    "\n",
     "def experiment(governor, exp_dir,  collect='ftrace', trace_time=30):\n",
     "    os.system('mkdir -p {}'.format(exp_dir));\n",
     "\n",
@@ -367,9 +377,7 @@
     "    elif 'systrace' in collect:\n",
     "        # Start systrace\n",
     "        trace_file = os.path.join(exp_dir, 'trace.html')\n",
-    "        trace_cmd = SYSTRACE_CMD.format(trace_file, trace_time)\n",
-    "        logging.info('SysTrace: %s', trace_cmd)\n",
-    "        systrace_output = pe.spawn(trace_cmd)\n",
+    "        systrace_output = System.systrace_start(te, trace_file, trace_time)\n",
     "\n",
     "    ### Run the benchmark ###\n",
     "    framestats_file = youtube_run(exp_dir, \"https://youtu.be/XSGBVzeBUbk?t=45s\", trace_time)\n",
@@ -381,8 +389,11 @@
     "        trace_file = os.path.join(exp_dir, 'trace.dat')\n",
     "        te.ftrace.get_trace(trace_file)\n",
     "    elif 'systrace' in collect:\n",
-    "        logging.info('Waiting systrace report [%s]...', trace_file)\n",
-    "        systrace_output.wait()   \n",
+    "        if systrace_output:\n",
+    "            logging.info('Waiting systrace report [%s]...', trace_file)\n",
+    "            systrace_output.wait()\n",
+    "        else:\n",
+    "            logging.warning('Systrace is not running!') \n",
     "\n",
     "    # Parse trace\n",
     "    tr = Trace(te.platform, trace_file,\n",
@@ -406,7 +417,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 11,
    "metadata": {
     "collapsed": false,
     "scrolled": true
@@ -416,20 +427,39 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "2016-04-12 15:20:15,080 INFO    : ------------------------\n",
-      "2016-04-12 15:20:15,081 INFO    : Run workload using performance governor\n",
-      "2016-04-12 15:20:15,219 INFO    : SysTrace: /home/pippo/work/catapult/systrace/systrace/systrace.py -o /home/pippo/work/lisa/results/Android_Youtube/performance/trace.html gfx view sched freq idle -t 15\n",
-      "2016-04-12 15:20:37,068 INFO    : Waiting systrace report [/home/pippo/work/lisa/results/Android_Youtube/performance/trace.html]...\n",
-      "2016-04-12 15:20:42,981 INFO    : Parsing SysTrace format...\n",
-      "2016-04-12 15:20:44,844 INFO    : Collected events spans a 3.673 [s] time interval\n",
-      "2016-04-12 15:20:44,845 INFO    : Set plots time range to (0.000000, 3.672542)[s]\n",
-      "2016-04-12 15:20:45,134 INFO    : ------------------------\n",
-      "2016-04-12 15:20:45,135 INFO    : Run workload using interactive governor\n",
-      "2016-04-12 15:20:45,177 INFO    : SysTrace: /home/pippo/work/catapult/systrace/systrace/systrace.py -o /home/pippo/work/lisa/results/Android_Youtube/interactive/trace.html gfx view sched freq idle -t 15\n",
-      "2016-04-12 15:21:08,083 INFO    : Waiting systrace report [/home/pippo/work/lisa/results/Android_Youtube/interactive/trace.html]...\n",
-      "2016-04-12 15:21:25,486 INFO    : Parsing SysTrace format...\n",
-      "2016-04-12 15:21:27,296 INFO    : Collected events spans a 3.450 [s] time interval\n",
-      "2016-04-12 15:21:27,296 INFO    : Set plots time range to (0.000000, 3.449909)[s]\n"
+      "2016-12-06 19:46:21,457 INFO    : root         : ------------------------\n",
+      "2016-12-06 19:46:21,458 INFO    : root         : Run workload using performance governor\n",
+      "2016-12-06 19:46:21,556 INFO    : System       : SysTrace: /home/vagrant/lisa/tools/catapult/systrace/systrace/run_systrace.py -e HT6670300102 -o /home/vagrant/lisa/results/Android_Youtube/performance/trace.html gfx view sched freq idle -t 15\n",
+      "2016-12-06 19:46:42,226 INFO    : root         : Waiting systrace report [/home/vagrant/lisa/results/Android_Youtube/performance/trace.html]...\n",
+      "2016-12-06 19:46:43,203 INFO    : Trace        : Parsing SysTrace format...\n",
+      "2016-12-06 19:46:48,092 INFO    : Trace        : Collected events spans a 9.888 [s] time interval\n",
+      "2016-12-06 19:46:48,092 INFO    : Trace        : Set plots time range to (0.000000, 9.888454)[s]\n",
+      "2016-12-06 19:46:48,093 INFO    : Analysis     : Registering trace analysis modules:\n",
+      "2016-12-06 19:46:48,094 INFO    : Analysis     :    tasks\n",
+      "2016-12-06 19:46:48,094 INFO    : Analysis     :    status\n",
+      "2016-12-06 19:46:48,095 INFO    : Analysis     :    frequency\n",
+      "2016-12-06 19:46:48,096 INFO    : Analysis     :    cpus\n",
+      "2016-12-06 19:46:48,097 INFO    : Analysis     :    latency\n",
+      "2016-12-06 19:46:48,097 INFO    : Analysis     :    idle\n",
+      "2016-12-06 19:46:48,098 INFO    : Analysis     :    functions\n",
+      "2016-12-06 19:46:48,098 INFO    : Analysis     :    eas\n",
+      "2016-12-06 19:46:48,208 INFO    : root         : ------------------------\n",
+      "2016-12-06 19:46:48,209 INFO    : root         : Run workload using interactive governor\n",
+      "2016-12-06 19:46:48,316 INFO    : System       : SysTrace: /home/vagrant/lisa/tools/catapult/systrace/systrace/run_systrace.py -e HT6670300102 -o /home/vagrant/lisa/results/Android_Youtube/interactive/trace.html gfx view sched freq idle -t 15\n",
+      "2016-12-06 19:47:09,175 INFO    : root         : Waiting systrace report [/home/vagrant/lisa/results/Android_Youtube/interactive/trace.html]...\n",
+      "2016-12-06 19:47:10,185 INFO    : Trace        : Parsing SysTrace format...\n",
+      "2016-12-06 19:47:13,573 INFO    : Trace        : Platform clusters verified to be Frequency coherent\n",
+      "2016-12-06 19:47:15,675 INFO    : Trace        : Collected events spans a 8.481 [s] time interval\n",
+      "2016-12-06 19:47:15,675 INFO    : Trace        : Set plots time range to (0.000000, 8.480988)[s]\n",
+      "2016-12-06 19:47:15,676 INFO    : Analysis     : Registering trace analysis modules:\n",
+      "2016-12-06 19:47:15,676 INFO    : Analysis     :    tasks\n",
+      "2016-12-06 19:47:15,677 INFO    : Analysis     :    status\n",
+      "2016-12-06 19:47:15,677 INFO    : Analysis     :    frequency\n",
+      "2016-12-06 19:47:15,678 INFO    : Analysis     :    cpus\n",
+      "2016-12-06 19:47:15,678 INFO    : Analysis     :    latency\n",
+      "2016-12-06 19:47:15,679 INFO    : Analysis     :    idle\n",
+      "2016-12-06 19:47:15,680 INFO    : Analysis     :    functions\n",
+      "2016-12-06 19:47:15,680 INFO    : Analysis     :    eas\n"
      ]
     }
    ],
@@ -452,7 +482,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 12,
    "metadata": {
     "collapsed": false
    },
@@ -462,20 +492,22 @@
      "output_type": "stream",
      "text": [
       "Frame Statistics for PERFORMANCE governor\n",
-      "Stats since: 6429956328009ns\n",
-      "Total frames rendered: 549\n",
-      "Janky frames: 65 (11.84%)\n",
-      "90th percentile: 17ms\n",
-      "95th percentile: 34ms\n",
-      "99th percentile: 89ms\n",
+      "Stats since: 107266916813060ns\n",
+      "Total frames rendered: 747\n",
+      "Janky frames: 44 (5.89%)\n",
+      "50th percentile: 5ms\n",
+      "90th percentile: 8ms\n",
+      "95th percentile: 19ms\n",
+      "99th percentile: 113ms\n",
       "\n",
       "Frame Statistics for INTERACTIVE governor\n",
-      "Stats since: 6429956328009ns\n",
-      "Total frames rendered: 665\n",
-      "Janky frames: 88 (13.23%)\n",
-      "90th percentile: 18ms\n",
-      "95th percentile: 36ms\n",
-      "99th percentile: 89ms\n",
+      "Stats since: 107266916813060ns\n",
+      "Total frames rendered: 942\n",
+      "Janky frames: 60 (6.37%)\n",
+      "50th percentile: 5ms\n",
+      "90th percentile: 9ms\n",
+      "95th percentile: 20ms\n",
+      "99th percentile: 113ms\n",
       "\n"
      ]
     }
@@ -490,7 +522,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": 13,
    "metadata": {
     "collapsed": true
    },
@@ -517,7 +549,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython2",
-   "version": "2.7.9"
+   "version": "2.7.6"
   },
   "toc": {
    "toc_cell": false,
diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py
index 7017041..da9a0f9 100644
--- a/libs/utils/android/system.py
+++ b/libs/utils/android/system.py
@@ -19,6 +19,8 @@
 
 from devlib.utils.android import adb_command
 from devlib import TargetError
+import os
+import pexpect as pe
 
 GET_FRAMESTATS_CMD = 'shell dumpsys gfxinfo {} > {}'
 
@@ -28,6 +30,36 @@
     """
 
     @staticmethod
+    def systrace_start(target, trace_file, time,
+                       events=['gfx', 'view', 'sched', 'freq', 'idle']):
+
+        log = logging.getLogger('System')
+
+        # Check which systrace binary is available under CATAPULT_HOME
+        for systrace in ['systrace.py', 'run_systrace.py']:
+                systrace_path = os.path.join(target.CATAPULT_HOME, 'systrace',
+                                             'systrace', systrace)
+                if os.path.isfile(systrace_path):
+                        break
+        else:
+                log.warning("Systrace binary not available under CATAPULT_HOME: %s!",
+                            target.CATAPULT_HOME)
+                return None
+
+        #  Format the command according to the specified time and events
+        systrace_pattern = "{} -e {} -o {} {} -t {}"
+        trace_cmd = systrace_pattern.format(systrace_path, target.conf['device'],
+                                            trace_file, " ".join(events), time)
+        log.info('SysTrace: %s', trace_cmd)
+
+        # Actually spawn systrace
+        return pe.spawn(trace_cmd)
+
+    @staticmethod
+    def systrace_wait(target, systrace_output):
+        systrace_output.wait()
+
+    @staticmethod
     def set_airplane_mode(target, on=True):
         """
         Set airplane mode