Profiling with GNU GProf

Slides:



Advertisements
Similar presentations
compilers and interpreters
Advertisements

Computer Science 2212a/b - UWO1 Structural Testing Motivation The gcov Tool An example using gcov How does gcov do it gcov subtleties Further structural.
GNU gprof Profiler Yu Kai Hong Department of Mathematics National Taiwan University July 19, 2008 GNU gprof 1/22.
Programming Types of Testing.
Performance Improvement
CSc 352 Performance Tuning Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Performance Measuring on Blue Horizon and Sun HPC Systems: Timing, Profiling, and Reading Assembly Language NPACI Parallel Computing Institute 2000 Sean.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Spring 2014 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
Lecture 8. Profiling - for Performance Analysis - Prof. Taeweon Suh Computer Science Education Korea University COM503 Parallel Computer Architecture &
This project has been funded with support from the European Commission. Mathematical literacy and basic competences in science and technology Module Information.
Vim Editor and Unix Command gcc compiler Computer Networks.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Slides Prepared from the CI-Tutor Courses at NCSA By S. Masoud Sadjadi School of Computing and Information Sciences Florida.
1 Components of the Virtual Memory System  Arrows indicate what happens on a lw virtual address data physical address TLB page table memory cache disk.
Application Profiling Using gprof. What is profiling? Allows you to learn:  where your program is spending its time  what functions called what other.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Timing Programs and Performance Analysis Tools for Analysing and Optimising advanced Simulations.
Adv. UNIX: Profile/151 Advanced UNIX v Objectives –introduce profiling based on execution times and line counts Special Topics in Comp.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Announcements  Homework 4 out today  Dec 7 th is the last day you can turn in Lab 4 and HW4, so plan ahead.
Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes.
Performance Improvement
Profiling Tools Introduction to Computer System, Fall (PPI, FDU) Vtune & GProfile.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
1 Performance Issues CIS*2450 Advanced Programming Concepts.
Copyright 2014 – Noah Mendelsohn Performance Analysis Tools Noah Mendelsohn Tufts University Web:
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
10/07/2011ecs40 fall Software Development & Object- Oriented Programming ecs40 Fall 2012: Software Development & Object- Oriented Programming #05:
© Dr. A. Williams, Fall Present Software Quality Assurance – Clover Lab 1 Tutorial / lab 2: Code instrumentation Goals of this session: 1.Create.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
July 10, 2016ISA's, Compilers, and Assembly1 CS232 roadmap In the first 3 quarters of the class, we have covered 1.Understanding the relationship between.
Stavroula Balopoulou , Angelo Lykiardopoulos, Sissy Iona HCMR-HNODC
KYC - Know your compiler Introduction to GCC
DEBUG.
Two notions of performance
Precept 10 : Building and Performance
First Day in Lab Making a C++ program
Lecture 5z Linux Tools – Call graphs Virtual Machines
CS1010: Intro Workshop.
Performance Analysis Tools
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Chapter 5- Assembling , Linking, and Executing Programs
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
CSCI-235 Micro-Computer Applications
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Profiling for Performance in C++
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
and Executing Programs
Compiler Construction
Chapter 11 Introduction to Programming in C
Topics Introduction to File Input and Output
GNU gcov (1/4) [from Wikipedia]
Chapter 11 Introduction to Programming in C
Iteration: Beyond the Basic PERFORM
Chapter One: An Introduction to Programming and Visual Basic
Parallel Computing Explained Timing and Profiling
Introduction to OProfile
GNU gcov gcov is a test coverage program running with gcc.
GNU gcov (1/4) [from Wikipedia]
Chapter 1 Introduction.
Topics Introduction to File Input and Output
Debugging.
Performance Tuning.
Makefiles, GDB, Valgrind
CSc 352 Performance Tuning
Presentation transcript:

Profiling with GNU GProf Aleksandar Jovic Institute of Physics Belgrade, Serbia Scientific Computing Laboratory ajovic@ipb.ac.rs The HP-SEE initiative is co-funded by the European Commission under the FP7 Research Infrastructures contract no. 261499

Profiling-Introduction Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing This information can show you which pieces of your program are slower than you expected, and might be candidates for rewriting to make your program execute faster It can also tell you which functions are being called more or less often than you expected This may help you spot bugs that had otherwise been unnoticed History: prof (1979.) gprof (1982.) GNU gprof was written by Jay Fenlason <Event> – <Place> <Date (DD-Month-YYYY)> 2

<Event> – <Place> <Date (DD-Month-YYYY)> 3 Gprof-Introduction The gprof utility produces an execution profile of C, Pascal, or Fortran77 programs. Detail time statistics for each subroutine Create relative graph for all subroutines Analysis the program bottleneck  It's a very powerful program The simplest one <Event> – <Place> <Date (DD-Month-YYYY)> 3

<Event> – <Place> <Date (DD-Month-YYYY)> 4 Gprof-Introduction Profiling steps: Compiling a program for profiling Executing the program (You must execute your program to generate a profile data file) You must run gprof to analyze the profile data 2 forms of output are available from the analysis: flat profile call graph <Event> – <Place> <Date (DD-Month-YYYY)> 4

