Performance issues in writing Android Apps



Similar documents
Using the Android Sensor API

Objective. Android Sensors. Sensor Manager Sensor Types Examples. Page 2

Android Sensors. CPRE 388 Fall 2015 Iowa State University

06 Team Project: Android Development Crash Course; Project Introduction

Sensors & Motion Sensors in Android platform. Minh H Dang CS286 Spring 2013

App Development for Smart Devices. Lec #5: Android Sensors

Android Framework. How to use and extend it

Using Sensors on the Android Platform. Andreas Terzis Android N00b

! Sensors in Android devices. ! Motion sensors. ! Accelerometer. ! Gyroscope. ! Supports various sensor related tasks

Android Fundamentals 1

Developing Sensor Applications on Intel Atom Processor-Based Android* Phones and Tablets

Designing An Android Sensor Subsystem Pitfalls and Considerations

CS11 Java. Fall Lecture 7

Android Sensors. XI Jornadas SLCENT de Actualización Informática y Electrónica

ELET4133: Embedded Systems. Topic 15 Sensors

Threads & Tasks: Executor Framework

Course MS10975A Introduction to Programming. Length: 5 Days

Module 1: Sensor Data Acquisition and Processing in Android

Building an energy dashboard. Energy measurement and visualization in current HPC systems

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Android Sensor Programming. Weihong Yu

Lab 1 (Reading Sensors & The Android API) Week 3

Android Basics. Xin Yang

Pedometer Project 1 Mr. Michaud /

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Android Application Model

Basics of Android Development 1

Obsoleted chapter from The Busy Coder's Guide to Advanced Android Development

Android Application Development

Programming Mobile Applications with Android

Mocean Android SDK Developer Guide

Android. Mobile Computing Design and Implementation. Application Components, Sensors. Peter Börjesson

Outline of this lecture G52CON: Concepts of Concurrency

Android app development course

Enterprise Java (BI-EJA) Technologie programování v jazyku Java (X36TJV)

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

E0-245: ASP. Lecture 16+17: Physical Sensors. Dipanjan Gope

Internal Services. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. Rajiv Ramnath

Mono for Android Activity Lifecycle Activity Lifecycle Concepts and Overview

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

TRACE PERFORMANCE TESTING APPROACH. Overview. Approach. Flow. Attributes

Lecture 1 Introduction to Android

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

CloudCmp:Comparing Cloud Providers. Raja Abhinay Moparthi

Android Concepts and Programming TUTORIAL 1

McAfee Enterprise Mobility Management Performance and Scalability Guide

HPC performance applications on Virtual Clusters

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

How to develop your own app

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Mobile App Sensor Documentation (English Version)

ODROID Multithreading in Android

A model driven approach for Android applications development

Dealing with Device Fragmentation in Mobile Games Testing. Ru Cindrea - Altom Consulting

Android Sensors This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. CC-BY Google

OBJECT ORIENTED PROGRAMMING LANGUAGE

VDI FIT and VDI UX: Composite Metrics Track Good, Fair, Poor Desktop Performance

Chapter 6 Concurrent Programming

Android Programming Lecture 18: Menus Sensors 11/11/2011

A Look through the Android Stack

Automated Performance Testing of Desktop Applications

Take Your Team Mobile with Xamarin

Creating a Windows Service using SAS 9 and VB.NET David Bosak, COMSYS, Kalamazoo, MI

CS 403X Mobile and Ubiquitous Computing Lecture 6: Maps, Sensors, Widget Catalog and Presentations Emmanuel Agu

Android For Java Developers. Marko Gargenta Marakana

Mobile App Testing Process INFLECTICA TECHNOLOGIES (P) LTD

Why Threads Are A Bad Idea (for most purposes)

Frameworks & Android. Programmeertechnieken, Tim Cocx

Use Cases for Large Memory Appliance/Burst Buffer

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

ios Design Patterns Jackie Myrose CSCI 5448 Fall 2012

Disk Storage Shortfall

Java Concurrency Framework. Sidartha Gracias

Multithreading and Java Native Interface (JNI)!

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

User Manual. Medical grade 24/7 Sleep Cycle Alarm, Snore and Apnea Recorder, Resting Heart Rate Monitor, Weight Loss and Activity Tracker

Improved metrics collection and correlation for the CERN cloud storage test framework

Transcription:

Performance issues in writing Android Apps Octav Chipara

The process of developing Android apps problem definition focus: define the problem what is the input/out? what is the criteria for success? develop basic data collection develop a algorithm focus: on accuracy not on energy how do you know you got it right? focus: solve the sensing problem how do you measure the algorithm s performance what factors you affect your algorithm design/choice? integrate on platform focus: deal with the system challegnes 2

