ì
Computer Systems and Networks
ECPE 170 – Jeff Shafer – University of the Pacific
Performance Measurement 2 Lab Schedule Activities Assignments - - PowerPoint PPT Presentation
Computer Systems and Networks ECPE 170 Jeff Shafer University of the Pacific Performance Measurement 2 Lab Schedule Activities Assignments Due Today Lab 4 Due by Feb 19 th 5:00am Discussion on Performance
ì
Computer Systems and Networks
ECPE 170 – Jeff Shafer – University of the Pacific
Lab Schedule
Activities
ì
Today
ì
Discussion on Performance Measurement (Lab 5)
ì
Finish Lab 4! ì
Next Week
ì
Lab 5 – Performance Measurement
Assignments Due
ì
Lab 4
ì
Due by Feb 19th 5:00am ì
Lab 5
ì
Due by Feb 26th 5:00am
Spring 2019 Computer Systems and Networks
2
Person of the Day: Bill Joy
ì
Co-founder of Sun Microsystems
ì
Author of vi text editor
ì
Key contributor to original BSD Unix while a Berkeley grad student
ì
First open-source OS with TCP/IP
Spring 2019 Computer Systems and Networks
3
ì
Memory Leaks
Spring 2019 Computer Systems and Networks
4
Problem 1
int main() { int *array; array=(int *)malloc(sizeof(int)*1000); for(i=0;i<1000;i++) array[i] = i; return 0; }
Spring 2019 Computer Systems and Networks
5
P1
Where is the Memory Leak?
Problem 2
int main() { int **array; array=(int **)malloc(sizeof(int *)*1000); for(i=0;i<1000;i++) array[i] = (int *)malloc(sizeof(int)*500); free(array); return 0; }
Spring 2019 Computer Systems and Networks
6
P2
(a) Where is the Memory Leak? (b) How do you fix it?
ì
Performance Measurement
Spring 2019 Computer Systems and Networks
7
Lab 5 Goals
1.
Measure program execution time
2.
Break down program execution time by specific subroutines / lines of code
3.
Monitor program for memory leaks
ì
Not really “performance”, but uses same tool
Spring 2019 Computer Systems and Networks
8
Performance Measurement
ì Why is it important to measure application
performance in detail?
Spring 2019 Computer Systems and Networks
9
Valgrind
Spring 2019 Computer Systems and Networks
10
http://valgrind.org/
Valgrind Features
ì Memcheck module – Memory error detector ì Access 1 beyond the beginning / end of your array? ì Access un-initialized memory? ì Reading/writing memory after calling free()? ì Memory leak? (Lost pointer to a malloc() block) ì Valgrind produces a report that identifies these
errors
Spring 2019 Computer Systems and Networks
11
Valgrind Features
ì Callgrind module – Program profiler ì Callgraph shows you what function called what
ì How much CPU time does each function / code line
consume?
ì Valgrind produces a report that summarizes CPU
usage of your program
Spring 2019 Computer Systems and Networks
12
Valgrind Features
ì Massif module – Heap profiler
ì
Optimize your program to use less memory (by identifying where memory is being used) ì Helgrind module – Threading profiler
ì
Bugs in multi-threaded programs are especially difficult to find! ì … and more modules …
Spring 2019 Computer Systems and Networks
13
Valgrind Common Uses
ì Your program runs and suddenly segfaults
ì
Recall a segfault means a memory address was accessed that doesn’t exist for your program ì How do I find where this error is?
ì
Valgrind can monitor your program and detect accesses outside of static variables and dynamic memory regions
Spring 2019 Computer Systems and Networks
14
Valgrind Common Uses
ì Your program gets slower and slower
the longer it runs
ì
Memory leak? (Slowing running out of heap memory because you malloc() without ever calling free()) ì How do I find where this error is?
ì
Valgrind can monitor your program. It can’t tell you where you should free it, but it will tell you where you originally called malloc(), or where the pointer was lost
Spring 2019 Computer Systems and Networks
15
Valgrind Behind-the-Scenes
ì Just-in time compiler
ì
Your program is re-compiled onto a virtual (simulated) processor
ì
Another example of a virtual machine! ì Benefit – Valgrind can observe your program
running at the machine instruction level
ì Drawback – Slow! (5x slower than normal)
ì
But it’s still better than fixing bugs without a tool…
Spring 2019 Computer Systems and Networks
16
ì
Profiling Basics
Spring 2019 Computer Systems and Networks
17
Profiling Basics
ì The next labs (5-7) ask you to measure application
performance by conducting experiments
ì
Execution time
ì
Processor usage
ì
Memory usage ì Which of these system configuration do you think
would be best in terms of producing the cleanest, most accurate, most reproducible results?
Spring 2019 Computer Systems and Networks
18
Spring 2019 Computer Systems and Networks
19
Spring 2019 Computer Systems and Networks
20
Spring 2019 Computer Systems and Networks
21
Profiling Basics
ì The best approach (directly booting Linux) may not
be convenient to achieve for this class
ì But you can *definitely* avoid the worst
configuration!
ì
Keep your system simple when benchmarking
Spring 2019 Computer Systems and Networks
22