aboutsummaryrefslogtreecommitdiff
path: root/ipynb/examples/android/workloads/Android_Viewer.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'ipynb/examples/android/workloads/Android_Viewer.ipynb')
-rw-r--r--ipynb/examples/android/workloads/Android_Viewer.ipynb321
1 files changed, 321 insertions, 0 deletions
diff --git a/ipynb/examples/android/workloads/Android_Viewer.ipynb b/ipynb/examples/android/workloads/Android_Viewer.ipynb
new file mode 100644
index 0000000..a3bd270
--- /dev/null
+++ b/ipynb/examples/android/workloads/Android_Viewer.ipynb
@@ -0,0 +1,321 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
+ "source": [
+ "# Generic Android viewer"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "from conf import LisaLogging\n",
+ "LisaLogging.setup()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "%pylab inline\n",
+ "\n",
+ "import json\n",
+ "import os\n",
+ "\n",
+ "# Support to access the remote target\n",
+ "import devlib\n",
+ "from env import TestEnv\n",
+ "\n",
+ "# Import support for Android devices\n",
+ "from android import Screen, Workload, System, ViewerWorkload\n",
+ "from target_script import TargetScript\n",
+ "\n",
+ "# Support for trace events analysis\n",
+ "from trace import Trace\n",
+ "\n",
+ "# Suport for FTrace events parsing and visualization\n",
+ "import trappy\n",
+ "\n",
+ "import pandas as pd\n",
+ "import sqlite3\n",
+ "\n",
+ "from IPython.display import display"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
+ "source": [
+ "# Test environment setup\n",
+ "\n",
+ "For more details on this please check out **examples/utils/testenv_example.ipynb**.\n",
+ "\n",
+ "**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 a cell to define where your Android SDK is installed or specify the ANDROID_HOME in your target configuration.\n",
+ "\n",
+ "In case more than one Android device are connected to the host, you must specify the ID of the device you want to target in **my_target_conf**. Run **adb devices** on your host to get the ID."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "# Setup target configuration\n",
+ "my_conf = {\n",
+ "\n",
+ " # Target platform and board\n",
+ " \"platform\" : 'android',\n",
+ " \"board\" : 'hikey960',\n",
+ " \n",
+ " # Device serial ID\n",
+ " # Not required if there is only one device connected to your computer\n",
+ " \"device\" : \"0123456789ABCDEF\",\n",
+ " \n",
+ " # Android home\n",
+ " # Not required if already exported in your .bashrc\n",
+ " #\"ANDROID_HOME\" : \"/home/vagrant/lisa/tools/\",\n",
+ "\n",
+ " # Folder where all the results will be collected\n",
+ " \"results_dir\" : \"Viewer_example\",\n",
+ "\n",
+ " # Define devlib modules to load\n",
+ " \"modules\" : [\n",
+ " 'cpufreq' # enable CPUFreq support\n",
+ " ],\n",
+ "\n",
+ " # FTrace events to collect for all the tests configuration which have\n",
+ " # the \"ftrace\" flag enabled\n",
+ " \"ftrace\" : {\n",
+ " \"events\" : [\n",
+ " \"sched_switch\",\n",
+ " \"sched_wakeup\",\n",
+ " \"sched_wakeup_new\",\n",
+ " \"sched_overutilized\",\n",
+ " \"sched_load_avg_cpu\",\n",
+ " \"sched_load_avg_task\",\n",
+ " \"sched_load_waking_task\",\n",
+ " \"cpu_capacity\",\n",
+ " \"cpu_frequency\",\n",
+ " \"cpu_idle\",\n",
+ " \"sched_tune_config\",\n",
+ " \"sched_tune_tasks_update\",\n",
+ " \"sched_tune_boostgroup_update\",\n",
+ " \"sched_tune_filter\",\n",
+ " \"sched_boost_cpu\",\n",
+ " \"sched_boost_task\",\n",
+ " \"sched_energy_diff\"\n",
+ " ],\n",
+ " \"buffsize\" : 100 * 1024,\n",
+ " },\n",
+ "\n",
+ " # Tools required by the experiments\n",
+ " \"tools\" : [ 'trace-cmd', 'taskset'],\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "# Initialize a test environment using:\n",
+ "te = TestEnv(my_conf, wipe=False)\n",
+ "target = te.target"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
+ "source": [
+ "# Workload definition\n",
+ "\n",
+ "The Viewer workload will simply read an URI and let Android pick the best application to view the item designated by that URI. That item could be a web page, a photo, a pdf, etc. For instance, if given an URL to a Google Maps location, the Google Maps application will be opened at that location. If the device doesn't have Google Play Services (e.g. HiKey960), it will open Google Maps through the default web browser.\n",
+ "\n",
+ "The Viewer class is intended to be subclassed to customize your workload. There are pre_interact(), interact() and post_interact() methods that are made to be overridden.\n",
+ "\n",
+ "In this case we'll simply execute a script on the target to swipe around a location on Gmaps. This script is generated using the TargetScript class, which is used here on System.{h,v}swipe() calls to accumulate commands instead of executing them directly. Those commands are then outputted to a script on the remote device, and that script is later on executed as the item is being viewed. See **${LISA_HOME}/libs/util/target_script.py**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "class GmapsViewer(ViewerWorkload):\n",
+ " \n",
+ " def pre_interact(self):\n",
+ " self.script = TargetScript(te, \"gmaps_swiper.sh\")\n",
+ "\n",
+ " # Define commands to execute during experiment\n",
+ " for i in range(2):\n",
+ " System.hswipe(self.script, 40, 60, 100, False)\n",
+ " self.script.append('sleep 1')\n",
+ " System.vswipe(self.script, 40, 60, 100, True)\n",
+ " self.script.append('sleep 1')\n",
+ " System.hswipe(self.script, 40, 60, 100, True)\n",
+ " self.script.append('sleep 1')\n",
+ " System.vswipe(self.script, 40, 60, 100, False)\n",
+ " self.script.append('sleep 1')\n",
+ "\n",
+ " # Push script to the target\n",
+ " self.script.push()\n",
+ " \n",
+ " def interact(self):\n",
+ " self.script.run()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "def experiment():\n",
+ " # Configure governor\n",
+ " target.cpufreq.set_all_governors('sched')\n",
+ " \n",
+ " # Get workload\n",
+ " wload = Workload.getInstance(te, 'gmapsviewer')\n",
+ " \n",
+ " # Run workload\n",
+ " wload.run(out_dir=te.res_dir,\n",
+ " collect=\"ftrace\",\n",
+ " uri=\"https://goo.gl/maps/D8Sn3hxsHw62\")\n",
+ " \n",
+ " # Dump platform descriptor\n",
+ " te.platform_dump(te.res_dir)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
+ "source": [
+ "# Workload execution"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true,
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "results = experiment()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true
+ },
+ "outputs": [],
+ "source": [
+ "# Load traces in memory (can take several minutes)\n",
+ "platform_file = os.path.join(te.res_dir, 'platform.json')\n",
+ "\n",
+ "with open(platform_file, 'r') as fh:\n",
+ " platform = json.load(fh)\n",
+ "\n",
+ "trace_file = os.path.join(te.res_dir, 'trace.dat')\n",
+ "trace = Trace(platform, trace_file, events=my_conf['ftrace']['events'], normalize_time=False)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "deletable": true,
+ "editable": true
+ },
+ "source": [
+ "# Traces visualisation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false,
+ "deletable": true,
+ "editable": true,
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "!kernelshark {trace_file} 2>/dev/null"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.6"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}