SlideShare a Scribd company logo
1 of 48
Download to read offline
Tools and Techniques for Understanding Threading Behavior in Android* 
Dr. Ramesh Peri 
Principal Engineer & Architect of Android tools 
Intel Corporation, 
Austin, TX 78746 
Email: ramesh.v.peri@intel.com
2 
Agenda 
 Goals 
 Tools Roundup 
 Intel Vtune, Linux Perf, Nvidia System Profiler, Google Systrace, ARM DS-5 
 Threading Examples 
 Simple Example 
 Simple Threading 
 Communicating Threads 
 Simultaneously executing threads 
 Lazy Thread 
 False Sharing
3 
Goals 
 Learn about performance analysis tools in Android 
 Develop simple micro-benchmarks and run them under the control of a performance 
analysis tool 
 Interpret and validate the data 
 Understanding of Threading models used in Android 
 Understand core to thread mapping 
 Impact on responsiveness 
 Impact on power and performance
4 
Intel® VTune
5 
Nvidia® System Profiler
6 
Google Systrace
7 
ARM DS-5
8 
Linux Perf
Tools 
9 
VTune Linux Perf Nvidia System Profiler 
Google 
Systrace 
OTB Experience hard hard hard good 
TimelIne Yes No Yes Yes 
Java Profiling Yes No No No 
Hotspot views Yes Yes Yes No 
h/w events Yes Limited Limited No 
OS Events Limited Yes Limited Yes 
Filtering Yes No No No 
Call stack Yes Yes No No
Devices 
10 
Column Heading Nexus 7 New Dell venue 8 Nvidia Shield 
Processor ARM Snapdragon Intel Merrifield Nvidia A15 
Frequency 
Memory
Simple Example 
11
A Simple Example 
12 
public void showValue(View v) { 
int i, j, sum=0; 
for (i=0;i<10000;i++) 
for (j=0;j<10000;j++) 
sum+=i; 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText(String.valueOf(sum)); 
} 
public void clearValue(View v) { 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText(""); 
} 
textview2
Performance Profile 
13 
All in one thread
Which core is being used ? 
14 
Mostly using core 1
Which key press used core 0 ? 
Second press used 
Core 0 
15
Simple Threading 
16
Simple Threading 
17 
public void showValue(View v) { 
new LongOperation().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 
} 
public void clearValue(View v) { 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText("CLEARED"); 
}
Thread Code 
18 
private class LongOperation extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
int sum=0; 
for (int i=0;i<10000;i++) 
for (int j=0;j<10000;j++) 
sum+=i; 
return (String.valueOf(sum)); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(result); 
} 
}
The Threading Picture for 10 key presses 
5 threads created 
and each one 
handling 2 key 
presses 
19
The Threading Picture for 15 key presses 
20
21 
Observation 
 There are 5 worker threads 
 Each one gets a piece of work in a roundrobin fashion 
 Why did the thread really terminate right after the last key press ? 
 No – there were no samples from the thread
