Finding sensor related energy black holes in smartphone applications

63
Finding Sensor Related Energy Black Holes In Smartphone Applications Yepang Liu 1 , Chang Xu 2 , S.C. Cheung 1 1 The Hong Kong University of Science and Technology 2 State Key Lab for Novel Software, Nanjing University IEEE PerCom2013 San Diego, California, USA

description

My talk slides at IEEE PerCom 2013. Link to paper: http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6526708 http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6815752

Transcript of Finding sensor related energy black holes in smartphone applications

Page 1: Finding sensor related energy black holes in smartphone applications

Finding Sensor Related Energy Black Holes In Smartphone Applications

Yepang Liu1, Chang Xu2, S.C. Cheung1

1The Hong Kong University of Science and Technology2State Key Lab for Novel Software, Nanjing University

IEEE PerCom 2013

San Diego, California, USA

Page 2: Finding sensor related energy black holes in smartphone applications

25+ billion downloads (September 2012)

650,000+ applications (September 2012)

Smartphone apps

1/29

Page 3: Finding sensor related energy black holes in smartphone applications

Energy Problem

Full Network access

Frequent sensor usage 3D rendering

2/29

Page 4: Finding sensor related energy black holes in smartphone applications

Energy Problem

Full Network access

Frequent sensor usage 3D rendering

Annual density improvement very slow (6%)

Energy Inefficiency

2/29

Page 5: Finding sensor related energy black holes in smartphone applications

Energy Problem

• Problem magnitude– Thousands of apps are NOT energy efficient

– Millions of users affected and complained

– Phone batteries drained in a few hours

• Major reasons– Hardware management burden (e.g., sensors)

– Lack of dedicated QA, short time to market

– Difficulty in problem diagnosis

3/29

(Pathak et al. Hotnets 2011)

Page 6: Finding sensor related energy black holes in smartphone applications

Motivation

• What are the common causes of energy problems?

• Can we distill patterns to enable automated diagnosis?

4/29

Page 7: Finding sensor related energy black holes in smartphone applications

Our Work

Investigation

•Diagnosis difficulty

•Common causes

Evaluation

•Effectiveness

•Efficiency

Automated diagnosis

•State exploration

•Energy efficiency analysis

5/29

Page 8: Finding sensor related energy black holes in smartphone applications

Investigated Subjects

7/29

10

33

136

SourceForge

GitHub

Google Code

0 40 80 120 160

App Availability Distribution

174 popular open-source Android apps

Page 9: Finding sensor related energy black holes in smartphone applications

Investigated Subjects

Source Repository (24 affected apps)

� Bug reports

� Comments on bug reports

� Bug fixing patches

� Revision commit logs

7/29

10

33

136

SourceForge

GitHub

Google Code

0 40 80 120 160

App Availability Distribution

174 popular open-source Android apps

Page 10: Finding sensor related energy black holes in smartphone applications

Observations

8/29

• Reproduce problem (extensive testing, energy profiling)

• Figure out root cause (instrumentation, runtime logging)

Diagnosis difficulty

Page 11: Finding sensor related energy black holes in smartphone applications

Observations

• Reproduce problem (extensive testing, energy profiling)

• Figure out root cause (instrumentation, runtime logging)

Diagnosis difficulty

• Common causes (10/24): improper use of sensors

Problem causes

8/29

Page 12: Finding sensor related energy black holes in smartphone applications

Patterns

• Sensor listener misusage

9/29

R

Registration

(All executions)

Page 13: Finding sensor related energy black holes in smartphone applications

Patterns

• Sensor listener misusage

9/29

R

“Always un-register sensor listener before program exits!”

UnregistrationRegistration

U (All executions)

Page 14: Finding sensor related energy black holes in smartphone applications

Patterns

• Sensor listener misusage

9/29

R

“Always un-register sensor listener before program exits!”

UnregistrationRegistration

U (All executions)

• Sensory data underutilization

R U (Execution 1)

Location data well utilized

Page 15: Finding sensor related energy black holes in smartphone applications

Patterns

• Sensor listener misusage

9/29

R

“Always un-register sensor listener before program exits!”

UnregistrationRegistration

U (All executions)

• Sensory data underutilization

