How To Install Gprof On Ubuntu Linux

GNU Binutils The GNU Binutils are a collection of binary tools. The main ones are:.

  1. Ubuntu Linux On Windows

ld - the GNU linker. as - the GNU assembler. But they also include:. addr2line - Converts addresses into filenames and line numbers.

ar - A utility for creating, modifying and extracting from archives. cfilt - Filter to demangle encoded C symbols. dlltool - Creates files for building and using DLLs. gold - A new, faster, ELF only linker, still in beta test. gprof - Displays profiling information.

GPROF Tutorial – How to use Linux GNU GCC Profiling Tool. GPROF does not do a good job of getting inclusive time for functions. Ubuntu Tutorials. Tutorials How to install and use profiling tool Gprof on Linux. How to install and use profiling tool Gprof on Linux. How to Install OpenProject on Ubuntu 16.04. How to Profile a C program in Linux using GNU gprof. Run the following command to download and install gprof on Debian. The Complete Beginner's Guide to Ubuntu.

nlmconv - Converts object code into an NLM. nm - Lists symbols from object files.

objcopy - Copies and translates object files. objdump - Displays information from object files. ranlib - Generates an index to the contents of an archive. readelf - Displays information from any ELF format object file. size - Lists the section sizes of an object or archive file. strings - Lists printable strings from files.

strip - Discards symbols. windmc - A Windows compatible message compiler. windres - A compiler for Windows resource files. Most of these programs use BFD, the Binary File Descriptor library, to do low-level manipulation. Many of them also use the opcodes library to assemble and disassemble machine instructions. The binutils have been ported to most major Unix variants as well as Wintel systems, and their main reason for existence is to give the (and ) the facility to compile and link programs.

Obtaining binutils The latest release of GNU binutils is 2.30. The various NEWS files (, and ) have details of what has changed in this release. See the page for information on obtaining releases of GNU binutils and other GNU software. The current release can be downloaded from or, preferably, from a nearby mirror through the generic URL. If you plan to do active work on GNU binutils, you can access the development source tree by anonymous git: git clone git://sourceware.org/git/binutils-gdb.git Alternatively, you can use, or the source snapshots, available as bzipped tar files via anonymous FTP from. Bug reports There is a bug-tracking system.

Mailing lists There are three binutils mailing lists: For reporting bugs. For discussing binutils issues. Binutils-cvs A read-only mailing list containing the notes from checkins to the binutils git repository. (This list has an odd name for historical reasons.) You can use this form to subscribe to the binutils@sourceware.org or binutils-cvs@sourceware.org mailing lists: Mailing list: Your e-mail address: Digest version? To subscribe to the bug-binutils@gnu.org mailing list, see. You may wish to browse the old mail archives of the and mailing lists. These were the discussion lists for binutils until May 1999.

Please do not send mail to them any longer. Documentation The is available.

A to a new target has been contributed.

From the man page of gcc: -pg: Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking. So, lets compile our code with ‘-pg’ option: $ gcc -Wall -pg testgprof.c testgprofnew.c -o testgprof $ Please note: The option ‘-pg’ can be used with the gcc command that compiles (-c option), gcc command that links(-o option on object files) and with gcc command that does the both(as in example above). Step-2: Execute the code In the second step, the binary file produced as a result of step-1 (above) is executed so that profiling information can be generated.

$ ls testgprof testgprof.c testgprofnew.c $./testgprof Inside main Inside func1 Inside newfunc1 Inside func2 $ ls gmon.out testgprof testgprof.c testgprofnew.c $ So we see that when the binary was executed, a new file ‘gmon.out’ is generated in the current working directory. Note that while execution if the program changes the current working directory (using chdir) then gmon.out will be produced in the new current working directory. Also, your program needs to have sufficient permissions for gmon.out to be created in current working directory. Step-3: Run the gprof tool In this step, the gprof tool is run with the executable name and the above generated ‘gmon.out’ as argument. This produces an analysis file which contains all the desired profiling information. $ gprof testgprof gmon.out analysis.txt Note that one can explicitly specify the output file (like in example above) or the information is produced on stdout. $ ls analysis.txt gmon.out testgprof testgprof.c testgprofnew.c So we see that a file named ‘analysis.txt’ was generated.

On a related note, you should also understand. Comprehending the profiling information As produced above, all the profiling information is now present in ‘analysis.txt’. Lets have a look at this text file: Flat profile: Each sample counts as 0.01 seconds.% cumulative self self total time seconds seconds calls s/call s/call name 33.86 15.52 15.52 1 15.52 15.52 func2 33.82 31.02 15.50 1 15.50 15.50 newfunc1 33.29 46.27 15.26 1 15.26 30.75 func1 0.07 46.30 0.03 main% the percentage of the total running time of the time program used by this function. Cumulative a running sum of the number of seconds accounted seconds for by this function and those listed above it. Self the number of seconds accounted for by this seconds function alone.

