Valgrind 2.2.0: Memory Debugging and Profiling
Memory and performance problems plague most of us, but tools are available that can help. One of the best, most powerful and easiest to use is Valgrind. One thing stands out when you use Valgrind--you do not need to recompile, relink or modify your source code. Valgrind is an open-source project available under the GPL 2 license.
Valgrind works on all x86 systems and is being adapted to run on the PowerPC architecture. It works with all major Linux distributions. Valgrind's benefits include:
Dynamic binary translation so you don't need to modify, recompile or relink your applications.
Able to debug and profile large and complex programs.
Usable on almost any kind of software written in any language.
Works with the entire program, including libraries.
Usable with other tools, such as GDB.
Works as a platform for writing and testing new debugging tools.
Also, Valgrind is maintained actively.
The Valgrind distribution includes five major tools that are tightly integrated into the Valgrind core: Memcheck, Addrcheck, Cachegrind, Massif and Helgrind. Memcheck detects the following problems:
Use of uninitialized memory.
Reading/writing memory after it has been freed or deleted.
Reading/writing off the end of malloced or new blocks.
Reading/writing inappropriate areas on the stack.
Memory leaks--where pointers to memory blocks are lost forever.
Passing uninitialized and/or unaddressable memory to system calls.
Mismatched use of malloc/new/new[] vs free/delete/delete[].
Overlapping src and dst pointers in memcpy() and related functions.
Some misuses of the POSIX pthreads API.
When Memcheck is run:
All memory reads and writes are checked.
All calls to malloc/new/free/delete are instrumented.
Immediate error reporting happens, giving source line number, if possible.
Function stack tracing shows how the error line was reached.
Tracks are addressable at the byte-level and initialization of values at the bit-level. So Valgrind detects the use of single uninitialized bits and does not report spurious errors on bitfield operations.
It runs programs about 10--30x slower than normal.
Addrcheck is a lightweight version of Memcheck. It does not check for uninitialized data. The tradeoff is that Addrcheck detects fewer errors than Memcheck but runs about twice as fast (about 5--20x slower than normal). Also, a lot less memory is used. This means programs can be run for longer and cover more test scenarios. And Valgrind still finds a lot of important bugs in this mode. The authors suggest that you use Addrcheck most of the time for finding memory bugs, and occasionally use Memcheck for more thorough checking.
Cachegrind is a cache profiler. It simulates the I1, D1 and L2 caches in your CPU and pinpoints the sources of cache misses in your code. It identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries. It is useful with programs written in any language. Cachegrind runs programs about 20--100x slower than normal.
Massif is a heap profiler. It performs detailed heap profiling by taking regular snapshots of a program's heap. It produces a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations. The graph is supplemented by a text or HTML file that includes more information for determining where the most memory is being allocated. Massif runs programs about 20x slower than normal. Massif was introduced in version 2.1.1 of Valgrind.
Helgrind is a thread debugger that finds data races in multithreaded programs. It looks for memory locations accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_)lock can be found. Such locations are indicative of missing synchronization between threads and could cause hard-to-find timing-dependent problems. It is useful for any program that uses pthreads. It is experimental, so the authors really welcome your feedback here.
To make Valgrind even easier to use or to extend its functionality, a number of other tools are available, including Kcachegrind, an extension to Cachegrind that provides more data about call graphs. Its visualization tool also gives a much better overview of the data it collects. There also are patches for vgprof, a Valgrind tool, that profiles in the same manner as gprof but doesn't require recompilation. It works with threaded programs and can profile shared libraries. Several experimental tools also are available, including a memory access tracer, a pointer misuse-checker and a signal-handler checker. Another patch for Valgrind adds watch points on memory locations.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Kernel Problem
4 hours 31 min ago - BASH script to log IPs on public web server
8 hours 58 min ago - DynDNS
12 hours 34 min ago - Reply to comment | Linux Journal
13 hours 7 min ago - All the articles you talked
15 hours 30 min ago - All the articles you talked
15 hours 33 min ago - All the articles you talked
15 hours 35 min ago - myip
19 hours 59 min ago - Keeping track of IP address
21 hours 50 min ago - Roll your own dynamic dns
1 day 3 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Valgrind is cool
Valgrind is cool. It is very easy to use and very powerful. The programs run quite slow and sometimes I do simplify the computing intensive algorithms to be able to run my real-time applications under valgrind, but again: Valgrind is cool.
Andre Adrian
Senior Engineer
Valgrind is cool
I could not have said it better myself (as a matter of fact, I didn't :-)).
Reg. Charney