R U (Execution 1)

Location data well utilized

R R U (Execution 2)

Poor utilization

Page 16: Finding sensor related energy black holes in smartphone applications

Sensory Data Underutilization

9/29

R U (Execution 1)

Location data well utilized

R R U (Execution 2)

Poor utilization

“GeoHashDroid should slow down sensor update significantly ifnothing besides the notification bar is listening.”

(GeoHashDroid Issue 24)

“GPS sensor should be timely disabled if location data are usedto update an invisible map.”

(Osmdroid Issue 53)

Page 17: Finding sensor related energy black holes in smartphone applications

Approach Overview (GreenDroid)

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

11/29

Page 18: Finding sensor related energy black holes in smartphone applications

Approach Overview (GreenDroid)

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

11/29

Java PathFinder

Sensory Data Utilization Analyzer

Runtime Controller

Application Under Analysis

*.class

*.xml

Analysis Report

• Application state• Energy inefficiency

Page 19: Finding sensor related energy black holes in smartphone applications

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

11/29

Java PathFinder

Sensory Data Utilization Analyzer

Runtime Controller

Application Under Analysis

*.class

*.xml

Analysis Report

• Application state• Energy inefficiency

Input Output

Approach Overview (GreenDroid)

Page 20: Finding sensor related energy black holes in smartphone applications

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

11/29

Java PathFinder

Sensory Data Utilization Analyzer

Runtime Controller

Application Under Analysis

*.class

*.xml

Analysis Report

• Application state• Energy inefficiency

1. Event generation2.State exploration

Approach Overview (GreenDroid)

Page 21: Finding sensor related energy black holes in smartphone applications

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

11/29

Java PathFinder

Sensory Data Utilization Analyzer

Runtime Controller

Application Under Analysis

*.class

*.xml

Analysis Report

• Application state• Energy inefficiency

1. Sensory data tracking2.Utilization analysis3.Sensor listener usage monitoring

Approach Overview (GreenDroid)

Page 22: Finding sensor related energy black holes in smartphone applications

• Dynamic analysis (on top of Java PathFinder)

• Goal: Simple, scalable, and effective

• Major Challenges

– App execution and state exploration in Java PathFinder

– Sensory data identification and utilization analysis (no metrics)

11/29

Java PathFinder

Sensory Data Utilization Analyzer

Runtime Controller

Application Under Analysis

*.class

*.xml

Analysis Report

• Application state• Energy inefficiency

Approach Overview (GreenDroid)

Page 23: Finding sensor related energy black holes in smartphone applications

12/29

General Java programs(explicit control flow)

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Problems)

Page 24: Finding sensor related energy black holes in smartphone applications

12/29

General Java programs(explicit control flow)

Android programs (event-driven)

VS

Class C• Handler 1• Handler 2• …• Handler n

Class B• Handler 1• Handler 2• …• Handler n

Class A• Handler 1• Handler 2• …• Handler n

Loosely coupled handlers

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Problems)

Page 25: Finding sensor related energy black holes in smartphone applications

12/29

Applications

Frameworks

Libs Dalvik VM

Linux Kernel

Android Platform

Scheduled by

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Problems)

Implicit control flow

Page 26: Finding sensor related energy black holes in smartphone applications

12/29

Applications

Frameworks

Libs Dalvik VM

Linux Kernel

Android Platform

Scheduled by

Mostlynative!

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Problems)

Implicit control flow

Page 27: Finding sensor related energy black holes in smartphone applications

12/29

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Problems)

Page 28: Finding sensor related energy black holes in smartphone applications

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

13/29

Android Specs Temporal rules (AEM Model)

Handler scheduling policies

Temporal rules (AEM Model)

Input: (1) app execution history(2) Newly received event

Output: next handler to execute

Decision procedure

Concretization

Page 29: Finding sensor related energy black holes in smartphone applications

14/29

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

Page 30: Finding sensor related energy black holes in smartphone applications

14/29

Identify native methods

Native method

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

Page 31: Finding sensor related energy black holes in smartphone applications

14/29

Identify native methods

Create stubs (native peers)Native peer

Native method

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

Page 32: Finding sensor related energy black holes in smartphone applications

14/29

Identify native methods