The process of developing Android apps Problem Formulation Initial experimental design refine problem formulation Data Collection Initial design refine experimental design Algorithm Design Integrate on Platform 3

Develop a Step-Counter Application

Problem definition Develop an application that counts the number of steps a user takes using a mobile phone using acceleration sensors Problem formulation: input: acceleration samples output: step counts goal: determine f : acceleration => step counts confounding factors? Requirements: it must work reliably for a large population of users it must work reliably for different phone placements 5

Data collection plan Key concern: get an sample that covers many real-world scenarios Collect acceleration readings from the phone from multiple users => necessary to get a diverse set of users from different environments => necessary to ensure reliability try to model user and environmental differences (confounding factors) user variability: hight, stride length phone placement: enforced during data collection environment: floor type, shoe type, etc. 6

Building the data collection application Focus: on data quality rather than application optimization Minimal data collection requirements: collect the data from the accelerometer save on disk straight forward?! How will you validate that the data collected is reasonable? 7

Motion sensors on Android Sensor motion API is straight forward: initialize SensorManager _sensormanager = (SensorManager)_context.getSystemService(android.content.Context.SENSOR_SERVICE); sensormanager.registerlistener(this, _sensormanager.getdefaultsensor(sensor.type_accelerometer), SensorManager.SENSOR_DELAY_FASTEST); get readings public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; For best performance you should keep the CPU awake! 8

Power Management API on Android Android uses power-locks to manage power use carefully => it significantly affects the power consumption of your phone PowerManager _powermanger = (PowerManager) context.getsystemservice(context.power_service); _wakelock = _powermanger.newwakelock(powermanager.partial_wake_lock, "accelerometer"); @Override public void onstart() { _wakelock.acquire(); @Override public void onstop() { _wakelock.release(); Why did I put the release of the wake lock onstop() rather than onpause()? 9

Sensor loops Sensor loops are performance critical routines you cannot do too much onsensorchange() is called by Android s sensor thread long processing times onsensorchange() will result in DROPPED values! public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; open file save event to file close file 10

Sensor loops File IO is generally slow and costs lots of energy! public void oncreate() { open file public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; save event to file public void onstop() { close file 11

Sensor loops public void oncreate() { open file public void savetofile (SensorEvent event) { save event to file public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; savetofile(event); public void onstop() { close file Still executed within the same thread! 12

A multi-thread approach Sensor thread ToDisk thread UI thread Multi-threaded approach: you have to create a new thread to hand the saving to disk => decouples the data collection from the writing on disk (that takes long time) This is called a producer-consumer problem challenge exchange data between threads in a thread-safe manner 13

Producer/Consumer class Producer implements Runnable { private final BlockingQueue queue; Producer(BlockingQueue q) { queue = q; public void run() { try { while(true) { queue.put(produce()); catch (InterruptedException ex) { handle Object produce() { class Consumer implements Runnable { private final BlockingQueue queue; Consumer(BlockingQueue q) { queue = q; public void run() { try { while(true) { consume(queue.take()); catch (InterruptedException ex) { handle void consume(object x) { 14

Producer/Consumer class Setup { void main() { BlockingQueue q = new SomeQueueImplementation(); Producer p = new Producer(q); Consumer c1 = new Consumer(q); Consumer c2 = new Consumer(q); new Thread(p).start(); new Thread(c1).start(); new Thread(c2).start(); 15

Back to our problem producer: BlockingQueue _queue; public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; MyEvent mevent = new MyEvent(); copy event fields into mevent Copying is necessary because the values field in SensorEvent is final! _queue.put(mevent); consumer: public void run(sensorevent event) { try { while(true) { event = _queue.take(); save to disk (event) catch (InterruptedException ex) { handle this will cause the garbage collector to fire very often => loose data 16

Preallocate memory producer: BlockingQueue _queue; BlockingQueue _memoryqueue = add N mevents public void onsensorchanged(sensorevent event) { if (event.sensor.gettype()!= Sensor.TYPE_ACCELEROMETER) return; MyEvent mevent = _memoryqueue.takes() copy event fields into mevent _queue.put(mevent); consumer: public void run(sensorevent event) { while(true) { event = _queue.take(); save to disk (event); _memoryqueue.put(event); 17

Check the data collection prototype Metrics to ensure that it works no gaps in data, possible through visual data inspection plot the distribution of the time differences between consecutive samples (should be relatively narrow) 18

A few other tips on writing performance code 19