Communicating Threads 
22
Communication Pattern 
Thread1 
Thread2 
bqt2 
bqt1 
busy 
time sleep
Communicating Threads 
24 
public void showValue(View v) { 
bqt1 = new LinkedBlockingQueue<String>(2); 
bqt2 = new LinkedBlockingQueue<String>(2); 
new Thread1().executeOnExecutor(AsyncTask. 
THREAD_POOL_EXECUTOR); 
new Thread2().executeOnExecutor(AsyncTask. 
THREAD_POOL_EXECUTOR); 
} 
public void clearValue(View v) { 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText(""); 
} 
Output from thread2 
Output from thread1
Thread Code 
25 
private class Thread1 extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
int sum=0; 
for (int times=0;times<5;times++) 
{ 
for (int i=0;i<10000;i++) 
for (int j=0;j<10000;j++) 
sum+=i; 
try 
{ bqt2.put("1"); } 
catch (InterruptedException intEx) 
{ System.out.println("Interrupted! "); } 
try 
{ bqt1.take(); } 
catch (InterruptedException intEx) 
{ System.out.println("Interrupted!"); } 
} 
return (String.valueOf(sum)); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(txt.getText() + " t1:" + result); 
} 
private class Thread2 extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
int sum=0; 
for (int times=0;times<5;times++) 
{ 
try 
{ bqt2.take(); } 
catch (InterruptedException intEx) 
{ System.out.println("Interrupted! "); } 
for (int i=0;i<10000;i++) 
for (int j=0;j<10000;j++) 
sum+=i; 
try 
{ bqt1.put("1"); } 
catch (InterruptedException intEx) 
{ System.out.println("Interrupted! "); } 
} 
return (String.valueOf(sum)); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(txt.getText() + " t2:" + result); 
}
The Threading Picture for 5 key presses 
26 
Alternating 
Thread1 & 
Thread2
Zoomed in view 
27
Simultaneously Executing Threads 
28
Communication Pattern 
Thread1 
Thread2 
busy 
time sleep 
Main thread
Communicating Threads 
30 
public void showValue(View v) { 
new MasterThread().execute(); 
} 
public void clearValue(View v) { 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText(""); 
} 
5tuples - <Output from thread1, output from thread2>
Thread Code 
31 
private class MasterThread extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
String result=""; 
for (int i=0;i<5;i++) 
{ 
AsyncTask<String,Void,String> t1 = new 
SlaveThread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 
AsyncTask<String,Void,String> t2 = new 
SlaveThread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 
String res1 = null; 
try { res1 = t1.get(); } 
catch (InterruptedException e) { e.printStackTrace(); } 
catch (ExecutionException e) { e.printStackTrace(); } 
String res2 = null; 
try { res2 = t2.get(); } 
catch (InterruptedException e) { e.printStackTrace(); } 
catch (ExecutionException e) { e.printStackTrace(); } 
result = result + ":" + res1 + "," + res2; 
} 
return (result); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(result); 
} 
}
The Threading Picture for two key presses 
32 
Thread1 & 
Thread2 executing 
At same time
Lazy Threads 
33
Communication Pattern 
Thread1 
busy 
sleep 
time 
3s 3s 3s 3s
Lazy Thread 
35 
public void showValue(View v) { 
new Thread().execute(“”); 
} 
public void clearValue(View v) { 
TextView tv = (TextView)findViewById(R.id.textView2); 
tv.setText(""); 
}
Thread Code 
36 
private class Thread extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
int sum=0; 
for (int i=0;i<5;i++) 
{ 
try { 
synchronized (this) { 
wait(3000); // wait for 3sec 
} 
} catch (InterruptedException e) { 
e.printStackTrace(); 
} 
for (int j=0;j<10000;j++) 
for (int k=0;k<10000;k++) 
sum+=i; 
} 
return (String.valueOf(sum)); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(result); 
} 
}
Performance view 
37 
Thread slept 
For 3 sec
False Sharing 
38
What is False Sharing ? 
struct { 
int x; 
int y; 
} v; 
/* sum & inc run in parallel */ 
int sum(void) 
{ 
int i, s = 0; 
int i; 
for (i = 0; i < 1000000; ++i) 
s+=v.x; 
return s; 
} 
void inc(void) 
{ 
int i; 
for (i = 0; i < 10000000; ++i) 
v.y++;; 
} 
v.x v.y 
memory 
cache cache 
v.x v.y 
sum inc
False Sharing App 
40 
public void showValue1(View v) { 
for (int i=0;i<256;i++) 
a[i]=0; 
for (int i=0;i<4;i++) 
new Thread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, String.valueOf(i)); 
} 
// No False Sharing 
public void showValue2(View v) { 
for (int i=0;i<256;i++) 
a[i]=0; 
for (int i=0;i<4;i++) 
new Thread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 
String.valueOf(i*64)); 
}
Thread Body 
41 
private class Thread extends AsyncTask<String, Void, String> { 
@Override 
protected String doInBackground(String... params) { 
int tid=Integer.parseInt(params[0]); 
int lim = tid+32; 
for (int j=0;j<1000;j++) 
for (int k=0;k<10000;k++) 
for (int i=tid;i<lim;i+=4) 
a[i]=a[i]+1; 
return (params[0]); 
} 
@Override 
protected void onPostExecute(String result) { 
TextView txt = (TextView) findViewById(R.id.textView2); 
txt.setText(txt.getText() + " " + result + ":" + a[Integer.parseInt(result)]); 
} 
}
Memory Access Pattern of Threads 
cacheline 1 2 3 4 1 2 3 4 
1 1 
2 2 
3 3 
4 4 
cacheline 
cacheline 
cacheline 
cacheline 
False Sharing 
No False Sharing 
In both cases same amount of work is done
Sample App 
43 
Click falseS Click NfalseS
Profile of the run 
False Sharing 
No False sharing
Detailed view 
45 
False Sharing No False Sharing 
Same number of instructions executed
Conclusion 
46
INFORMATION IN THIS DOCUMENT IS PROVIDED “AS IS”. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY 
INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS 
ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO THIS INFORMATION INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS 
FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY 
RIGHT. 
Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as 
SYSmark and MobileMark, are measured using specific computer systems, components, software, operations and functions. Any change to any of those 
factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated 
purchases, including the performance of that product when combined with other products. 
Copyright © 2013, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and other countries. 
Optimization Notice 
Intel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel 
microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the 
availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent 
optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are 
reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific 
instruction sets covered by this notice. 
Notice revision #20110804 
Legal Disclaimer & Optimization Notice 
47 Intel Confidential 
11/26/2014 
Copyright© 2013, Intel Corporation. All rights reserved. 
*Other brands and names are the property of their respective owners.
Tools and Techniques for Understanding Threading Behavior in Android*