Create stubs (native peers)

Implement logics

Native peer

Native method

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

Page 33: Finding sensor related energy black holes in smartphone applications

15/29

Application configurations

Activity 1

……

Activity n

GUI Layout

GUI Layout

Association

Association

GUI Layout Analysis (Static)

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

Page 34: Finding sensor related energy black holes in smartphone applications

15/29

• Absence of explicit control flow (event-driven)

• Heavy reliance on native system libs (platform specific)

• Essentially interactive (valid user input generation)

App Execution in JPF (Solutions)

JPFJVM

Call stack

onResume()

ListenerVM events

Waiting for user interaction?

Event sequence generation (Dynamic)

Click Long press

Sequence length bounded!

Page 35: Finding sensor related energy black holes in smartphone applications

State Exploration

• State changes as the app continuous handles events (user events, system events etc.)

16/29

(Execution 1)

(Execution 2)

(Execution k)

… …

Event State

Page 36: Finding sensor related energy black holes in smartphone applications

State Exploration

• State changes as the app continuous handles events (user events, system events etc.)

16/29

(Execution 1)

(Execution 2)

(Execution k)

… …

Event StateHow to analyze sensory data utilization?Are they well utilized?

Page 37: Finding sensor related energy black holes in smartphone applications

Sensory Data Tracking & Identification

17/29

Data enter app

Transformed and consumed

Data leave app

Data Lifecycle:

Page 38: Finding sensor related energy black holes in smartphone applications

Sensory Data Tracking & Identification

17/29

Data enter app

Transformed and consumed

Data leave app

Data Lifecycle:

• Taint the mock sensory data

Taint source

Sensory Data tracking process:

Page 39: Finding sensor related energy black holes in smartphone applications

Sensory Data Tracking & Identification

17/29

Data enter app

Transformed and consumed

Data leave app

Data Lifecycle:

• Taint the mock sensory data

Taint source

• Tracking and pinpointing sensory data

• Record sensory data usages

Taint propagation

Sensory Data tracking process:

Page 40: Finding sensor related energy black holes in smartphone applications

Sensory Data Tracking & Identification

17/29

Data enter app

Transformed and consumed

Data leave app

Data Lifecycle:

• Taint the mock sensory data

Taint source

• Tracking and pinpointing sensory data

• Record sensory data usages

Taint propagation

• Terminate tainting

• Compute sensory data utilization

Taint sink

Sensory Data tracking process:

Page 41: Finding sensor related energy black holes in smartphone applications

Taint Propagation Policy

18/29

Index Bytecode Instruction Taint Propagation Rule

1 Const-op C T(stack[0]) = Ø

2 Load-op index T(stack[0]) = T(localVarindex)

3 LoadArray-op arrayRef, index T(stack[0]) = T(arrayRef) ⋃ T(arrayRef [index])

4 Store-op index T(localVarindex) = T(stack’[0])

5 StoreArray-op arrayRef, index T(arrayRef [index]) = T(stack’[0])

6 Binary-op T(stack[0]) = T(stack’[0]) ⋃ T(stack’[1])

7 Unary-op T(stack[0]) = T(stack’[0])

8 GetField-op index T(stack[0]) = T(stack’[0].instanceField) ⋃ T(stack’[0])

9 GetStatic-op index T(stack[0]) = T(ClassName.staticField)

10 PutField-op index T(stack’[1].instanceField) = T(stack’[0])

1 PutStatic-op index T(ClassName.staticField) = T(stack’[0])

12 Return-op(non-void) T(callerStack[0]) = T(calleeStack’[0])

Page 42: Finding sensor related energy black holes in smartphone applications

Example

19/29

float x = values[0];float y = values[1];float z = values[2];

float g = GRAVERTIY_EARTH;

float acc = (x*x + y*y + z*z) / (g*g);

Compute accelerationInput: accEvent from accelerometer

float[] values = accEevent.values;

Page 43: Finding sensor related energy black holes in smartphone applications

Example

19/29

float x = values[0];float y = values[1];float z = values[2];

float g = GRAVERTIY_EARTH;

float acc = (x*x + y*y + z*z) / (g*g);

Compute accelerationInput: accEvent from accelerometer