Compiling a program for profiling I assume that you know how to write, compile, and execute programs. Recompile the original source code with flag –pg This option –pg affects both compiling and linking $ gcc –pg sourcecode.c -o executablefile [ajovic@ui moj_C]$ gcc –pg savrsen.c –o savrsen If you compile only some of the modules of the program with `-pg', you can still profile the program, but you won't get complete information about the modules that were compiled without `-pg'. The only information you get for the functions in those modules is the total time spent in them; there is no record of how many times they were called, or from where. <Event> – <Place> <Date (DD-Month-YYYY)> 5

<Event> – <Place> <Date (DD-Month-YYYY)> 6 Executing the program Your program will write the profile data into a file called `gmon.out' just before exiting. If there is already a file called `gmon.out', its contents are overwritten Run the program: [ajovic@ui moj_C]$ ./savrsen [ajovic@ui moj_C]$ ls You should now see a file in the same directory called gmon.out.  This file is used by gprof to build your profile report Run gprof: $ gprof List_of_options ExecuteFile gmon.out > OutputFile List_of_options can be omitted ExecuteFile can be omitted when the file name is a.out Run gprof using the following syntax gprof savrsen gmon.out > output.txt <Event> – <Place> <Date (DD-Month-YYYY)> 6

<Event> – <Place> <Date (DD-Month-YYYY)> 7 List of options List of options: -b omit the table or data illustration on output file -e(E) subroutine_name exclude the subroutine subroutine_name from the table (and exclude its elapsed time). The -e  option tells gprof to not print information about the subroutine_name (and its children) in the call graph -f(F) subroutine_name: only display the subroutine SRName on the table (and its elapsed time). The -f  option causes gprof to limit the call graph to the function function_name and its children -Z only display all subroutines table which are unused on the program -v causes gprof to print the current version number, and then exit <Event> – <Place> <Date (DD-Month-YYYY)> 7

<Event> – <Place> <Date (DD-Month-YYYY)> 8 Flat profile Flat profile - The flat profile shows the total amount of time your program spent executing each function [ajovic@ui moj_C]$ gcc -pg eratosten.c -o eratosten [ajovic@ui moj_C]$ gprof -b eratosten gmon.out > erat.txt [ajovic@ui moj_C]$ vim erat.txt Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls ms/call ms/call name 56.1 0.80 0.80 1 796.79 796.79 make 30.54 1.23 0.43 100000001 0.00 0.00 isprime 9.94 1.37 0.14 3.35 main % time: the percent of self seconds from total program elapsed time cumulative seconds : the seconds cumulate from self seconds self seconds : total elapsed time called by its parents, not including its children’s elapsed time. Equal to (self s/call)*(calls) calls : total number for each subroutine called by its parents <Event> – <Place> <Date (DD-Month-YYYY)> 8

<Event> – <Place> <Date (DD-Month-YYYY)> 9 Flat profile self s/call : elapsed time for each time called by its parents, not including its children’s elapsed time total s/call : total elapsed time called by its parents, including its children’s elapsed time name : subroutine name <Event> – <Place> <Date (DD-Month-YYYY)> 9

<Event> – <Place> <Date (DD-Month-YYYY)> 10 Call graph Call graph - The call graph shows how much time was spent in each function and its children $ ifort -pg primer_gprof.f -o f_primer $ gprof –b f_primer gmon.out > output.txt $ vim output.txt Primary line : Index % time self children called name Index - Each function has an index number, which appears at the beginning of its primary line % time – This is the percentage of the total time that was spent in this function, including time spent in subroutines called from this function self - This is the total amount of time spent in this function children - This is the total amount of time spent in the subroutine calls made by this function called - This is the number of times the function was called name - This is the name of the current function <Event> – <Place> <Date (DD-Month-YYYY)> 10

<Event> – <Place> <Date (DD-Month-YYYY)> 11 Example1 granularity: each sample hit covers 2 byte(s) no time propagated index % time self children called name 0.00 0.00 1/2 fizika_ [3] 0.00 0.00 1/2 matematika_ [4] [1] 0.0 0.00 0.00 2 hemija_ [1] ----------------------------------------------- 0.00 0.00 1/1 main [223] [2] 0.0 0.00 0.00 1 MAIN__ [2] 0.00 0.00 1/1 matematika_ [4] 0.00 0.00 1/1 fizika_ [3] 0.00 0.00 1/1 MAIN__ [2] [3] 0.0 0.00 0.00 1 fizika_ [3] 0.00 0.00 1/2 hemija_ [1] [4] 0.0 0.00 0.00 1 matematika_ [4] <Event> – <Place> <Date (DD-Month-YYYY)> 11

<Event> – <Place> <Date (DD-Month-YYYY)> 12 Example2 [ajovic@ui moj_C]$ gcc -pg eratosten.c -o eratosten [ajovic@ui moj_C]$ gprof -b eratosten gmon.out > erat.txt [ajovic@ui moj_C]$ vim erat.txt granularity: each sample hit covers 2 byte(s) for 0.73% of 1.37 seconds index % time self children called name <spontaneous> [1] 100.0 0.14 1.23 main [1] 0.80 0.00 1/1 make [2] 0.43 0.00 100000001/100000001 isprime [3] ------------------------------------------------------------------------------------------------ 0.80 0.00 1/1 main [1] [2] 58.1 0.80 0.00 1 make [2] 0.43 0.00 100000001/100000001 main [1] [3] 31.6 0.43 0.00 100000001 isprime [3] <Event> – <Place> <Date (DD-Month-YYYY)> 12

<Event> – <Place> <Date (DD-Month-YYYY)> 13 References http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html <Event> – <Place> <Date (DD-Month-YYYY)> 13