More Related Content

What's hot

Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphismUsama Malik
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diplomamustkeem khan
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKGuardSquare
 
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...Istanbul Tech Talks
 
Eric Lafortune - ProGuard and DexGuard for optimization and protection
Eric Lafortune - ProGuard and DexGuard for optimization and protectionEric Lafortune - ProGuard and DexGuard for optimization and protection
Eric Lafortune - ProGuard and DexGuard for optimization and protectionGuardSquare
 
Mutate and Test your Tests
Mutate and Test your TestsMutate and Test your Tests
Mutate and Test your TestsSTAMP Project
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Ontico
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUGSTAMP Project
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handlingIntro C# Book
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming languageSQLI
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguageSamir Chekkal
 

What's hot (20)

Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphism
 
Thread
ThreadThread
Thread
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
Base de-datos
Base de-datosBase de-datos
Base de-datos
 
分散式系統
分散式系統分散式系統
分散式系統
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
ITT 2014 - Eric Lafortune - ProGuard, Optimizer and Obfuscator in the Android...
 
Java File
Java FileJava File
Java File
 
Eric Lafortune - ProGuard and DexGuard for optimization and protection
Eric Lafortune - ProGuard and DexGuard for optimization and protectionEric Lafortune - ProGuard and DexGuard for optimization and protection
Eric Lafortune - ProGuard and DexGuard for optimization and protection
 
Programs of java
Programs of javaPrograms of java
Programs of java
 
Mutate and Test your Tests
Mutate and Test your TestsMutate and Test your Tests
Mutate and Test your Tests
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUG
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming language
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguage
 

Similar to Tools and Techniques for Understanding Threading Behavior in Android*

TDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidTDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidCodemotion
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonbeITconference
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 Mahmoud Samir Fayed
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And EnumsBhushan Mulmule
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210Mahmoud Samir Fayed
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindAndreas Czakaj
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effectsSergey Kuksenko
 
Matteo Vaccari - TDD per Android | Codemotion Milan 2015
Matteo Vaccari - TDD per Android | Codemotion Milan 2015Matteo Vaccari - TDD per Android | Codemotion Milan 2015
Matteo Vaccari - TDD per Android | Codemotion Milan 2015Codemotion
 
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202Mahmoud Samir Fayed
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdfinfo30292
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 

Similar to Tools and Techniques for Understanding Threading Behavior in Android* (20)

#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
TDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidTDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with Android
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Testability for Developers
Testability for DevelopersTestability for Developers
Testability for Developers
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
 
Ac2
Ac2Ac2
Ac2
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mind
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
Matteo Vaccari - TDD per Android | Codemotion Milan 2015
Matteo Vaccari - TDD per Android | Codemotion Milan 2015Matteo Vaccari - TDD per Android | Codemotion Milan 2015
Matteo Vaccari - TDD per Android | Codemotion Milan 2015
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 

More from Intel® Software

AI for All: Biology is eating the world & AI is eating Biology
AI for All: Biology is eating the world & AI is eating Biology AI for All: Biology is eating the world & AI is eating Biology
AI for All: Biology is eating the world & AI is eating Biology Intel® Software
 
Python Data Science and Machine Learning at Scale with Intel and Anaconda
Python Data Science and Machine Learning at Scale with Intel and AnacondaPython Data Science and Machine Learning at Scale with Intel and Anaconda
Python Data Science and Machine Learning at Scale with Intel and AnacondaIntel® Software
 
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSci
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSciStreamline End-to-End AI Pipelines with Intel, Databricks, and OmniSci
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSciIntel® Software
 