float[] values = accEevent.values;Tainted Data

accEvent

Page 44: Finding sensor related energy black holes in smartphone applications

Example

19/29

float x = values[0];float y = values[1];float z = values[2];

float g = GRAVERTIY_EARTH;

float acc = (x*x + y*y + z*z) / (g*g);

Compute accelerationInput: accEvent from accelerometer

float[] values = accEevent.values;Tainted Data

accEvent

values (Rule 8)

Field access

Page 45: Finding sensor related energy black holes in smartphone applications

Example

19/29

float x = values[0];float y = values[1];float z = values[2];

float g = GRAVERTIY_EARTH;

float acc = (x*x + y*y + z*z) / (g*g);

Compute accelerationInput: accEvent from accelerometer

float[] values = accEevent.values;Tainted Data

accEvent

values (Rule 8)

x (Rule 3)

y (Rule 3)

z (Rule 3)

Array elementaccess

Page 46: Finding sensor related energy black holes in smartphone applications

Example

19/29

float x = values[0];float y = values[1];float z = values[2];

float g = GRAVERTIY_EARTH;

float acc = (x*x + y*y + z*z) / (g*g);

Compute accelerationInput: accEvent from accelerometer

float[] values = accEevent.values;Tainted Data

accEvent

values (Rule 8)

x (Rule 3)

y (Rule 3)

z (Rule 3)

acc (Rule 6)

Arithmetic computation

Page 47: Finding sensor related energy black holes in smartphone applications

Sensory data usage measurement

20/29

Usage Accumulationusage(s, d) = weight(i, s)× rel(i)i∈Instr(s,d )

Page 48: Finding sensor related energy black holes in smartphone applications

Sensory data usage measurement

20/29

(Execution 1)

(Execution 2)

State1 State2

State3

Osmdroid issue 53:

Usage Accumulationusage(s, d) = weight(i, s)× rel(i)i∈Instr(s,d )

Page 49: Finding sensor related energy black holes in smartphone applications

Sensory data usage measurement

21/29

dataProcess()

broadcast()

updateMap()

Location data dataProcess()

broadcast()

updateMap()

Location data

writeToDB()

State 2(map invisible) State 3

dataProcess()

broadcast()

updateMap()

Location data

State 1

1 2 (Execution 1)

(Execution 2)3

Page 50: Finding sensor related energy black holes in smartphone applications

Sensory data usage measurement

21/29

dataProcess()

broadcast()

updateMap()

Location data dataProcess()

broadcast()

updateMap()

Location data

writeToDB()

State 2(map invisible) State 3

dataProcess()

broadcast()

updateMap()

Location data

State 1

+n

+n

+n

+n

+n

+0

+n

+n

+n

+n

1 2 (Execution 1)

(Execution 2)3

Page 51: Finding sensor related energy black holes in smartphone applications

Usage Comparison

22/29

1 2 (Execution 1)

(Execution 2)3

Index Usage Utilization coefficient

State 1 3n 0.75

State 2 2n 0.5

State 3 4n 1

utilization _ coefficient(s, d) =usage(s, d)

Maxs '∈S,d '∈D (usage(s ', d '))

Page 52: Finding sensor related energy black holes in smartphone applications

Usage Comparison

22/29

1 2 (Execution 1)

(Execution 2)3

Index Usage Utilization coefficient

State 1 3n 0.75

State 2 2n 0.5

State 3 4n 1

utilization _ coefficient(s, d) =usage(s, d)

Maxs '∈S,d '∈D (usage(s ', d '))

Report• Event sequence• Sensory data usage details

Page 53: Finding sensor related energy black holes in smartphone applications

Usage Comparison

22/29

1 2 (Execution 1)

(Execution 2)3

Index Usage Utilization coefficient

State 1 3n 0.75

State 2 2n 0.5

State 3 4n 1

utilization _ coefficient(s, d) =usage(s, d)

Maxs '∈S,d '∈D (usage(s ', d '))

Report• Event sequence• Sensory data usage details

Sensor listener misusage

Page 54: Finding sensor related energy black holes in smartphone applications

Evaluation

• RQ1 (Effectiveness): Can GreenDroid effectively detect energy problems?

