10

For a method that I am trying to code for one of the classes I have been working on, I am trying to read double values from a file and dynamically set some arrays inside the program with these numeric values.

I wanted to check, at least up to the point that I came, whether I have memory leaks or not. However, firing up valgrind just hangs, valgrind seems to work quite heavily since the cpu loading is high, but no output is generated even if I have been waiting for some time now. I have shuffled through the pages of the manual however could not find something useful. I compiled valgrind-3.8.0 and using that now. And I am firing it the way I have always done as

valgrind --leak-check=yes --log-file=valgrind_log ./binary_to_execute args_if_any

I could not also find sth useful for this hanging problem on google search. Any ideas on the reason of this hanging behaviour?

Edit 1: Here is a timing output from time command for the application

47740

real    0m1.299s
user    0m1.116s
sys     0m0.176s

Edit 2: Here is a link which is more or less the same as the problem that I am experiencing,

A message with a similar problem

Edit 3: I have noticed sth interesting, if the file size that I am trying to read is large this problem occurs, if the size of the files are relatively small, this hanging does not occur, which is also strange to me.

Umut Tabak
  • 1,862
  • 4
  • 26
  • 41
  • how long does the program take to run without valgrind? – titus Aug 16 '12 at 18:33
  • with valgrind it should take about 20x as much, so about 30 seconds – titus Aug 16 '12 at 18:35
  • 1
    yes, indeed, that I know, however valgrind never stops executing... – Umut Tabak Aug 16 '12 at 18:36
  • try using another tool to see if valgrind or memcheck is causing the problem (--tool=cachegrind or other), or maybe try using an older version of valgrind – titus Aug 16 '12 at 18:46
  • Have you tried running valgrind with debug trace options (those that show everything being executed?)? – PlasmaHH Aug 16 '12 at 18:47
  • maybe try and start callgrind without instrumentation `--instr-atstart=no`, and start it, immediately before you need it, with the shell command `callgrind_control --instr=on` – titus Aug 16 '12 at 18:54
  • @titus, indeed, cachegrid works and outputs information, and the version of valgrind at my deskptop is 3.6.1. – Umut Tabak Aug 16 '12 at 21:01
  • @PlasmaHH, I am not very good at using valgrind, can you be more specific on 'debug trace options' – Umut Tabak Aug 16 '12 at 21:02
  • @UmutTabak: valgrind --help-debug – PlasmaHH Aug 16 '12 at 21:08
  • @Umut Tabak, i'm also using 3.6.1, you should use that if I understand correctly that memcheck works on that. Wild guess here: is your program spawning processes and doesn't close them properly? – titus Aug 16 '12 at 21:39
  • @titus, ok, lets rephrase a bit more into detail, basically I am trying to call some FORTRAN library functions from C++, this is what I would like to do.Yesterday, I had a chat with the developer of this library and I am trying to make sure that the code until I call this FORTRAN functions are working without leaks, that is how I ended up with this problem.Now I am linking the library to the code but not calling the functions from the library, I am just checking if the interfacing stuff is without leaks or other problems. Well I am not a CS guy, no I do not know what 'spawning' is, I will read – Umut Tabak Aug 16 '12 at 21:47
  • @titus, no, memcheck for 3.6.1 also does not work on large sized files – Umut Tabak Aug 16 '12 at 22:01
  • @Umut Tabak, you could add print statements in your program to see where valgrind hangs. Spawning means creating a new process, as far as I know, as in en.wikipedia.org/wiki/Fork_(operating_system) I guess you are not creating processes. If you are familiar with Python here is a somewhat useful program to add print statements in code after every opement { bracket: github.com/titusnicolae/poorman-dbg/blob/master/p.py – titus 4 mins ago edit – titus Aug 16 '12 at 22:14
  • You can possibly have same problem that was described in http://stackoverflow.com/questions/24558914/valgrind-hangs-in-pthread-spin-lock-consuming-100-cpu/28881969?noredirect=1#comment46065293_28881969 – prez Mar 17 '15 at 08:47

2 Answers2

8

A large file suggests more work to be done. So valgrind needs more time. Valgrind really is very slow.

You can easily debug this with the world's best debugger: printf() (only half-kidding.) Simply print something before or after every iteration of your main loop. If it doesn't show up, valgrind is really hanging somewhere. Thoughtful placement of your printf() statements should reveal the exact location where it hangs (if it actually hangs rather than being slow.)

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
-1
  1. maybe your program main thread not exit
  2. wait valgrind exit
chlaws
  • 30
  • 4