This is the major sort for this listing. Calls the number of times this function was invoked, if this function is profiled, else blank. Self the average number of milliseconds spent in this ms/call function per call, if this function is profiled, else blank. Total the average number of milliseconds spent in this ms/call function and its descendents per call, if this function is profiled, else blank.

Name the name of the function. This is the minor sort for this listing. The index shows the location of the function in the gprof listing. If the index is in parenthesis it shows where it would appear in the gprof listing if it were to be printed.

I have been using gprof to isolate a performance issue in a large scale business application, but recent attempts to do this have stalled. What we’re seeing is that at the end of the program’s execution, the CPU hangs at 100% utilization in the program, and it either takes hours (or days) to finish, or it never finishes. This never happens when the non-profiling version is run. We typically use SLES 11 for the build base, and either SLES 11 or RHEL 6 for the execution. This always happens on RHEL 6, and with large datasets on SLES 11. Why would the profiling version hang up at the end of program execution like that?

GPROF is not very good for what you need. Try this instead: Plenty of people have used it, and it gets results.

In a large application like yours, 99.9% of the time is spent in a deep call stack terminating in system functions, often doing I/O. GPROF is blind to I/O, so you have no idea how much wall-clock time any functions in your system are actually responsible for.

Ubuntu Linux On Windows

The flat profile is mainly about self time, which in a large program is usually irrelevant because the real problems are mid-stack. GPROF does not do a good job of getting inclusive time for functions, and it gives you no information at the level of lines of code, and if there’s recursion, it gives up. Stuck at “Step-2: Execute the code” Executing the code does not produce the gmon.out. The code that I have, runs indefinitely, until I do Ctrl+C Any ideas why no gmon.out? It should not change directory. — Update1: Well, I ran the proram again, and this time it produced the gmon.out file.

I still stopped it by “Ctrl+C”, so I have no idea why it did not work the other time — Update2: It produced the gmon.out because I ran the program with the –help switch, which means clean exit. So doing a “Ctrl+C” prevents the program from producing the gmon.out. Mike, that’s funny.

The only reason I came here is I was trying to remember why gmon.out was not produced (the article didn’t help – I remembered you have to pass it to the compiler and the linker and I then remembered you cannot send it a signal – it has to exit the execution in the normal way) anyway, I took my own code, profiled it, made some adjustments to my code and dropped the CPU time from 10% to. Hi Cody, You raise a lot of valid points, but let me itemize my objections to gprof. I’ll try to be brief. It’s not just about gprof itself, because many newer profilers have corrected some of these objections. It’s about the mental habits that go along with it, i.e.

That program counter sampling is useful (as opposed to stack sampling). That measuring time of functions is good enough (as opposed to lines of code or even instructions). That the call graph is important (as opposed to the information in stack samples). That recursion is a tricky confusing issue (it only is a problem when trying to construct an annotated call graph). That accuracy of measurement is important (as opposed to accuracy of identifying speedup opportunities). That invocation counting is useful (as opposed to getting inclusive time percent). That samples need not be taken during IO or other blockage (as opposed to sampling on wall-clock time).

That self time matters (as opposed to inclusive time, which includes self time). That samples have to be taken at high frequency (they do not). That you are looking for “the bottleneck” (as opposed to finding all of them – there often are several). I could go into greater detail on any of these if necessary.

Ubuntu

I’m not saying you can’t find problems with these tools. I’m saying, in big software, there are problems they won’t find, and if you really need performance, those are killers.

If you need highest performance, in big software, and you can’t just kill-it-with-iron, these tools are nowhere near aggressive enough. The human eye can recognize similarities between state samples (stack and data) that no summarizing backend of any profiler has any hope of exposing to the user.

For what it’s worth, I made a very amateur 8-minute video of how this works: Cheers. Hi Mike, Well your points are also valid. I think point 10 is exactly what I was getting at: that there are many variables (pardon the pun) and that gprof is only one tool of many that can help but it can still help. Responding to your revised third paragraph: Indeed, it can always get faster and that is the con and pro of higher level languages; on the one hand, you can get more done sooner but on the other hand the executable will be larger and the executable will not be as efficient (or as fast). And hey, even if you were to write everything in assembly (or even machine code), there’s always room for improvement. and even without improvement we as humans always strive for faster, better, etc.