AI for good: Scaling AI in science, healthcare, and more.
AI for good: Scaling AI in science, healthcare, and more.AI for good: Scaling AI in science, healthcare, and more.
AI for good: Scaling AI in science, healthcare, and more.Intel® Software
 
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...Intel® Software
 
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...Intel® Software
 
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...Intel® Software
 
AWS & Intel Webinar Series - Accelerating AI Research
AWS & Intel Webinar Series - Accelerating AI ResearchAWS & Intel Webinar Series - Accelerating AI Research
AWS & Intel Webinar Series - Accelerating AI ResearchIntel® Software
 
Intel AIDC Houston Summit - Overview Slides
Intel AIDC Houston Summit - Overview SlidesIntel AIDC Houston Summit - Overview Slides
Intel AIDC Houston Summit - Overview SlidesIntel® Software
 
AIDC NY: BODO AI Presentation - 09.19.2019
AIDC NY: BODO AI Presentation - 09.19.2019AIDC NY: BODO AI Presentation - 09.19.2019
AIDC NY: BODO AI Presentation - 09.19.2019Intel® Software
 
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019Intel® Software
 
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...Intel® Software
 
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...Intel® Software
 
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...Intel® Software
 
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...Intel® Software
 
AIDC India - Intel Movidius / Open Vino Slides
AIDC India - Intel Movidius / Open Vino SlidesAIDC India - Intel Movidius / Open Vino Slides
AIDC India - Intel Movidius / Open Vino SlidesIntel® Software
 
AIDC India - AI Vision Slides
AIDC India - AI Vision SlidesAIDC India - AI Vision Slides
AIDC India - AI Vision SlidesIntel® Software
 
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...Intel® Software
 

More from Intel® Software (20)

AI for All: Biology is eating the world & AI is eating Biology
AI for All: Biology is eating the world & AI is eating Biology AI for All: Biology is eating the world & AI is eating Biology
AI for All: Biology is eating the world & AI is eating Biology
 
Python Data Science and Machine Learning at Scale with Intel and Anaconda
Python Data Science and Machine Learning at Scale with Intel and AnacondaPython Data Science and Machine Learning at Scale with Intel and Anaconda
Python Data Science and Machine Learning at Scale with Intel and Anaconda
 
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSci
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSciStreamline End-to-End AI Pipelines with Intel, Databricks, and OmniSci
Streamline End-to-End AI Pipelines with Intel, Databricks, and OmniSci
 
AI for good: Scaling AI in science, healthcare, and more.
AI for good: Scaling AI in science, healthcare, and more.AI for good: Scaling AI in science, healthcare, and more.
AI for good: Scaling AI in science, healthcare, and more.
 
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...
Software AI Accelerators: The Next Frontier | Software for AI Optimization Su...
 
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...
Advanced Techniques to Accelerate Model Tuning | Software for AI Optimization...
 
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...
Reducing Deep Learning Integration Costs and Maximizing Compute Efficiency| S...
 
AWS & Intel Webinar Series - Accelerating AI Research
AWS & Intel Webinar Series - Accelerating AI ResearchAWS & Intel Webinar Series - Accelerating AI Research
AWS & Intel Webinar Series - Accelerating AI Research
 
Intel Developer Program
Intel Developer ProgramIntel Developer Program
Intel Developer Program
 
Intel AIDC Houston Summit - Overview Slides
Intel AIDC Houston Summit - Overview SlidesIntel AIDC Houston Summit - Overview Slides
Intel AIDC Houston Summit - Overview Slides
 
AIDC NY: BODO AI Presentation - 09.19.2019
AIDC NY: BODO AI Presentation - 09.19.2019AIDC NY: BODO AI Presentation - 09.19.2019
AIDC NY: BODO AI Presentation - 09.19.2019
 
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019
AIDC NY: Applications of Intel AI by QuEST Global - 09.19.2019
 
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...
Advanced Single Instruction Multiple Data (SIMD) Programming with Intel® Impl...
 
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
 
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...
Bring Intelligent Motion Using Reinforcement Learning Engines | SIGGRAPH 2019...
 
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
 
AIDC India - AI on IA
AIDC India  - AI on IAAIDC India  - AI on IA
AIDC India - AI on IA
 