• RQ2 (Efficiency): How much overhead does GreenDroid incur? Is GreenDroid practical enough to handler real-world large subjects?

23/29

Page 55: Finding sensor related energy black holes in smartphone applications

Subjects

24/29

ApplicationBasic Information

Revision No. Lines of code Downloads Availability

Osmdroid 750 18,091 10K—50K Google Play

Zmanim 322 4,893 10K—50K Google Play

Omnidroid 863 12,427 1K—5K Google Play

DroidAR 204 18,106 1K—5K Google Code

Recycle-locator 68 3,241 1K—5K Google Play

GPSLogger 15 659 1K—5K Google Code

Page 56: Finding sensor related energy black holes in smartphone applications

Effectiveness

25/29

Energy Problem Problem type New problem

OsmDroid Issue 53 Sensory data underutilization No

Zmanim Issue 50 Sensory data underutilization No

Zmanim Issue 56 Sensory data underutilization No

DroidAR Issue 27 Sensor listener misusage No

Recycle-Locator Issue 33 Sensor listener misusage No

Omnidroid Issue 179 Sensory data underutilization Yes

GPSLogger Issue 7 Sensory data underutilization Yes

GreenDroid found seven real problems. Five problems arecaused by poor sensory data utilization. Two problems arecaused by sensor listener misusage.

Page 57: Finding sensor related energy black holes in smartphone applications

Energy Problem Problem type New problem

OsmDroid Issue 53 Sensory data underutilization No

Zmanim Issue 50 Sensory data underutilization No

Zmanim Issue 56 Sensory data underutilization No

DroidAR Issue 27 Sensor listener misusage No

Recycle-Locator Issue 33 Sensor listener misusage No

Omnidroid Issue 179 Sensory data underutilization Yes

GPSLogger Issue 7 Sensory data underutilization Yes

Effectiveness

25/29

First five problems were confirmed before our experiments.The Last two were new problems found by GreenDroid

Page 58: Finding sensor related energy black holes in smartphone applications

Effectiveness

25/29

“Completely true, Omnidroid does suck up way more energythan necessary. I'd be happy to accept a patch in this regard”.

(Omnidroid issue 179)

Energy Problem Problem type New problem

OsmDroid Issue 53 Sensory data underutilization No

Zmanim Issue 50 Sensory data underutilization No

Zmanim Issue 56 Sensory data underutilization No

DroidAR Issue 27 Sensor listener misusage No

Recycle-Locator Issue 33 Sensor listener misusage No

Omnidroid Issue 179 Sensory data underutilization Yes

GPSLogger Issue 7 Sensory data underutilization Yes

Page 59: Finding sensor related energy black holes in smartphone applications

Efficiency

26/29

ApplicationAnalysis Overhead

Explored states Time (seconds) Space (MB)

Osmdroid 120,189 151 591

Zmanim 54,270 110 205

Omnidroid (12 KLOC) 52,805 220 342

DroidAR (18 KLOC) 91,170 276 217

Recycle-locator 114,709 43 153

GPSLogger 58,824 35 149

Thousands of states explored in a few minutes. MemoryConsumption well supported by modern PCs even withoutoptimization.

Page 60: Finding sensor related energy black holes in smartphone applications

Efficiency

26/29

ApplicationAnalysis Overhead

Explored states Time (seconds) Space (MB)

Osmdroid (18 KLOC) 120,189 151 591

Zmanim 54,270 110 205

Omnidroid (12 KLOC) 52,805 220 342

DroidAR (18 KLOC) 91,170 276 217

Recycle-locator 114,709 43 153

GPSLogger 58,824 35 149

Large subjects’ analysis overhead suggests that GreenDroid ispractical enough to handle real world Android applications.

Page 61: Finding sensor related energy black holes in smartphone applications

Discussion

• Limitations– Imprecision in AEM model and native lib modeling

– Complex inputs generation (e.g., password)

– Limited subjects in evaluation

• Future work– Validate the effectiveness with more subjects

– Investigate energy problems caused by other reasons (e.g., network)

28/29

Page 62: Finding sensor related energy black holes in smartphone applications

Conclusion

29/29

Page 63: Finding sensor related energy black holes in smartphone applications

Thank you!