(hence why CPUs of today are so much faster, better, can handle more at one time, and so on, compared to the example from when I last did any major assembly 16 bit days).For instance, the following assembly is not as efficient as it could be (unless CPUs and their instructions set or rather the assemblers have improved so much that they optimise it nowadays): mov ax, 0 versus xor ax, ax So yes, you’re absolutely right – there is no one size fits all and each tool has their own strengths and weaknesses and the ability to recognise those strengths and weaknesses is what really helps. Shortly, I think we’re on the same page more than I thought initially and if I sounded at all arrogant (about life, about the fact there is no such thing as perfection or anything else) then I apologise. The main thing I was getting at is gprof has its uses and to dismiss it entirely is not always helpful (but then so would be dismissing your points – they are valid). But there’s always room for improvement and it really is a matter of perspective (your point about software being able to be much faster for example versus my point about assembly versus HLL and even that assembly instructions can be improved upon). Hopefully that clears up any points from my end (you did indeed clear up your points and I – besides being surprised you responded to me responding from your response from 2012 – appreciate it).

Ubuntu

(As a quick addendum: looking at your points again, I think 2 is another excellent one to consider and something I was getting at too albeit it takes knowing the function and what it calls and where; in fact, that is how I improved my program – I knew the functions that took significant time and called the most, and combined it with the knowledge (from writing the entire fairly large program myself) of what called it and what it called, and was able to more or less optimise it out in most cases. Also, I agree that recursion is not all that difficult.

All in all, your points are very valid and whilst you may dislike gprof I’ve found it useful. On the other hand, I’ll take a look at what you suggested too, because as I noted, there is always room for improvement and I strive to better myself and to always learn more). Thanks for the productive discussion (I didn’t expect it but I’m more glad I responded now than I was initially). Cheers, Cody. Alex, The reason ctrl-c prevents it from producing a gmon.out file is not so much that you hit ctrl-c (by itself) but rather what ctrl-c does: it sends an interrupt signal.

The problem is gprof won’t generate the output unless it calls the exit or returns normally. This means that sending SIGINT or SIGTERM or SIGHUP to your program through the kill utility (and presumably the kill system call or raise library call) will also prevent the generation of the output file. So you need it to exit from program termination (normal termination). My only comment here is that what we did get from the few profiling runs that ran to completion helped us identify exactly what the performance problems were. I was much more concerned about why the profiling build of the app hung at the end, thereby preventing us from collecting the gmon,out files. Yes, I understand the limitations of most program analysis tools. None of them are perfect, but a great many help us mere humans look in the right direction to let our brains figure out what went slow/wrong.

It’s much easier than just staring at million line-long logs that contain gobs of relatively useless information, typically enough that slogging through it is not worth the effort as compared to narrowing the focus with profiling tools so we have a clue what to look for. I take it that no one knows why a -pg program just hangs at the end of execution? Mark, Indeed – that we’re imperfect is something that can be turned into a strength, exactly as you described (the utility is not perfect but it still has its uses just like all things in life and even the concept of ‘good’ comes with ‘bad’ and ‘bad’ comes with ‘good’ – always). Anyway, as for why it would hang, a question and a suggestion on figuring out where its having issues: Question is: how does the program end (Does it directly call exit or does it return from main (assuming that it is C or C)? Okay, make that two questions (three if you count the previous one as two): does the program do this when not compiled with -pg?

Anything else that is different should be kept in mind too (including – just saying and not suggesting this is it – system load). Suggestion: while debugging is truly an art form (which by the way, if you are troubleshooting programs, I highly suggest that if you can, you learn this art as it is incredibly invaluable and that is coming from experience with this ability) even if you can do basic debugging you might be able to figure out at least where the problem lies. Can you compile the program with debugging symbols (compiler option would be ‘-g’, linker does not need it unlike ‘-pg’ typically the compiler will pass certain options to the linker but apparently -pg is not passed to it – at least according to the man page)? If yes, after that, if you find the task’s PID (e.g., via ps or if there’s only one instance of it, pgrep, assuming Linux so /proc filesystem. Far as I recall, pgrep uses that but maybe my tired head is mixed up) and attach to the program during its hang up.

You could do that with (examples) GDB (option -p ) or it might be easier to use something like strace (since it will show you the function running without having to look at ‘bt’ also ‘backtrace’ – same command in GDB). Strace invocation would be like: strace -p (obviously replace with the pid of the task) GDB would be more involved once in the program but GDB you have more control over and that includes line by line execution, break points, watch points and indeed seeing where the execution is at the point you stopped it backtrace or bt (and whether strace needs debugging symbols or not I’m not even sure about 100% but I think not: strace ls seems to work and I highly doubt I have debugging symbols for such utility). One final note is that it is almost always not a system library bug when you see something hanging or crashing in a system library (e.g., exit can and does call other functions), despite what many developers would some times wish (because it means there is a problem in their code and so something they have to fix). Just mentioning that because I see that complaint a lot.

From attaching to the program during execution (where you need to investigate), you then have an idea (well, often) where the problem is in which case you can get closer to solving the problem. I have followups enabled so if you respond maybe I can help more.