AIDC India - Intel Movidius / Open Vino Slides
AIDC India - Intel Movidius / Open Vino SlidesAIDC India - Intel Movidius / Open Vino Slides
AIDC India - Intel Movidius / Open Vino Slides
 
AIDC India - AI Vision Slides
AIDC India - AI Vision SlidesAIDC India - AI Vision Slides
AIDC India - AI Vision Slides
 
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...
Enhance and Accelerate Your AI and Machine Learning Solution | SIGGRAPH 2019 ...
 

Recently uploaded

Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxSasikiranMarri
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapIshara Amarasekera
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsDEEPRAJ PATHAK
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 

Recently uploaded (20)

Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery Roadmap
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software Projects
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 

Tools and Techniques for Understanding Threading Behavior in Android*

  • 1. Tools and Techniques for Understanding Threading Behavior in Android* Dr. Ramesh Peri Principal Engineer & Architect of Android tools Intel Corporation, Austin, TX 78746 Email: ramesh.v.peri@intel.com
  • 2. 2 Agenda  Goals  Tools Roundup  Intel Vtune, Linux Perf, Nvidia System Profiler, Google Systrace, ARM DS-5  Threading Examples  Simple Example  Simple Threading  Communicating Threads  Simultaneously executing threads  Lazy Thread  False Sharing
  • 3. 3 Goals  Learn about performance analysis tools in Android  Develop simple micro-benchmarks and run them under the control of a performance analysis tool  Interpret and validate the data  Understanding of Threading models used in Android  Understand core to thread mapping  Impact on responsiveness  Impact on power and performance
  • 5. 5 Nvidia® System Profiler
  • 9. Tools 9 VTune Linux Perf Nvidia System Profiler Google Systrace OTB Experience hard hard hard good TimelIne Yes No Yes Yes Java Profiling Yes No No No Hotspot views Yes Yes Yes No h/w events Yes Limited Limited No OS Events Limited Yes Limited Yes Filtering Yes No No No Call stack Yes Yes No No
  • 10. Devices 10 Column Heading Nexus 7 New Dell venue 8 Nvidia Shield Processor ARM Snapdragon Intel Merrifield Nvidia A15 Frequency Memory
  • 12. A Simple Example 12 public void showValue(View v) { int i, j, sum=0; for (i=0;i<10000;i++) for (j=0;j<10000;j++) sum+=i; TextView tv = (TextView)findViewById(R.id.textView2); tv.setText(String.valueOf(sum)); } public void clearValue(View v) { TextView tv = (TextView)findViewById(R.id.textView2); tv.setText(""); } textview2
  • 13. Performance Profile 13 All in one thread
  • 14. Which core is being used ? 14 Mostly using core 1
  • 15. Which key press used core 0 ? Second press used Core 0 15
  • 17. Simple Threading 17 public void showValue(View v) { new LongOperation().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void clearValue(View v) { TextView tv = (TextView)findViewById(R.id.textView2); tv.setText("CLEARED"); }
  • 18. Thread Code 18 private class LongOperation extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { int sum=0; for (int i=0;i<10000;i++) for (int j=0;j<10000;j++) sum+=i; return (String.valueOf(sum)); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(result); } }
  • 19. The Threading Picture for 10 key presses 5 threads created and each one handling 2 key presses 19
  • 20. The Threading Picture for 15 key presses 20
  • 21. 21 Observation  There are 5 worker threads  Each one gets a piece of work in a roundrobin fashion  Why did the thread really terminate right after the last key press ?  No – there were no samples from the thread
  • 23. Communication Pattern Thread1 Thread2 bqt2 bqt1 busy time sleep
  • 24. Communicating Threads 24 public void showValue(View v) { bqt1 = new LinkedBlockingQueue<String>(2); bqt2 = new LinkedBlockingQueue<String>(2); new Thread1().executeOnExecutor(AsyncTask. THREAD_POOL_EXECUTOR); new Thread2().executeOnExecutor(AsyncTask. THREAD_POOL_EXECUTOR); } public void clearValue(View v) { TextView tv = (TextView)findViewById(R.id.textView2); tv.setText(""); } Output from thread2 Output from thread1
  • 25. Thread Code 25 private class Thread1 extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { int sum=0; for (int times=0;times<5;times++) { for (int i=0;i<10000;i++) for (int j=0;j<10000;j++) sum+=i; try { bqt2.put("1"); } catch (InterruptedException intEx) { System.out.println("Interrupted! "); } try { bqt1.take(); } catch (InterruptedException intEx) { System.out.println("Interrupted!"); } } return (String.valueOf(sum)); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(txt.getText() + " t1:" + result); } private class Thread2 extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { int sum=0; for (int times=0;times<5;times++) { try { bqt2.take(); } catch (InterruptedException intEx) { System.out.println("Interrupted! "); } for (int i=0;i<10000;i++) for (int j=0;j<10000;j++) sum+=i; try { bqt1.put("1"); } catch (InterruptedException intEx) { System.out.println("Interrupted! "); } } return (String.valueOf(sum)); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(txt.getText() + " t2:" + result); }
  • 26. The Threading Picture for 5 key presses 26 Alternating Thread1 & Thread2
  • 29. Communication Pattern Thread1 Thread2 busy time sleep Main thread
  • 30. Communicating Threads 30 public void showValue(View v) { new MasterThread().execute(); } public void clearValue(View v) { TextView tv = (TextView)findViewById(R.id.textView2); tv.setText(""); } 5tuples - <Output from thread1, output from thread2>
  • 31. Thread Code 31 private class MasterThread extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { String result=""; for (int i=0;i<5;i++) { AsyncTask<String,Void,String> t1 = new SlaveThread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); AsyncTask<String,Void,String> t2 = new SlaveThread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); String res1 = null; try { res1 = t1.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } String res2 = null; try { res2 = t2.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } result = result + ":" + res1 + "," + res2; } return (result); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(result); } }
  • 32. The Threading Picture for two key presses 32 Thread1 & Thread2 executing At same time
  • 34. Communication Pattern Thread1 busy sleep time 3s 3s 3s 3s
  • 35. Lazy Thread 35 public void showValue(View v) { new Thread().execute(“”); } public void clearValue(View v) { TextView tv = (TextView)findViewById(R.id.textView2); tv.setText(""); }
  • 36. Thread Code 36 private class Thread extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { int sum=0; for (int i=0;i<5;i++) { try { synchronized (this) { wait(3000); // wait for 3sec } } catch (InterruptedException e) { e.printStackTrace(); } for (int j=0;j<10000;j++) for (int k=0;k<10000;k++) sum+=i; } return (String.valueOf(sum)); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(result); } }
  • 37. Performance view 37 Thread slept For 3 sec
  • 39. What is False Sharing ? struct { int x; int y; } v; /* sum & inc run in parallel */ int sum(void) { int i, s = 0; int i; for (i = 0; i < 1000000; ++i) s+=v.x; return s; } void inc(void) { int i; for (i = 0; i < 10000000; ++i) v.y++;; } v.x v.y memory cache cache v.x v.y sum inc
  • 40. False Sharing App 40 public void showValue1(View v) { for (int i=0;i<256;i++) a[i]=0; for (int i=0;i<4;i++) new Thread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, String.valueOf(i)); } // No False Sharing public void showValue2(View v) { for (int i=0;i<256;i++) a[i]=0; for (int i=0;i<4;i++) new Thread().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, String.valueOf(i*64)); }
  • 41. Thread Body 41 private class Thread extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { int tid=Integer.parseInt(params[0]); int lim = tid+32; for (int j=0;j<1000;j++) for (int k=0;k<10000;k++) for (int i=tid;i<lim;i+=4) a[i]=a[i]+1; return (params[0]); } @Override protected void onPostExecute(String result) { TextView txt = (TextView) findViewById(R.id.textView2); txt.setText(txt.getText() + " " + result + ":" + a[Integer.parseInt(result)]); } }
  • 42. Memory Access Pattern of Threads cacheline 1 2 3 4 1 2 3 4 1 1 2 2 3 3 4 4 cacheline cacheline cacheline cacheline False Sharing No False Sharing In both cases same amount of work is done
  • 43. Sample App 43 Click falseS Click NfalseS
  • 44. Profile of the run False Sharing No False sharing
  • 45. Detailed view 45 False Sharing No False Sharing Same number of instructions executed
  • 47. INFORMATION IN THIS DOCUMENT IS PROVIDED “AS IS”. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO THIS INFORMATION INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products. Copyright © 2013, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and other countries. Optimization Notice Intel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice. Notice revision #20110804 Legal Disclaimer & Optimization Notice 47 Intel Confidential 11/26/2014 Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.